问题
I'm looking for a solution to register the MBeans or the whole MBean Servers itself from different Java VMs in a central MBean Server which should also run in a separate VM. The goal is to have only one central MBean Server which contains all MBeans of the whole System. One additional requirement is and thats the difficulty :-), that the "client" MBean Servers must connect/register to the central MBean Server and not the other way. The central MBean Server don't need any knowledge of the "client" MBean Servers to register.
I have only found JMX examples in which the "master" MBean Server connects to the "client" MBean Servers and geht their registred MBeans but not the other way. Unfortunately the registerMBean() method which is used to register your own MBeans, only exists for local MBean Servers but not for remote MBean Servers on a MBeanServerConnection. There, it is only possible to use the createMbean() method, problem here is, that it worked to register the MBean in the remote MBean Server but then you have to different Objects, one local und another in the remote MBean Server. So the Problem now is, that when something changes on the local object the changes are only there, the registered MBean in the remote MBean Server doesen't get these changes (new values of variables ...). The only solution I have so far, is to create a loop to unregister the MBeans in the remote Server and create them new, to get the actual values of the object. Thats very ugly and also not so good for the performance.
I hope someone can give me a hint, how I can do this in a better way.
回答1:
The OpenDMK provides a complete way to do this using the Cascading Service. From the documentation:
The cascading service enables you to access the MBeans of a subagent directly through the MBean server of a master agent. The cascading service has been completely overhauled in Java Dynamic Management Kit (Java DMK) 5.1 to allow it to operate over the connector protocols defined by the Java Management Extensions (JMX) Remote API. The legacy cascading service is now deprecated. The examples of the legacy cascading service have been retained in Chapter 25, for reasons of backwards compatibility. However, when using legacy Java DMK connectors, you should use the new CasdingServiceMBean with wrapped legacy connectors rather than relying on the deprecated legacy cascading agent API.
There are some interesting bits-and-pieces in this library that were slated to be naturalized into the standard Java SE in JMX 2.0. The cascading service, I think, was one of them. Once you understand how it works, you may conclude it is something you can implement yourself, although there are several thorny corner cases that the OpenDMK does account for. I am not sure how active the project is, but the software as is seems stable.
You can find the documentation set here. Additionally, I created a mavenized project build of the packages here.
//Nicholas
来源:https://stackoverflow.com/questions/9710003/is-it-possible-with-jmx-to-register-or-show-the-mbeans-form-different-vms-in-one