Search |
||
Adding Descriptors to MBeans in MustangPosted by emcmanus on October 22, 2005 at 9:41 AM PDT
Descriptors allow you to give additional information about MBeans to management clients. For example, a Descriptor on an MBean attribute might say what units it is measured in, or what its minimum and maximum possible values are. As of Mustang (Java SE 6), Descriptors are a basic part of the JMX API and are available in all types of MBeans. Here's the easiest way to use them. Mustang makes it very convenient to add information to an MBean. You can use annotations in a Standard MBean to define the Descriptor contents. For example, with this definition...
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Units {
@DescriptorKey("units")
String value();
}
...you can define an annotation
public interface CacheMBean {
@Units("whatsits")
public int getUsed();
}
You can just cut-and-paste the @-infested text that defines
As usual with Standard MBeans, you can make an MBean by
defining a class
MBeanServer mbeanServer =
Now you can see the units of the
MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(name);
for (MBeanAttributeInfo a : mbeanInfo.getAttributes()) {
Descriptor d = a.getDescriptor();
System.out.println("Attribute " + a.getName() + " has units " +
d.getFieldValue("units"));
}
...and as expected this will print... Attribute Used has units whatsits If the Descriptor doesn't contain a value for
You can imagine that a management console such as
jconsole
might use this kind of code to add a label to a graph of the
This picture comes from my session at this year's JavaOne. Sessions are now online for free! If you're unable to migrate to Mustang just yet, I have a later blog entry describing how to use descriptors with Tiger and earlier versions of the J2SE platform. »
Related Topics >>
Open JDK Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|