The instrumentation level of the JMX specification defines standards for making resources manageable in the Java programming language. The instrumentation of a manageable resource is provided by one or more Managed Beans, or MBeans. An MBean is a Java object that exposes attributes and operations for management. These attributes and operations enable any Java Dynamic Management agent to recognize and manage the MBean.
The design patterns for MBeans give the developer explicit control over how a resource, device or application will be managed. For example, attribute patterns enable you to make the distinction between a read-only and a read-write property in an MBean. The set of all attributes and operations exposed to management through the design patterns is called the management interface of an MBean.
Any resource that you want to make accessible through an agent must be represented as an MBean. Both the agent application and remote managers may access MBeans in an agent. MBeans can generate notification events which are sent to all local or remote listeners. For more information regarding managing MBeans remotely, please refer to "Communication Components".
MBeans can also be downloaded from a Web server and plugged into an agent at any time, in response to a demand from the management application. This is called dynamic class loading and means that future services and applications can be loaded on-the-fly and without any downtime. For example, dynamic class loading can be used to provide rapid, low-cost delivery of end-user applications across very large bases of Java technology-enabled devices, such as desktop PC's or Web phones.
There are three types of MBeans:
Standard MBeans
Dynamic MBeans
Model MBeans, which are an extension of dynamic MBeans
Standard MBeans are Java objects that conform to certain design patterns derived from the JavaBeans component model. Standard MBeans allow you to define your management interface straightforwardly in a Java interface. The method names of this interface determine getters and setters for attributes and the names of operations. The class implementation of this interface contains the equivalent methods for reading and writing the MBean's attributes and for invoking its operations, respectively.
The management interface of a standard MBean is static, and this interface is exposed statically. Standard MBeans are static because the management interface is defined by the source code of the Java interface. Attribute and operation names are determined at compilation time and cannot be altered at runtime. Changes to the interface will need to be recompiled.
Standard MBeans are the quickest and easiest type of MBeans to implement. They are suited to creating MBeans for new manageable resources and for data structures which are defined in advance and unlikely to change often.
Dynamic MBeans do not have getter and setter methods for each attribute and operation. Instead, they have generic methods for getting or setting an attribute by name, and for invoking operations by name. These methods are common to all dynamic MBeans and defined by the DynamicMBean interface.
The management interface is determined by the set of attribute and operation names to which these methods will respond. The getMBeanInfo method of the DynamicMBean interface must also return a data structure which describes the management interface. This metadata contains the attribute and operation names, their types, and the notifications that may be sent if the MBean is a broadcaster.
Dynamic MBeans provide a simple way to wrap existing Java object which do not follow the design patterns for standard MBeans. They can also be implemented to access non-Java technology based resources by using the Java Native Interface (JNI).
The management interface of a dynamic MBean is static, but this interface is exposed dynamically when the MBean server calls its getMBeanInfo method. The implementation of a dynamic MBean may be quite complex, for example if it determines its own management interface based on existing conditions when it is instantiated.
A model MBean is a generic, configurable, dynamic MBean which you can use to instrument a resource at runtime. A model MBean is an MBean template: the caller tells the model MBean what management interface to expose. The caller also determines how attributes and operations are implemented by designating a target object on which attribute access and operation invocation are actually performed.
The model MBean implementation class is mandated by the JMX specification, and therefore it is always available for instantiation in an agent. Management applications can use model MBeans to instrument resources on-the-fly.
To instrument a resource and expose it dynamically, you need to:
Instantiate the javax.management.modelmbean.RequiredModelMBean class in a JMX agent
Set the model MBean's management interface
Designate the target object which implements the management interface
Register the model MBean in the MBean server
The management interface of a model MBean is dynamic, and it is also exposed dynamically. The application which configures a model MBean may modify its management interface at any time. It may also change its implementation by designating a new target object.
Management applications access all types of MBeans in the same manner, and most applications are not aware of the different MBean types. However, if a manager understands model MBeans, it will be able to obtain additional management information about the managed resource. This informations includes behavioral and runtime metadata that is specific to model MBeans.