[jbosscache-commits] JBoss Cache SVN: r6544 - in core/trunk/src/main/java/org/jboss/cache: interceptors/base and 1 other directories.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Fri Aug 8 05:37:39 EDT 2008
Author: mircea.markus
Date: 2008-08-08 05:37:39 -0400 (Fri, 08 Aug 2008)
New Revision: 6544
Added:
core/trunk/src/main/java/org/jboss/cache/jmx/JmxStatisticsExposer.java
Removed:
core/trunk/src/main/java/org/jboss/cache/interceptors/base/JmxStatisticsInterceptor.java
Modified:
core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/interceptors/base/JmxStatsCommandInterceptor.java
core/trunk/src/main/java/org/jboss/cache/jmx/JmxUtil.java
Log:
added management stats for replication
Modified: core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-08-07 19:23:46 UTC (rev 6543)
+++ core/trunk/src/main/java/org/jboss/cache/RPCManagerImpl.java 2008-08-08 09:37:39 UTC (rev 6544)
@@ -32,6 +32,8 @@
import org.jboss.cache.transaction.TransactionTable;
import org.jboss.cache.util.ThreadGate;
import org.jboss.cache.util.reflect.ReflectionUtil;
+import org.jboss.cache.jmx.annotations.ManagedOperation;
+import org.jboss.cache.jmx.annotations.ManagedAttribute;
import org.jgroups.Address;
import org.jgroups.Channel;
import org.jgroups.ChannelException;
@@ -53,6 +55,7 @@
import java.util.List;
import java.util.Set;
import java.util.Vector;
+import java.text.NumberFormat;
/**
* Manager that handles all RPC calls between JBoss Cache instances
@@ -64,6 +67,9 @@
private Channel channel;
private final Log log = LogFactory.getLog(RPCManagerImpl.class);
private List<Address> members;
+ private long replicationCount;
+ private long replicationFailures;
+ private boolean statisticsEnabled;
private final Object coordinatorLock = new Object();
/**
@@ -407,65 +413,65 @@
public List<Object> callRemoteMethods(Vector<Address> recipients, ReplicableCommand command, int mode, long timeout, RspFilter responseFilter, boolean useOutOfBandMessage) throws Exception
{
- // short circuit if we don't have an RpcDispatcher!
- if (rpcDispatcher == null) return null;
-
- int modeToUse = mode;
- int preferredMode;
- if ((preferredMode = spi.getInvocationContext().getOptionOverrides().getGroupRequestMode()) > -1)
- modeToUse = preferredMode;
-
- if (trace)
- log.trace("callRemoteMethods(): valid members are " + recipients + " methods: " + command + " Using OOB? " + useOutOfBandMessage);
-
- if (channel.flushSupported())
- {
- if (!flushBlockGate.await(configuration.getStateRetrievalTimeout()))
- throw new TimeoutException("State retrieval timed out waiting for flush unblock.");
- }
-
- useOutOfBandMessage = false;
-
- RspList rsps = rpcDispatcher.invokeRemoteCommands(recipients, command, modeToUse, timeout, isUsingBuddyReplication, useOutOfBandMessage, responseFilter);
-
- if (mode == GroupRequest.GET_NONE) return Collections.emptyList();// async case
-
- if (trace)
- log.trace("(" + getLocalAddress() + "): responses for method " + command.getClass().getSimpleName() + ":\n" + rsps);
-
- // short-circuit no-return-value calls.
- if (rsps == null) return Collections.emptyList();
-
- List<Object> retval = new ArrayList<Object>(rsps.size());
-
- for (Rsp rsp : rsps.values())
- {
- if (rsp.wasSuspected() || !rsp.wasReceived())
+ boolean success = true;
+ try {
+ // short circuit if we don't have an RpcDispatcher!
+ if (rpcDispatcher == null) return null;
+ int modeToUse = mode;
+ int preferredMode;
+ if ((preferredMode = spi.getInvocationContext().getOptionOverrides().getGroupRequestMode()) > -1)
+ modeToUse = preferredMode;
+ if (trace)
+ log.trace("callRemoteMethods(): valid members are " + recipients + " methods: " + command + " Using OOB? " + useOutOfBandMessage);
+ if (channel.flushSupported())
{
- CacheException ex;
- if (rsp.wasSuspected())
+ if (!flushBlockGate.await(configuration.getStateRetrievalTimeout()))
+ throw new TimeoutException("State retrieval timed out waiting for flush unblock.");
+ }
+ useOutOfBandMessage = false;
+ RspList rsps = rpcDispatcher.invokeRemoteCommands(recipients, command, modeToUse, timeout, isUsingBuddyReplication, useOutOfBandMessage, responseFilter);
+ if (mode == GroupRequest.GET_NONE) return Collections.emptyList();// async case
+ if (trace)
+ log.trace("(" + getLocalAddress() + "): responses for method " + command.getClass().getSimpleName() + ":\n" + rsps);
+ // short-circuit no-return-value calls.
+ if (rsps == null) return Collections.emptyList();
+ List<Object> retval = new ArrayList<Object>(rsps.size());
+ for (Rsp rsp : rsps.values())
+ {
+ if (rsp.wasSuspected() || !rsp.wasReceived())
{
- ex = new SuspectException("Suspected member: " + rsp.getSender());
+ CacheException ex;
+ if (rsp.wasSuspected())
+ {
+ ex = new SuspectException("Suspected member: " + rsp.getSender());
+ }
+ else
+ {
+ ex = new TimeoutException("Replication timeout for " + rsp.getSender());
+ }
+ retval.add(new ReplicationException("rsp=" + rsp, ex));
+ success = false;
}
else
{
- ex = new TimeoutException("Replication timeout for " + rsp.getSender());
+ Object value = rsp.getValue();
+ if (value instanceof Exception && !(value instanceof ReplicationException))
+ {
+ // if we have any application-level exceptions make sure we throw them!!
+ if (trace) log.trace("Recieved exception'" + value + "' from " + rsp.getSender());
+ throw (Exception) value;
+ }
+ retval.add(value);
+ success = true;
}
- retval.add(new ReplicationException("rsp=" + rsp, ex));
}
- else
- {
- Object value = rsp.getValue();
- if (value instanceof Exception && !(value instanceof ReplicationException))
- {
- // if we have any application-level exceptions make sure we throw them!!
- if (trace) log.trace("Recieved exception'" + value + "' from " + rsp.getSender());
- throw (Exception) value;
- }
- retval.add(value);
- }
+ return retval;
+ } catch (Exception e) {
+ success = false;
+ throw e;
+ } finally {
+ computeStats(success);
}
- return retval;
}
// ------------ START: Partial state transfer methods ------------
@@ -696,5 +702,58 @@
}
}
- /*------------------- End of MembershipListener ----------------------*/
+
+
+ //jmx operations
+ private void computeStats(boolean success) {
+ if (this.isStatisticsEnabled() && rpcDispatcher != null)
+ {
+ if (success)
+ {
+ replicationCount ++;
+ } else
+ {
+ replicationFailures ++;
+ }
+ }
+ }
+
+ @ManagedOperation
+ public void resetStatistics()
+ {
+ this.replicationCount = 0;
+ this.replicationFailures = 0;
+ }
+
+ @ManagedAttribute(description = "number of successful replications")
+ public long getReplicationCount() {
+ return replicationCount;
+ }
+
+ @ManagedAttribute (description = "number of failed replications")
+ public long getReplicationFailures() {
+ return replicationFailures;
+ }
+
+ @ManagedAttribute (description = "whether or not jmx statistics are enabled")
+ public boolean isStatisticsEnabled() {
+ return statisticsEnabled;
+ }
+
+ @ManagedAttribute
+ public void setStatisticsEnabled(boolean statisticsEnabled) {
+ this.statisticsEnabled = statisticsEnabled;
+ }
+
+ @ManagedAttribute
+ public String getSuccessRatio()
+ {
+ if (replicationCount == 0 || !statisticsEnabled)
+ {
+ return "N/A";
+ }
+ double totalCount = replicationCount + replicationFailures;
+ double ration = (double)replicationCount / totalCount * 100d;
+ return NumberFormat.getInstance().format(ration) +"%";
+ }
}
\ No newline at end of file
Deleted: core/trunk/src/main/java/org/jboss/cache/interceptors/base/JmxStatisticsInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/base/JmxStatisticsInterceptor.java 2008-08-07 19:23:46 UTC (rev 6543)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/base/JmxStatisticsInterceptor.java 2008-08-08 09:37:39 UTC (rev 6544)
@@ -1,63 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.cache.interceptors.base;
-
-import java.util.Map;
-
-/**
- * Interface containing common cache management operations
- *
- * @author Jerry Gauthier
- * @version $Id$
- */
-public interface JmxStatisticsInterceptor
-{
- /**
- * Returns whether an interceptor's statistics are
- * being captured.
- *
- * @return true if statistics are captured
- */
- boolean getStatisticsEnabled();
-
- /**
- * Enables an interceptor's cache statistics
- * If true, the interceptor will capture statistics
- * and make them available through the mbean.
- *
- * @param enabled true if statistics should be captured
- */
- void setStatisticsEnabled(boolean enabled);
-
- /**
- * Returns a map of the cache interceptor's statistics
- * Map is keyed on statistic names (which are Strings) and values are Objects.
- *
- * @return a map containing statistics
- */
- Map<String, Object> dumpStatistics();
-
- /**
- * Resets an interceptor's cache statistics
- */
- void resetStatistics();
-}
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/base/JmxStatsCommandInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/base/JmxStatsCommandInterceptor.java 2008-08-07 19:23:46 UTC (rev 6543)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/base/JmxStatsCommandInterceptor.java 2008-08-08 09:37:39 UTC (rev 6544)
@@ -22,7 +22,7 @@
package org.jboss.cache.interceptors.base;
import org.jboss.cache.jmx.annotations.ManagedAttribute;
-import org.jboss.cache.interceptors.base.JmxStatisticsInterceptor;
+import org.jboss.cache.jmx.JmxStatisticsExposer;
import org.jboss.cache.factories.annotations.Start;
import java.util.Map;
@@ -34,7 +34,7 @@
* @author Mircea.Markus at jboss.com
* @since 3.0
*/
-public class JmxStatsCommandInterceptor extends CommandInterceptor implements JmxStatisticsInterceptor
+public class JmxStatsCommandInterceptor extends CommandInterceptor implements JmxStatisticsExposer
{
private boolean statsEnabled = false;
Copied: core/trunk/src/main/java/org/jboss/cache/jmx/JmxStatisticsExposer.java (from rev 6541, core/trunk/src/main/java/org/jboss/cache/interceptors/base/JmxStatisticsInterceptor.java)
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/JmxStatisticsExposer.java (rev 0)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/JmxStatisticsExposer.java 2008-08-08 09:37:39 UTC (rev 6544)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.cache.jmx;
+
+import java.util.Map;
+
+/**
+ * Interface containing common cache management operations
+ *
+ * @author Jerry Gauthier
+ * @version $Id$
+ */
+public interface JmxStatisticsExposer
+{
+ /**
+ * Returns whether an interceptor's statistics are
+ * being captured.
+ *
+ * @return true if statistics are captured
+ */
+ boolean getStatisticsEnabled();
+
+ /**
+ * Enables an interceptor's cache statistics
+ * If true, the interceptor will capture statistics
+ * and make them available through the mbean.
+ *
+ * @param enabled true if statistics should be captured
+ */
+ void setStatisticsEnabled(boolean enabled);
+
+ /**
+ * Returns a map of the cache interceptor's statistics
+ * Map is keyed on statistic names (which are Strings) and values are Objects.
+ *
+ * @return a map containing statistics
+ */
+ Map<String, Object> dumpStatistics();
+
+ /**
+ * Resets an interceptor's cache statistics
+ */
+ void resetStatistics();
+}
Property changes on: core/trunk/src/main/java/org/jboss/cache/jmx/JmxStatisticsExposer.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: core/trunk/src/main/java/org/jboss/cache/jmx/JmxUtil.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/jmx/JmxUtil.java 2008-08-07 19:23:46 UTC (rev 6543)
+++ core/trunk/src/main/java/org/jboss/cache/jmx/JmxUtil.java 2008-08-08 09:37:39 UTC (rev 6544)
@@ -22,13 +22,10 @@
package org.jboss.cache.jmx;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.interceptors.base.CommandInterceptor;
-import org.jboss.cache.interceptors.base.JmxStatisticsInterceptor;
import javax.management.JMException;
import javax.management.MBeanServer;
import javax.management.ObjectName;
-import java.util.List;
/**
* Various JMX related utilities
More information about the jbosscache-commits
mailing list