java 如何为MBean方法添加描述以在JBOSS的jmx-console中查看
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5077175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add description for MBean method to see it in jmx-console of JBOSS
提问by Zaur_M
I'm using JBoss 4.3.2.GA
我正在使用 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.
我已经向我的 MBean 服务添加了方法。方法在签名中有几个参数。它工作正常,但我想要更多。
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.
问题:当我在 jmx-console 中看到方法签名时,我不知道每个输入字段的含义,因为 jmx-console 不显示参数名称,只显示值的输入字段。
Is there ability add description of every argument (in Java code, not xml) allowing to show this description in jmx-console of JBOSS?
是否有能力添加每个参数的描述(在 Java 代码中,而不是 xml)允许在 JBOSS 的 jmx-console 中显示这个描述?
I've tried to use Spring annotation: @ManagedOperation
to add at least method description but no results (description is not showed in jmx-console).
我尝试使用 Spring 注释:@ManagedOperation
至少添加方法描述但没有结果(描述未显示在 jmx-console 中)。
May be some one have resolved such issue...
可能有人已经解决了这样的问题......
回答by Heiko Rupp
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.
在 Java 中,如果您不使用标准 MBean,但DynamicMBean
您需要实现的 sgetMBeanInfo()
返回所有数据,则可以执行此操作。这是一种通用方式,不限于 JBoss。但这也需要大量工作,只有当您确实需要 DynamicMBean 的动态特性时,这 (IMO) 才有意义。
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:
您可以编写一个 xmbean-descriptor 并将其放入例如 $SERVER/conf/xmdesc/ 除此之外,您需要像这样增强标准 MBeean-descriptor(注意xmbean-dd
属性:
<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.
此示例取自 $SERVER/conf/jboss-service.xml,NamingBean-xmban.xml 位于属性描述的路径中。
回答by Udo Klimaschewski
I have created a small wrapperthat 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.
我创建了一个小包装器,它将通过注释从普通 Java 类中创建一个动态 MBean。使用它,您还可以向 bean、属性、操作和参数添加描述。
It also supports externalization and localization of names and descriptions using Java ResourceBundles.
它还支持使用 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:
使用 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
你可以在GitHub 上找到源代码
回答by Simon Gibbs
I've had success with mixing Spring XML and Spring annotations where I had multiple MBeans of the same Java class. The approach allowed tight control over bean names and allowed me to define descriptions etc at the class level. I needed to define an annotation based bean assembler for an MBeanExporter, and supply a map of bean names and bean references:
我在混合 Spring XML 和 Spring 注释方面取得了成功,其中我有多个相同 Java 类的 MBean。该方法允许对 bean 名称进行严格控制,并允许我在类级别定义描述等。我需要为 MBeanExporter 定义一个基于注释的 bean 组装器,并提供 bean 名称和 bean 引用的映射:
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"
lazy-init="false">
<property name="server" ref="mbeanServer" />
<property name="assembler">
<!-- will create management interface using annotation metadata -->
<bean class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
<property name="attributeSource">
<bean class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/>
</property>
</bean>
</property>
<property name="beans">
<map>
<!-- entries -->
</map>
</property>
</bean>
An example of what I read from Java annotations might be:
我从 Java 注释中读取的内容的一个示例可能是:
@ManagedAttribute(description = "A detailed description to show in JConsole tooltips etc")
public String getFoo() {
return foo;
}
I had the assemblers defined privately to the exporter, but you could share those beans more widely I'm sure.
我让出口商私下定义了汇编程序,但我相信你可以更广泛地共享这些 bean。
BTW this was on Tomcat.
顺便说一句,这是在Tomcat上。