Java Reference
In-Depth Information
specification does state that the management interface should not change, in
order for management tools to better perform their function.
5.6 Creating utility classes
After examining only two Dynamic MBeans, you probably have noticed that it
can sometimes be a tedious task to implement the getMBeanInfo() method.
Depending on the management interface, you may spend some time writing the
getMBeanInfo() method that constructs the MBeanInfo object. It can be tiring
work constructing an object for every exposed constructor, operation, attribute,
and notification. It would be nice not to have to write that method for every
Dynamic MBean you create.
This section creates a super class for Dynamic MBeans that makes it easier to
create MBeanInfo objects.
5.6.1
Creating a dynamic MBean super class
After you have written a few Dynamic MBeans, you begin to want to avoid writ-
ing the code that creates the MBeanInfo object. One way to solve this problem is
to create methods that do it for you and reuse that code. You can do so by using
a super class for Dynamic MBeans that provides a generic implementation of the
DynamicMBean interface.
The super class contains generic getAttribute() , setAttribute() , and
invoke() method implementations. In addition, it needs a mechanism for gener-
ically creating an MBeanInfo object to return in the getMBeanInfo() method. The
DynamicMBeanSupport class in listing 5.2 is such a super class.
Listing 5.2
DynamicMBeanSupport.java
package jmxbook.ch5;
Implement
javax.management.DynamicMBean
import javax.management.*;
import java.lang.reflect.*;
import java.util.*;
public class DynamicMBeanSupport implements DynamicMBean
{
protected MBeanInfo mbeanInfo = null;
protected Hashtable attributes = new Hashtable();
protected Hashtable notifications = new Hashtable();
protected Hashtable constructors = new Hashtable();
protected Hashtable operations = new Hashtable();;
//exposed fields
protected String description = "Description of the MBean";
Search WWH ::




Custom Search