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控制台不显示参数名,只显示值的输入字段。
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控制台中显示此描述?
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 annotation: @ManagedOperation添加至少方法描述,但是没有结果(在jmx-console中没有显示描述)。
May be some one have resolved such issue...
也许有人已经解决了这个问题……
3 个解决方案
#1
3
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,您可以这样做,但是例如,需要实现getMBeanInfo()的dynamicmbean,它返回所有的数据。这是一种通用的方式,不仅限于JBoss。但这也需要大量的工作,(在我看来)只有在您真正需要dynamic mbean的动态特性时才有意义。
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:
您可以编写一个xml描述符,并将其放入$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位于属性所描述的路径中。
#2
2
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.
我已经创建了一个小包装器,它将通过注释从普通Java类中创建一个动态MBean。通过它,您还可以向bean、属性、操作和参数添加描述。
It also supports externalization and localization of names and descriptions using Java ResourceBundles.
它还支持使用Java resourcebundle对名称和描述进行外部化和本地化。
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:
使用resourcebundle的带注释类示例:
@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上找到源文件
#3
1
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名进行严格控制,并允许我在类级别定义描述等。我需要为mbeanexports定义一个基于注释的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上。
#1
3
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,您可以这样做,但是例如,需要实现getMBeanInfo()的dynamicmbean,它返回所有的数据。这是一种通用的方式,不仅限于JBoss。但这也需要大量的工作,(在我看来)只有在您真正需要dynamic mbean的动态特性时才有意义。
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:
您可以编写一个xml描述符,并将其放入$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位于属性所描述的路径中。
#2
2
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.
我已经创建了一个小包装器,它将通过注释从普通Java类中创建一个动态MBean。通过它,您还可以向bean、属性、操作和参数添加描述。
It also supports externalization and localization of names and descriptions using Java ResourceBundles.
它还支持使用Java resourcebundle对名称和描述进行外部化和本地化。
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:
使用resourcebundle的带注释类示例:
@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上找到源文件
#3
1
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名进行严格控制,并允许我在类级别定义描述等。我需要为mbeanexports定义一个基于注释的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上。