Model MBean
A Model MBean is a Dynamic MBean, but it is more flexible than the Dynamic
MBeans. The main difference between a Model MBean and a Dynamic MBean
is that you do not develop the MBean class, since any JMX implementation
should provide a default implementation of the ModelMBean interface,
called RequiredModelMBean.
Advantages of Model MBeans over Dynamic MBeans
- A default implementation of ModelMBean (RequiredModelMBean) has to
be provided by the JMX implementation.
- While creating DynamicMBeans, the managed resource (object which contains
the Implementation details of the DynamicMBean) has to be specified. In
case of ModelMBeans, the managed resource can be set dynamically using the
setManagedResource method available in the RequiredModelMBean class. (More
details about setManagedResource are provided in the RequiredModelMBean section
in this topic.)
- In DynamicMBeans, all the required management information has to be
known in advance. Out of these management information, some information alone
can be exposed dynamically. In ModelMBeans, the management information
itself can be dynamically configured using the setModelMBeanInfo method.
- Additional data about the behavior of the attributes and operations
can be specified by using the Descriptors. (More information is provided
in the Descriptors section in this topic.)
- Custom Descriptors can be added.
- Translation of MBean data and data models into other management technologies
and their data models are possible using the protocolMap descriptor.
- Value added services, such as persistence, caching, attribute change
notifications, and logging are provided. Another important feature
is that these services can be customizable for each attribute and operation.
- The management information of a ModelMBean can be specified using a
file format, such as XML. This reduces a lot of coding.
ModelMBean metadata classes
The attributes, operations, and notifications, that is, the management information
for the Model MBean, are exposed using the ModelMBeanInfo interface. The
ModelMBeanAttributeInfo object describes an attribute of the ModelMBean. Similarly,
the ModelMBeanOperationInfo, ModelMBeanConstructorInfo, and ModelMBeanNotificationInfo
describe an operation, constructor, and notification of the ModelMBean. The
classes that describe the management information of a ModelMBean are called
ModelMBean metadata classes. The ModelMBean metadata classes are
- ModelMBeanAttributeInfo -- describes an attribute
- ModelMBeanOperationInfo -- describes the signature of an operation
- ModelMBeanConstructorInfo -- describes the signature of a constructor
- ModelMBeanNotificationInfo -- describes a notification
- DescriptorSupport -- provides additional information about an attribute,
operation, constructor, and notification
RequiredModelMBean
JMX implementations provide a default implementation of the ModelMBean interface
called RequiredModelMBean. This model MBean implementation is intended
to provide ease of use and extensive default management behavior for the
instrumentation. A model MBean can be created by extending the RequiredModelMBean
and can be overridden if necessary.
The RequiredModelMBean can be instantiated using the no argument constructor.
This constructs a RequiredModelMBean with an empty ModelMBeanInfo. The RequiredModelMBean's
MBeanInfo and Descriptors can be customized using the setModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo)
method. After the RequiredModelMBean's MBeanInfo
and Descriptors are customized, the RequiredModelMBean can be registered with
the MBeanServer. The managed resource (i.e. the instance handle of
the object against which all methods in this ModelMBean management interface
are executed) can be set to RequiredModelMBean, by the setManagedResource(java.lang.Object, String)
method which takes the actual managed object and its type, i.e. it can be
"ObjectReference", "Handle", "EJBHandle", "IOR" (Interoperable Object Reference),
or "RMIReference".
Descriptors
Descriptors classes implement the Descriptor interface and are used in the
Model MBean metadata to add behavioral policies, such as caching, persistence,
and logging for the management interface defined in the MBeanInfo to the managed
bean.
Descriptors are a list of name-value pairs (each has String as name and Object
as value) that provide additional information about behavior of attributes,
operations, and notifications. While defining the management interface for
an MBean attribute, it is possible to add a descriptor that describes the
behavioral policies for the attribute. The Model MBean implementation will
then try to adapt to match the required behavior. The behavioral descriptors
can also be changed via a management application or by the managed resource
at run time.