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 which defines generic methods to access attributes and operations. Since the management interface is no longer visible through introspection, dynamic MBeans must also provide a description of their attributes and operations explicitly.
The DynamicMBean class is a Java interface defined by the Java Management extensions. It specifies the methods that a resource implemented as a dynamic MBean must provide to expose its management interface. Here is an uncommented version of the code:
public interface DynamicMBean { public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException; public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException ; public AttributeList getAttributes(String[] attributes); public AttributeList setAttributes(AttributeList attributes); public Object invoke( String actionName, Object params[], String signature[]) throws MBeanException, ReflectionException ; public MBeanInfo getMBeanInfo(); } |
The getMBeanInfo method is the one which provides a description of the MBean's management interface. This method returns an MBeanInfo object which is the descriptor type that contains information about attributes and operations.
The attribute getters and setters are generic, since they take the name of the attribute which 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.
Since 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 which 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 having a specific getter called by name, the generic getter must verify the attribute name and then encode the functionality to read each of the possible attributes.
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, they are referred to as the MBean descriptor classes because they provide information about the MBean. This information includes the attributes and operations of the management interface but also the list of constructors for the MBean class and the notifications that the MBean may send. Notifications are messages in the event mechanism that is defined by the JMX architecture; they are covered in the notification example in examplesDir/Notification.
Each element is described by its descriptor object containing its name, a description string, and its characteristics. For example, an attribute has a type and is readable and/or writeable. The following table lists all MBean descriptor classes:
Class Name |
Purpose |
---|---|
MBeanInfo | Top-level object containing arrays of descriptors for all MBean elements; also includes the name of the MBean's Java class and a description string |
MBeanFeatureInfo | Parent class for all other descriptors so that they 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 writeable |
MBeanNotificationInfo | Contains an array of notification type strings |