Implement MBeanRegistration
Sometimes a JMX agent is an MBean and might need to use the services provided by the MBean server to interact with other MBeans that are registered in the same MBean server. To do so, the agent needs a reference to the MBean server. In addition, a mechanism is needed for MBeans to provide their own object names when the agent is generic or is provided by another vendor. Finally, MBeans that are using system resources such as connections need to release these resources when the MBeans are no longer needed by the application.
The
MBeanRegistration
interface provides the ability to handle all these situations. It
defines four methods:
public interface MBeanRegistration {
public ObjectName preRegister (MBeanServer server, ObjectName name)
throws java.lang.Exception;
public void postRegister (Boolean registrationDone);
public void preDeregister( ) throws java.lang.Exception;
public void postDeregister( );
}The MBean server invokes these methods on MBeans that implement this interface. You can probably guess, based on the names of the methods when they are called during the process of registering and unregistering your MBean. There are several advantages to implementing this interface:
The MBean gets the opportunity to store a reference to the MBean server in which it is registered. Using this reference, the MBean can now interact with other MBeans, using the MBean server as a communications bus.
The MBean gets a chance to provide its own object name if the ...