Java Reference
In-Depth Information
Figure 4.9
The
Logger
MBean accessing
the
PropertyManager
MBean. The
Logger
class can
use another MBean because it
has a reference to the MBean
server. It acquires this
reference by implementing the
MBeanRegistration
interface.
For one MBean to use another MBean, it must be able to contact the MBean
server. You could pass in an MBean as a parameter to another's constructor, but
you don't want to create an unnecessary dependency on the MBean. You can
implement an MBean to contain a reference to its MBean server two ways:
■
Construct the MBean with an MBean server parameter.
■
Implement the
MBeanRegistration
interface.
This section discusses the
MBeanRegistration
interface. This interface declares
methods that are invoked before and after registration and deregistration on the
MBean server. The following is the
MBeanRegistration
interface:
package javax.management;
public abstract interface MBeanRegistration
{
public void postDeregister();
public void postRegister( Boolean registrationDone );
public void preDeregister();
public ObjectName preRegister( MBeanServer server,
ObjectName name );
}
This interface contains two methods that are called in conjunction with the
MBean's registration on a MBean server, and two methods that are called with
deregistration. These methods are invoked by the
MBeanServer
instance that is
being asked to perform the registration or deregistration of a particular MBean
instance. For example, if the
HelloWorld
MBean from chapter 2 implemented
this interface, the MBean server would perform the following tasks when asked
by the
HTML
adapter to create another
HelloWorld
MBean instance: