javajmxmbeansinfinispan

Access Infinispan MBeans programmatically


I am using Infinispan 5.2.1 and tried to access the MBeans via my Java program. But no luck. I assume Infinispan MBeans are registered in Platform MBean server. I can see all the MBeans correctly in Jconsole but not with the program.

My Infinispan configuration

    <globalJmxStatistics enabled="true" allowDuplicateDomains="true"/>

My Java program.

MBeanServerConnection mBeanServer = ManagementFactory.getPlatformMBeanServer();

String jmxQuery = "org.infinispan:type=Cache,name=" + "\"" + cacheName + "(" + cacheMode + ")" + "\""
            + ",manager=" + "\"" + "DefaultCacheManager" + "\""
            + ",component=Statistics";

Set<ObjectInstance> queryResults = mBeanServer.queryMBeans(new ObjectName(jmxQuery), null); 

for (ObjectInstance objectInstance : queryResults) {

            ObjectName objectName = objectInstance.getObjectName();

            long cacheHits = (Long) mBeanServer.getAttribute(objectName, "Hits");

            long removeHits = (Long) mBeanServer.getAttribute(objectName, "RemoveHits");

            totalHits = cacheHits + removeHits;

        }

Solution

  • You will need to use the remote MBean server access even though the JVMs are running on the same host.

    Please, check out Accessing a remote MBean server to learn more about setting up the platform MBean server for the remote connection and connecting to that server.