Before writing an agent application, it is important to understand the functionality of the MBean server. It is actually an interface and a factory object defined by the agent specification level of the JMX specification. The Java DMK provides an implementation of this interface and factory. The factory object finds or creates the MBean server instance, making it possible to substitute different implementations of the MBean server.
Methods for controlling MBean instances:
createMBean, or instantiate and registerMBean add a new MBean to the agent
unregisterMBean removes an MBean from the agent
isRegistered and getObjectInstance associate the class name with the MBean's management name
addNotificationListener and removeNotificationListener control event listeners for a particular MBean
deserialize is used to download new MBean classes
Methods for accessing MBean attributes and operations. These methods are identical to those presented in DynamicMBean Interface, except they all have an extra parameter for specifying the target MBean:
getAttribute and getAttributes
setAttribute and setAttributes
Methods for managing the agent as a whole:
getDefaultDomain (domains are a way of grouping MBeans in the agent)
getMBeanCount counts all MBeans in an agent
queryMBeans and queryNames to find MBeans by name or by value
The MBeanServerImpl class in the Java DMK implements the MBeanServer interface. It is the class that will be instantiated in an agent. However, it is never instantiated directly by the agent application. Instead, you rely on the MBean server factory to return a new instance of the implementing class.
The MBeanServerFactory is a static class defined by the JMX specification that makes the agent application independent of the MBean server implementation. It resides in the Java virtual machine and centralizes all MBean server instantiation. The MBeanServerFactory class provides two static methods:
createMBeanServer returns a new MBean server instance.
findMBeanServer returns a list of MBean servers in the Java virtual machine.
You must use this class to create an MBean server so that other objects can obtain its reference by calling the findMBeanServer method. This method enables dynamically loaded objects to find the MBean server in an agent that has already been started.