Chapter 12. Management Information

JBoss Cache includes JMX MBeans to expose cache functionality and provide statistics that can be used to analyze cache operations. JBoss Cache can also broadcast cache events as MBean notifications for handling via JMX monitoring tools.

12.1. JBoss Cache MBeans

JBoss Cache provides an MBean that allows JMX access to a cache instance. This MBean is accessible from an MBean server through the service name specified in the cache instance's configuration. For example, the Tomcat clustering cache instance is accessible through the service named "jboss.cache:service=TomcatClusteringCache." This MBean can be used to perform most cache operations via JMX.

JBoss Cache also provides MBeans for each interceptor configured in the cache's interceptor stack. These MBeans are used to capture and expose statistics related to cache operations. They are hierarchically associated with the cache's primary MBean and have service names that reflect this relationship. For example, a replication interceptor MBean for the TomcatClusteringCache instance will be accessible through the service named "jboss.cache:service=TomcatClusteringCache,treecache-interceptor=ReplicationInterceptor."

12.2. JBoss Cache Statistics

JBoss Cache captures statistics in its interceptors and exposes the statistics through interceptor MBeans. Cache interceptor MBeans are enabled by default; these MBeans can be disabled for a specific cache instance through the UseInterceptorMbeans attribute. See the Configuration chapter for further details on configuration of this attribute.

Each interceptor's MBean provides an attribute that can be used to disable maintenance of statistics for that interceptor. Note that the majority of the statistics are provided by the CacheMgmtInterceptor MBean so this interceptor is the most significant in this regard. If you want to disable all statistics for performance reasons, you should utilize the UseInterceptorMbeans configuration setting as this will prevent the CacheMgmtInterceptor from being included in the cache's interceptor stack when the cache is started.

Each interceptor provides the following common operations and attributes.

  • dumpStatistics - returns a Map containing the interceptor's attributes and values.
  • resetStatistics - resets all statistics maintained by the interceptor.
  • setStatisticsEnabled(boolean) - allows statistics to be disabled for a specific interceptor.

The following table describes the statistics currently available for JBoss Cache.

Table 12.1. JBoss Cache Management Statistics

MBean NameAttributeTypeDescription
ActivationInterceptorActivationslongNumber of passivated nodes that have been activated.
CacheLoaderInterceptorCacheLoaderLoadslongNumber of nodes loaded through a cache loader.
CacheLoaderInterceptorCacheLoaderMisseslongNumber of unsuccessful attempts to load a node through a cache loader.
CacheMgmtInterceptorHitslongNumber of successful attribute retrievals.
CacheMgmtInterceptorMisseslongNumber of unsuccessful attribute retrievals.
CacheMgmtInterceptorStoreslongNumber of attribute store operations.
CacheMgmtInterceptorEvictionslongNumber of node evictions.
CacheMgmtInterceptorNumberOfAttributesintNumber of attributes currently cached.
CacheMgmtInterceptorNumberOfNodesintNumber of nodes currently cached.
CacheMgmtInterceptorElapsedTimelongNumber of seconds that the cache has been running.
CacheMgmtInterceptorTimeSinceResetlongNumber of seconds since the cache statistics have been reset.
CacheMgmtInterceptorAverageReadTimelongAverage time in milliseconds to retrieve a cache attribute, including unsuccessful attribute retrievals.
CacheMgmtInterceptorAverageWriteTimelongAverage time in milliseconds to write a cache attribute.
CacheMgmtInterceptorHitMissRatiodoubleRatio of hits to hits and misses. A hit is a get attribute operation that results in an object being returned to the client. The retrieval may be from a cache loader if the entry isn't in the local cache.
CacheMgmtInterceptorReadWriteRatiodoubleRatio of read operations to write operations. This is the ratio of cache hits and misses to cache stores.
CacheStoreInterceptorCacheLoaderStoreslongNumber of nodes written to the cache loader.
InvalidationInterceptorInvalidationslongNumber of cached nodes that have been invalidated.
PassivationInterceptorPassivationslongNumber of cached nodes that have been passivated.
TxInterceptorPrepareslongNumber of transaction prepare operations performed by this interceptor.
TxInterceptorCommitslongNumber of transaction commit operations performed by this interceptor.
TxInterceptorRollbackslongNumber of transaction rollbacks operations performed by this interceptor.

12.3. Receiving Cache Notifications

JBoss Cache users can register a listener to receive cache events as described in the Eviction Policies chapter. Users can alternatively utilize the cache's management information infrastructure to receive these events via JMX notifications. Cache events are accessible as notifications by registering a NotificationListener for the CacheMgmtInterceptor MBean. This functionality is only available if cache statistics are enabled as described in the previous section.

The following table depicts the JMX notifications available for JBoss Cache as well as the cache events to which they correspond. These are the notifications that can be received through the CacheMgmtInterceptor MBean. Each notification represents a single event published by JBoss Cache and provides user data corresponding to the parameters of the event.

