4.2 The ModelMBean Interface

The model MBean implementation, including RequiredModelMBean , must implement the ModelMBean interface, which extends three other JMX interfaces: DynamicMBean , PersistentMBean , and ModelMBeanNotificationBroadcaster . Here's how these interfaces are used in the model MBean.

4.2.1 DynamicMBean

Because it is a dynamic MBean, the model MBean must implement the DynamicMBean interface, which consists of the getAttribute() , setAttribute() , invoke() , and getMBeanInfo() methods . The getMBeanInfo() method returns a ModelMBeanInfo instance that extends MBeanInfo . The model MBean uses the additional information in the descriptors in ModelMBeanInfo to delegate and map these operations to the correct operations on your managed resources. You do not need to implement these methods unless you need to override the default behavior. The DynamicMBean and basic MBeanInfo interfaces were explained fully in Chapter 3.

4.2.2 PersistentMBean

The model MBean is also responsible for its own persistence and therefore must implement the PersistentMBean interface. The PersistentMBean interface is simply the load() and the store() methods. This does not mean that a model MBean must persist itself. Some implementations of the JMX agent may be completely transient in nature. In this situation, the load() and store() methods would be empty. The load() method is invoked when the model MBean is instantiated . The store() method is invoked according to the policy defined in the descriptors in the ModelMBeanInfo of the MBean (to be discussed later in this chapter).

In a simple implementation, the model MBean may be saved to a file. Alternatively, it may be saved to a database through JDBC (a.k.a., the Java Database Connectivity API). In a more complex environment, the JMX agent may handle persistence on behalf of the model MBean. If you are using an implementation of JMX that has an implementation of RequiredModelMBean that does not support persistence and you need support for persistence, then you must override and implement the load() and store() methods. Here is the PersistentMBean interface:

 interface PersistentMBean {         void load();        void store(); } 

The model MBean constructor will attempt to prime itself by calling the model MBean load() method. The model MBean load() method must determine if this model MBean has a persistent representation. It can do this by invoking the findInPersistent() method; this is not a JMX standard, but it is a common practice. Then the load() method must determine where this data is located, retrieve it, and initialize the model MBean. The model MBean can, through JDBC operations, persist data to and populate the model MBeans from any number of data storage options, such as an LDAP [8] server, a DB2 [9] application, a flat file, an NFS [10] file, or an internal high-performance cache. If the model MBean were implemented as an EJB object, object loading might be managed by the EJB container and the load() method would do nothing.

Because the load() method is not typically used by the application or adapter, the JMX agent can be independent and ignorant of data locale information and knowledge. Thus, data location may vary from one installation to another, depending on how the JMX agent and managed resource are installed and configured. Data locale independence also permits application configuration data to be defined within the directory service for use by multiple application instances or JMX agent instances. In this way, data locale has no impact on the interaction between the application, its model MBean, the JMX agent, the adapter, or the management system. As with all data persistence issues, the platform data services characteristics may have an impact on performance and security.

4.2.3 ModelMBeanNotificationBroadcaster

The ModelMBeanNotificationBroadcaster interface extends the NotificationBroadcaster interface and adds support for issuing generic text notifications and attribute change notifications. These events are sent only if at least one NotificationListener instance is registered with the model MBean. Generic text notifications are simple to use, accepting any text string and sending it as a notification. Attribute change notifications are sent by the model MBean whenever one of its attribute's values changes. The MBean can also send an attribute change notification to the managed resource itself. For example, if a configuration program has just changed an attribute in the MBean and a setter does not exist for that attribute, the MBean could send an attribute change notification to the managed resource, given that the managed resource implements the NotificationListene r interface. The managed resource would detect the change in its external configuration (held by the MBean), and it would make the internal adjustments necessary to comply . Application-specific notifications are supported like they are for any other MBean. Here is the ModelMBeanNotificationBroadcaster interface:

 interface ModelMBeanNotificationBroadcaster extends     NotificationBroadcaster {    addAttributeChangeNotificationListener(             javax.management.NotificationListener inlistener,             java.lang.String inAttributeName,             java.lang.Object inhandback);    removeAttributeChangeNotificationListener(             javax.management.NotificationListener inlistener,             java.lang.String inAttributeName);    sendAttributeChangeNotification(             javax.management.Attribute inOldVal,             javax.management.Attribute inNewVal);    sendAttributeChangeNotification(              javax.management.AttributeChangeNotification ntfyObj);    sendNotification(javax.management.Notification ntfyObj);    sendNotification(java.lang.String ntfyText); } 

The ModelMBean interface has two additional methods:

 void setManagedResource(java.lang.Object managedResourceReference,              java.lang.String managedResourceReference_type); void setModelMBeanInfo(ModelMBeanInfo ModelMBeanInfo_instance); 

Let's look at how these methods are used to customize your model MBean.



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