我正在使用 Infinispan 5.2.1 并尝试通过我的 Java 程序访问 MBean。但没有运气。我假设 Infinispan MBean 已在 Platform MBean 服务器中注册。我可以在 Jconsole 中正确地看到所有 MBean,但不能在程序中看到。
我的 Infinispan 配置
<globalJmxStatistics enabled="true" allowDuplicateDomains="true"/>
我的 Java 程序。
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;
}