Table 12.2. JBoss Cache MBean Notifications

Notification TypeNotification DataTreeCacheListener Event
org.jboss.cache.CacheStartedString : cache service namecacheStarted
org.jboss.cache.CacheStoppedString : cache service namecacheStopped
org.jboss.cache.NodeCreatedString : fqnNodeCreated
org.jboss.cache.NodeEvictedString : fqnNodeEvicted
org.jboss.cache.NodeLoadedString : fqnNodeLoaded
org.jboss.cache.NodeModifedString : fqnNodeModifed
org.jboss.cache.NodeRemovedString : fqnNodeRemoved
org.jboss.cache.NodeVisitedString : fqnNodeVisited
org.jboss.cache.ViewChangeString : viewViewChange
org.jboss.cache.NodeActivate
Object[0]=String: fqn
Object[1]=Boolean: pre
NodeActivate
org.jboss.cache.NodeEvict
Object[0]=String: fqn
Object[1]=Boolean: pre
NodeEvict
org.jboss.cache.NodeModify
Object[0]=String: fqn
Object[1]=Boolean: pre
Object[2]=Boolean: isLocal
NodeModify
org.jboss.cache.NodePassivate
Object[0]=String: fqn
Object[1]=Boolean: pre
NodePassivate
org.jboss.cache.NodeRemove
Object[0]=String: fqn
Object[1]=Boolean: pre
Object[2]=Boolean: isLocal
NodeRemove

The following is an example of how to programmatically receive cache notifications when running in a JBoss application server environment. In this example, the client uses a filter to specify which events are of interest.

MyListener listener = new MyListener();
NotificationFilterSupport filter = null;
	 
// get reference to MBean server
Context ic = new InitialContext();
MBeanServerConnection server = (MBeanServerConnection)ic.lookup("jmx/invoker/RMIAdaptor");
	 
// get reference to CacheMgmtInterceptor MBean
String cache_service = "jboss.cache:service=TomcatClusteringCache";
String mgmt_service = cache_service + ",treecache-interceptor=CacheMgmtInterceptor";
ObjectName mgmt_name = new ObjectName(mgmt_service);
	 
// configure a filter to only receive node created and removed events
filter = new NotificationFilterSupport();
filter.disableAllTypes();
filter.enableType(CacheMgmtInterceptor.NOTIF_NODE_CREATED);
filter.enableType(CacheMgmtInterceptor.NOTIF_NODE_REMOVED);
	 
// register the listener with a filter
// leave the filter null to receive all cache events
server.addNotificationListener(mgmt_name, listener, filter, null);
	 
// ...
	 
// on completion of processing, unregister the listener
server.removeNotificationListener(mgmt_name, listener, filter, null);
  

The following is the simple notification listener implementation used in the previous example.

private class MyListener implements NotificationListener, Serializable {
   public void handleNotification(Notification notification, Object handback) {
      String message = notification.getMessage();
      String type = notification.getType();
      Object userData = notification.getUserData();
      System.out.println(type + ": "+message);
      if (userData == null) {
         System.out.println("notification data is null");
      }
      else if (userData instanceof String) {
         System.out.println("notification data: "+(String)userData);
      }
      else if (userData instanceof Object[]) {
         Object[] ud = (Object[])userData;
         for (int i = 0; i > ud.length; i++) {
            System.out.println("notification data: "+ud[i].toString());
         }
      }
      else {
         System.out.println("notification data class: " + userData.getClass().getName());
      }
   }
} 
	

Note: the JBoss Cache management implementation only listens to cache events after a client registers to receive MBean notifications. As soon as no clients are registered for notifications, the MBean will remove itself as a cache listener.

12.4. Accessing Cache MBeans in a Standalone Environment

JBoss Cache MBeans are readily accessed when running cache instances in an application server that provides an MBean server interface such as JBoss JMX Console. Refer to server documentation for instructions on how to access MBeans running in a server's MBean container.

JBoss Cache MBeans are also accessible when running in a non-server environment if the JVM is JDK 5.0 or later. When running a standalone cache in a JDK 5 environment, you can access the cache's MBeans as follows.

  1. Set the system property -Dcom.sun.management.jmxremote when starting the JVM where the cache will run.
  2. Once the JVM is running, start the JDK 5 jconsole utility, located in the JDK's /bin directory.
  3. When the utility loads, you will be able to select your JVM and connect to it. The JBoss Cache MBeans will be available on the MBeans panel.

Note: The jconsole utility will automatically register as a listener for cache notifications when connected to a JVM running JBoss Cache instances.

The following figure shows cache interceptor MBeans in jconsole. Cache statistics are displayed for the CacheMgmt interceptor:

CacheMgmtInterceptor MBean

Figure 12.1. CacheMgmtInterceptor MBean