如何从jmx客户端访问dynamicmbeans [英] How to access dynamicmbeans from a jmx client
问题描述
我正在为我们的产品中的JMX接口编写一些测试用例.我可以从标准MBean访问属性(遵循 sun教程).但是,我似乎无法访问动态MBean.这些属性在JConsole中是完全(可读/可写)的.
I am writing some test cases for the JMX interface in our product. I can access attributes from standard MBeans (following sun tutorial). However, I don't seem to be able to access dynamic MBeans. The attributes are fully (readable/writable) from JConsole.
JMXConnector jmxc = getJMXConnector(); // Takes care of our connection
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
ObjectName mbeanName = new ObjectName("com.xyz.prodname:type=LogManager");
// Up to this point, the logic is the same as the working logic. In our working logic,
// DynamicMBean is replace with our MBean interface class.
DynamicMBean mbean = (DynamicMBean)JMX.newMBeanProxy(mbsc, mbeanName, DynamicMBean.class);
Object o = mbean.getAttribute("AttributeNameAsItAppearsInJConsole");
o应该是布尔值,但它为null.没有引发异常.
o should be a Boolean, but it is null. No exceptions are thrown.
我也尝试过对属性名称进行其他一些排列,但是我相信它应该是简单的名称,就像我在实现类中定义的一样.
I have also tried a few other permutations on the attribute name, but I believe it should be the simple name as I've defined it in the implementation class.
推荐答案
我发现您可以直接通过MBeanServerConnection对象获取动态MBean属性:
I've found that you can get to dynamic MBean attributes directly through the MBeanServerConnection object:
JMXConnector jmxc = getJMXConnector(); // Takes care of our connection
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
ObjectName mbeanName = new ObjectName("com.xyz.prodname:type=LogManager");
// This change demonstrates what must be done
Object result = mbsc.getAttribute(mbeanName, "AttributeNameAsItAppearsInJConsole");
这篇关于如何从jmx客户端访问dynamicmbeans的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!