The XMOJO Project
<< Prev Chapter 2.2 Dynamic MBean Next >>

Dynamic MBean


A Java class that implements the interface javax.management.DynamicMBean directly or indirectly is a dynamic MBean. In a dynamic MBean, the attribute and operations are exposed only at the run time. Hence, Dynamic MBean is most appropriate where the management information will not be static.

 Advantages 

  1. No need to define your own management interface.
  2. The attributes and operations are exposed only at the run time, and exposing the attributes and operations can be controlled dynamically.
  3. Description about the dynamic MBean and its attributes and operations can be provided.

 DynamicMBean Interface 

The javax.management.DynamicMBean interface defines the following six methods:
  1. getMBeanInfo
  2. getAttribute
  3. setAttribute
  4. getAttributes
  5. setAttributes
  6. invoke

 getMBeanInfo 

The declaration of the getMBeanInfo method is

public javax.management.MBeanInfo getMBeanInfo()

The getMBeanInfo method returns an MBeanInfo object. With this MBeanInfo object, the attributes, operations, constructors, and notification information can be obtained. The management information is obtained from the MBeanInfo returned by this method. This is one of the advantages of Dynamic MBeans over Standard MBeans. In Standard MBeans, the management information will be obtained using MBean introspection. So, some standard lexical naming pattern of the methods has to be followed by the implementing class. Dynamic MBeans are free from these sorts of restrictions. If the implementing class has already defined a method printName() which does not follow the standard lexical naming pattern, the method can be mapped to the getter or setter method of some attribute (say ServerName) in that MBean.

 getAttribute and setAttribute 

The getAttribute method gets the value of a specific attribute of the Dynamic Mbean. The setAttribute method sets the value of a specific attribute of the Dynamic MBean. The method declarations are given below:

public Object getAttribute(String AttributeName)
       throws javax.management.AttributeNotFoundException,
               javax.management.MBeanException,
               javax.management.ReflectionException

public void setAttribute(javax.management.Attribute AttributeName)
        throws javax.management.AttributeNotFoundException,
               javax.management.InvalidAttributeValueException,
               javax.management.MBeanException,
               javax.management.ReflectionException

 getAttributes and setAttributes 

The methods getAttributes and setAttributes are used for getting and setting the values of several attributes of the Dynamic MBean respectively. The method declarations are given below:

public javax.management.AttributeList getAttributes(String[] AttributeNames)

public javax.management.AttributeList setAttributes(javax.management.AttributeList AttributeNames)


 invoke 

The method invoke allows an action (method) to be invoked on the Dynamic MBean. The method declarations are given below:

public Object invoke(String methodName, Object[] parameters, String[] signature)
                        throws javax.management.MBeanException,
                               javax.management.ReflectionException

Points to Remember
  1. Dynamic MBean must be a concrete class having at least one public constructor and should implement the javax.management.DynamicMBean interface.
  2. In a Dynamic MBean, the attributes and operations are formed by the MBeanInfo object returned by the getMBeanInfo method.
  3. No semantics to be followed for naming the Attributes. Mapping of some method foo( ) for an attribute with name ServerName is possible.
  4. Description of the MBean and its attributes and operations is possible.

<< Prev Home Next >>
Attribute Name Overloading When Dynamic MBean