Search code examples
javajmxmbeans

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:

1) TO use the invoke operation of MBeanServerConnection and provide the method name as a String using mbsc.invoke(name, operationName, params, signature)

2) Get the MBean interface using JMX.newMBeanProxy(connection, objectName, interfaceClass) and call the operations on 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? The Mbean interface is part of source of my main application that is to be monitored. Do I need to copy the same Mbean interface into the client code as well?


Solution

  • For me there is no best practice, as the decision depends on your needs.

    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. Take as example the jconsole utility. It can invoke all exposed operations without the need to have access to the mbean interface class.

    JMX.newMBeanProxy(connection, objectName, interfaceClass)

    If the client application has a strong dependency to the application where the MBean is executed (e.g. 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.