I'm using JBoss 4.3.2.GA
I've added method to my MBean service. Method has several arguments in signature. It works fine but I want more.
Problem: when I see method signature in jmx-console, I don't know what every of this input fields means, because jmx-console doesn't show arguments names, only input fields for values.
Is there ability add description of every argument (in Java code, not xml) allowing to show this description in jmx-console of JBOSS?
I've tried to use Spring annotation: @ManagedOperation
to add at least method description but no results (description is not showed in jmx-console).
May be some one have resolved such issue...
In Java, you can do this, if you don't use standard MBeans, but e.g. DynamicMBean
s for which you need to implement getMBeanInfo()
which is returning all that data.
This is a generic way, not limited to JBoss. But it is also a lot of work, which (IMO) only makes sense if you really need the dynamic features of a DynamicMBean.
For completeness sake (and as this may be the easier approach):
You can write an xmbean-descriptor and put that e.g. into $SERVER/conf/xmdesc/
In addition to this you need to enhance the standard MBeean-descriptor like this (note the xmbean-dd
attribute:
<mbean code="org.jnp.server.NamingBeanImpl"
name="jboss:service=NamingBeanImpl"
xmbean-dd="resource:xmdesc/NamingBean-xmbean.xml">
</mbean>
This example is taken from $SERVER/conf/jboss-service.xml and the NamingBean-xmban.xml is in the path described by the attribute.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With