我正在使用 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;
}
最佳答案
即使 JVM 在同一主机上运行,您也需要使用远程 MBean 服务器访问。
请查看Accessing a remote MBean server了解有关设置平台 MBean 服务器以进行远程连接以及连接到该服务器的更多信息。
关于java - 以编程方式访问 Infinispan MBean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16400399/