I have created a small wrapper that will create a dynamic MBean out of a normal Java class through annotations. With it you can also add descriptions to beans, attributes, operations and parameters.
It also supports externalization and localization of names and descriptions using Java ResourceBundles.
Example of an annotated class:
@JMXBean(description = "My first JMX bean test")
public class MyBean {
int level = 0;
@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;
}
}
Example of an annotated class using ResourceBundles:
@JMXBean(resourceBundleName="com.example.my.package.BundleName")
public class MyBean {
int level = 0;
@JMXBeanAttribute(nameKey="level", descriptionKey="levelDescription")
public int getLevel() {
return level;
}
}
How to use it:
MyBean bean = new MyBean();
JMXBeanWrapper wrappedBean = new JMXBeanWrapper(bean);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbs.registerMBean(wrappedBean, new Objectname("com.example.my.package:type=TestBean,name=My Bean"));
You can find the source on GitHub