public class JMXBeanWrapper
extends javax.management.NotificationBroadcasterSupport
implements javax.management.DynamicMBean
This is a wrapper class that wraps a normal Java object into a JMX dynamic bean by using Java annotations. It supports free naming and description of the bean, bean attributes, operations and operation parameters. To create a dynamic JMX bean, simply annotate your normal Java class and pass an instance of it to the constructor. This wrapper class will act as a proxy between the JMX system and your logic. Simply register the wrapped bean with JMX and you can access it through JCOnsole, JVisualVM and other JMX clients. Four annotation types are used to describe the bean:
JMXBean
: Marks and describes a class to be used as a dynamic JMX bean.JMXBeanKey
: Marks the getter method used to set the key for the bean.JMXBeanAttribute
: Marks and describes methods (setter/getter) in a JMXBean to be used as a JMX attribute.JMXBeanOperation
: Marks and describes a method to be used as a JMX operation.JMXBeanParameter
: Describes a method parameter for JMX operation parametersHere is an example of an annotated class:
@JMXBean(description = "My first JMX bean test") public class MyBean { private int level = 0; @JMXBeanKey public String getBeanKey() { return "bean.key:name=mybean,level=" + level; } @JMXBeanAttribute(name = "Floor Level", description = "The current floor level") public int getLevel() { return level; } @JMXBeanAttribute public void setLevel(int newLevel) { level = newLevel; } @JMXBeanOperation(name = "Echo Test", description = "Echoes the parameter back to you") public String myMethod( @JMXBeanParameter(name = "Input", description = "String of what to echo") String param) { return "You said " + param; } }
MyBean myBean = new MyBean(); MBeanServerManager mBeanServerManager = MBeanServerManagerFactory.newInstance(dataSource.getMBeanServer(), "Demo-0", logger); mBeanServerManager.registerMBean(myBean);
Constructor and Description |
---|
JMXBeanWrapper(java.lang.Object bean)
Creates a new dynamic JMX bean on the basis of an annotated class.
|
Modifier and Type | Method and Description |
---|---|
void |
addRelationshipAttribute(javax.management.Attribute attribute,
java.lang.String description)
Add relationship attribute to this bean
|
java.lang.Object |
getAttribute(java.lang.String attribute) |
javax.management.AttributeList |
getAttributes(java.lang.String[] attributes) |
java.lang.Object |
getInnerObject()
Access to the wrapped bean
|
javax.management.MBeanInfo |
getMBeanInfo() |
java.lang.Object |
invoke(java.lang.String actionName,
java.lang.Object[] params,
java.lang.String[] signature) |
void |
setAttribute(javax.management.Attribute attribute) |
javax.management.AttributeList |
setAttributes(javax.management.AttributeList attributes) |
java.lang.String |
toString()
Joins the toString() method on the inner object and appends the toString() method of
MBeanInfo |
public JMXBeanWrapper(java.lang.Object bean) throws java.lang.SecurityException, javax.management.IntrospectionException
bean
- The bean object which acts as a proxy target.java.lang.SecurityException
javax.management.IntrospectionException
public void addRelationshipAttribute(javax.management.Attribute attribute, java.lang.String description)
attribute
- Attribute key value pair of name and object it links todescription
- of this attribute that will appear in a JMX Consolepublic java.lang.Object getAttribute(java.lang.String attribute) throws javax.management.AttributeNotFoundException, javax.management.MBeanException, javax.management.ReflectionException
getAttribute
in interface javax.management.DynamicMBean
javax.management.AttributeNotFoundException
javax.management.MBeanException
javax.management.ReflectionException
public void setAttribute(javax.management.Attribute attribute) throws javax.management.AttributeNotFoundException, javax.management.InvalidAttributeValueException, javax.management.MBeanException, javax.management.ReflectionException
setAttribute
in interface javax.management.DynamicMBean
javax.management.AttributeNotFoundException
javax.management.InvalidAttributeValueException
javax.management.MBeanException
javax.management.ReflectionException
public javax.management.AttributeList getAttributes(java.lang.String[] attributes)
getAttributes
in interface javax.management.DynamicMBean
public javax.management.AttributeList setAttributes(javax.management.AttributeList attributes)
setAttributes
in interface javax.management.DynamicMBean
public java.lang.Object invoke(java.lang.String actionName, java.lang.Object[] params, java.lang.String[] signature) throws javax.management.MBeanException, javax.management.ReflectionException
invoke
in interface javax.management.DynamicMBean
javax.management.MBeanException
javax.management.ReflectionException
public javax.management.MBeanInfo getMBeanInfo()
getMBeanInfo
in interface javax.management.DynamicMBean
public java.lang.Object getInnerObject()
public java.lang.String toString()
MBeanInfo
toString
in class java.lang.Object
Please send bug reports and comments to Caplin support