Java Dynamic Management Kit 5.1 Tutorial

2.1 Exposing the Management Interface

In the standard MBean, attributes and operations are exposed statically in the names of methods in the MBean interface. Dynamic MBeans all share the same interface that defines generic methods to access attributes and operations. Because the management interface is no longer visible through introspection, dynamic MBeans must also provide a description of their attributes and operations explicitly.

2.1.1 DynamicMBean Interface

The DynamicMBean class is a Java interface defined by the Java Management Extensions (JMX) specification. It specifies the methods that a resource implemented as a dynamic MBean must provide to expose its management interface. Example 2–1 shows the uncommented code for the DynamicMBean interface.


Example 2–1 The DynamicMBean Interface

public class SimpleDynamic
    extends NotificationBroadcasterSupport
    implements DynamicMBean {

[...]

    public MBeanInfo getMBeanInfo() {

        return dMBeanInfo;
    }

The getMBeanInfo method provides a description of the MBean's management interface. This method returns an dMBeanInfo object that contains the metadata information about attributes and operations.

The attribute getters and setters are generic, since they take the name of the attribute that needs to be read or written. For convenience, dynamic MBeans must also define bulk getters and setters to operate on any number of attributes at once. These methods use the Attribute and AttributeList classes to represent attribute name-value pairs and lists of name-value pairs, respectively.

Because the names of the attributes are not revealed until runtime, the getters and setters are necessarily generic. In the same way, the invoke method takes the name of an operation and its signature, in order to invoke any method that might be exposed.

As a consequence of implementing generic getters, setters, and invokers, the code for a dynamic MBean is more complex than for a standard MBean. For example, instead of calling a specific getter by name, the generic getter must verify the attribute name and then encode the functionality to read each of the possible attributes.

2.1.2 MBean Metadata Classes

A dynamic MBean has the burden of building the description of its own management interface. The JMX specification defines the Java objects used to completely describe the management interface of an MBean. Dynamic MBeans use these objects to provide a complete self description as returned by the getMBeanInfo method. Agents also use these classes to describe a standard MBean after it has been introspected.

As a group, these classes are referred to as the MBean metadata classes because they provide information about the MBean. This information includes the attributes and operations of the management interface, also the list of constructors for the MBean class, and the notifications that the MBean might send. Notifications are event messages that are defined by the JMX architecture. See Chapter 8, Notification Mechanism.

Each element is described by its metadata object containing its name, a description string, and its characteristics. For example, an attribute has a type and is readable and/or writable. Table 2–1 lists all MBean metadata classes.

Table 2–1 MBean Metadata Classes

Class Name 

Purpose 

MBeanInfo

Top-level object containing arrays of metadata objects for all MBean elements; also includes the name of the MBean's Java class and a description string 

MBeanFeatureInfo

Parent class from which all other metadata objects inherit a name and a description string 

MBeanOperationInfo

Describes an operation: the return type, the signature as an array of parameters, and the impact (whether the operation just returns information or modifies the resource) 

MBeanConstructorInfo

Describes a constructor by its signature 

MBeanParameterInfo

Gives the type of a parameter in an operation or constructor signature 

MBeanAttributeInfo

Describes an attribute: its type, whether it is readable, and whether it is writable 

MBeanNotificationInfo

Contains an array of notification type strings