如何从 jmx 客户端访问dynamicmbean

发布于 2024-08-15 14:01:21 字数 841 浏览 5 评论 0原文

我正在为我们产品中的 JMX 接口编写一些测试用例。我可以从标准 MBean 访问属性(遵循 sun 教程)。但是,我似乎无法访问动态 MBean。这些属性完全来自 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 应该是布尔值,但它是空的。不会引发任何异常。

我还尝试了属性名称的一些其他排列,但我相信它应该是简单的名称,因为我在实现类中定义了它。

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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓬勃野心 2024-08-22 14:01:21

我发现您可以直接通过 MBeanServerConnection 对象获取动态 MBean 属性:

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");

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");
情绪 2024-08-22 14:01:21

我应该在回答之前重新加载页面。我基本上发布了原始提交者同时发现的内容。如果您有一个描述 MBean 管理接口(标准 MBean 模式)的 Java 接口,则 JMX.newMBeanProxy 非常有用,但如果您的 MBean 是动态的,则您不需要或不需要代理。

I should have reloaded the page before answering. I basically posted what the original submitter had discovered in the meantime. JMX.newMBeanProxy is useful if you have a Java interface describing the management interface of your MBean (the Standard MBean pattern), but if your MBean is dynamic then you don't need or want a proxy.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文