简体   繁体   English

需要MBean接口的JMX客户端

[英]JMX Client needing MBean interface

I am new to JMX technology and if I understand correctly: There are 2 ways to invoke operation on Mbeans: 我是JMX技术的新手,如果我理解正确:有两种方法可以在Mbeans上调用操作:

1) TO use the invoke operation of MBeanServerConnection and provide the method name as a String using mbsc.invoke(name, operationName, params, signature) 1)使用MBeanServerConnection的调用操作并使用mbsc.invoke(name, operationName, params, signature)将方法名称提供为String

2) Get the MBean interface using JMX.newMBeanProxy(connection, objectName, interfaceClass) and call the operations on interface. 2)使用JMX.newMBeanProxy(connection, objectName, interfaceClass) )获取MBean接口JMX.newMBeanProxy(connection, objectName, interfaceClass)并调用interface上的操作。

My question is that if I want to use the second approach mentioned above, do I need to have the Mbean interface in my client also? 我的问题是,如果我想使用上述第二种方法,是否还需要在客户端中使用Mbean接口? The Mbean interface is part of source of my main application that is to be monitored. Mbean接口是我要监视的主应用程序源代码的一部分。 Do I need to copy the same Mbean interface into the client code as well? 我是否还需要将相同的Mbean接口复制到客户端代码中?

For me there is no best practice , as the decision depends on your needs. 对我而言,没有best practice ,因为决定取决于您的需求。

Find below my personal opinions. 在下面找到我的个人意见。

mbsc.invoke(name, operationName, params, signature)

If the client application is not strictly dependent on the application where the MBean is executed, the client application should not depend on the interface. 如果客户端应用程序不严格依赖执行MBean的应用程序,则客户端应用程序不应依赖于接口。 Take as example the jconsole utility. jconsole实用程序为例。 It can invoke all exposed operations without the need to have access to the mbean interface class. 它可以调用所有公开的操作,而无需访问mbean接口类。

JMX.newMBeanProxy(connection, objectName, interfaceClass)

If the client application has a strong dependency to the application where the MBean is executed (eg you provide the application with the mbean, and the client application is your support tool), I would go for this solution as you get the benefit of compile time checks. 如果客户端应用程序对执行MBean的应用程序具有高度依赖性(例如,您为应用程序提供了mbean,而客户端应用程序是您的支持工具),那么我将采用此解决方案,因为您可以受益于编译时间检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM