4.4 ModelMBeanInfo

The model MBean uses a ModelMBeanInfo class for metadata. ModelMBeanInfo extends the MBeanInfo class by adding a descriptor to each of the elements of the management interface: attributes, operations, and notifications. Descriptors are a list of name /value pairs that describe additional metadata about the resource and behavioral policy for the model MBean instance. The descriptors control how attribute values are cached or persisted , which attributes are retrievable from other objects, whether notifications are logged, where logs are located, along with other descriptive data. This is the ModelMBeanInfo interface:

 interface ModelMBeanInfo {    Object clone():   Descriptor getMBeanDescriptor();   void setMBeanDescriptor(Descriptor inDescriptor );   Descriptor getDescriptor(String inDescriptorName,                            String inDescriptorType );   Descriptor[] getDescriptors (String inDescriptorType );   void setDescriptor(Descriptor inDescriptor,                      String inDescriptorType );   void setDescriptors(Descriptor[] inDescriptors );   ModelMBeanAttributeInfo getAttribute(String inAttrName );   ModelMBeanNotificationInfo getNotification(String inNotifName );   ModelMBeanOperationInfo getOperation(String inOperName );   MBeanAttributeInfo[]getAttributes();   MBeanNotificationInfo[]getNotifications() ;   MBeanOperationInfo[]getOperations();   MBeanConstructorInfo[]getConstructors() ;   String getClassName();   String getDescription(); } 

In addition, ModelMBeanInfo is required to support the following constructors:

  • ModelMBeanInfo();

    The default constructor constructs a ModelMBeanInfo instance with empty component arrays and a default MBean descriptor.

  • ModelMBeanInfo (ModelMBeanInfo);

    The copy constructor constructs a ModelMBeanInfo instance that is a duplicate of the one passed in.

  • ModelMBeanInfo (className, String description ,

     ModelMBeanAttributeInfo[], ModelMBeanConstructorInfo[],  ModelMBeanOperationInfo[], ModelMBeanNotificationInfo[]) 

    The MBeanInfo -compliant constructor creates a ModelMBeanInfo instance with the provided information, but the MBean descriptor contains default value. Because the MBean descriptor must not be null , the default descriptor will contain at least the name and descriptorType fields. The name will match the MBean name.

  • ModelMBeanInfo (className, String description ,

     ModelMBeanAttributeInfo[], ModelMBeanConstructorInfo[],  ModelMBeanOperationInfo[], ModelMBeanNotificationInfo[], MBeanDescriptor) 

    The full constructor creates a ModelMBeanInfo instance with the provided information. The MBean descriptor is verified : If it is not valid, an exception will be thrown and a default MBean descriptor will be set. You can see that there is a descriptor associated with the model MBean itself. It must not be null .

The normal MBeanInfo methods return model MBean extensions of the AttributeInfo , OperationInfo , and NotificationInfo classes respectively. Each of the model MBean extensions implements the DescriptorAccess interface. The DescriptorAccess interface gives you access to attribute descriptor , operation descriptor , and notification descriptor , which are associated with AttributeInfo , OperationInfo , and NotificationInfo , respectively. This is the DescriptorAccess interface:

 interface DescriptorAccess {    Descriptor getDescriptor();   void setDescriptor(Descriptor inDescriptor); } 

The descriptor also defines the method signatures that will be executed by the model MBean on its managed resource to satisfy the getAttribute() , setAttribute() , and invoke() operations. As Figure 4.2 shows, defining the managed resource and method signature in the operation descriptor allows the actual methods called for an operation to have different signatures and to be delegated to a wide range of objects at runtime. This flexibility enables the management of distributed, dynamic applications directly from a model MBean.

Figure 4.2. JMX Model MBeans and Multiple Managed Resources

graphics/04fig02.gif

The descriptor-oriented methods in ModelMBeanInfo allow you to list and update any descriptor in the model MBean without having to retrieve the specific ModelMBeanAttributeInfo , ModelMBeanOperationInfo , ModelMBeanConstructorInfo , or ModelMBeanNotificationInfo class for it first. This is strictly a convenience for the programmer.

You can customize the model MBean during development by defining the ModelMBeanInfo instance in the program with the ModelMBeanInfo interface. Defining an instance of MBeanInfo directly in a program creates a static model MBean. You can also create model MBeans more dynamically. The descriptor values and ModelMBeanInfo attributes and operations can be loaded from the application or a file at runtime. This means that you can update or upgrade the management data along with your application without having to remove and reinstantiate all of the data. You could also use an Interface Definition Language (IDL) [11] or Managed Object Format (MOF) [12] file. Using external files whose formats are defined by standards permits management interfaces to be defined in a language-independent manner. The JMX specification does not define how to use XML, IDL, or MOF files for MBeanInfo data, but we include an example at the end of this chapter to illustrate the use of an XML service to load ModelMBeanInfo from an XML file.



Java and JMX. Building Manageable Systems
Javaв„ў and JMX: Building Manageable Systems
ISBN: 0672324083
EAN: 2147483647
Year: 2000
Pages: 115

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net