Description for Standard MBean

青春壹個敷衍的年華 提交于 2019-12-07 06:36:51

问题


I want to make my Standard MBean verbose in JBoss jmx-console. DynamicMBean has getMBeanInfo() to do it. Method return MBeanInfo with description of MBean. But how I can to do the same thing for Standard MBean? E.g. I have following MBean interface:

public interface MyMBean {
  String f();
}

... with following implementation:

public class My implements MyMBean {
  public String f() {
    return "test";
  }
}

What should be done to add description in such example?

Thanks


回答1:


For StandardMBeans there is no way for adding description or other meta information.

From the JavaDoc of MBeanInfo:

The remaining details of the MBeanInfo for a Standard MBean are not specified. This includes the description of the MBeanInfo and of any contained constructors, attributes, operations, and notifications; and the names and descriptions of parameters to constructors and operations.

So you need to use at least DynamicMBeans (or a ModelMBean or OpenMBean) for specifying this information. Spring can help you insofar as it allows the creation of DynamicMBeans via annotations, which at the end is even simpler to use than to write own StandardMBeans. Example (from the spring documentation) :

@ManagedResource(objectName="bean:name=testBean4",
                 description="My Managed Bean")
public class AnnotationTestBean {

    private int age;

    @ManagedAttribute(description="The Age Attribute", currencyTimeLimit=15)
    public int getAge() {
        return age;
    }
}

See this article for details.




回答2:


You can do this via an xmbean-descriptor without the need to modify the existing mbean source code.

See How to add description for MBean method to see it in jmx-console of JBOSS for an answer to this.




回答3:


The way to get the description information from Spring annotations @Managed* is just to declare a standard Spring "managed bean", and not an MBean or MXBean.

To do this, in your example, you must not implements the interface with "MBean" suffix. Then, the bean will be detected as a standard "managed bean" when MBeanExporter will registerBeanInstance(..), and will be converted to a ModelMBean using all spring annotations, including descriptions of attributes, operations, parameters, etc..

As a requirement, you should declare in your spring context the MBeanExporter with AnnotationJmxAttributeSource, MetadataNamingStrategy, and MetadataMBeanInfoAssembler attributes, which can be simplified like this :

<bean id="mbeanExporter"
     class="org.springframework.jmx.export.annotation.AnnotationMBeanExporter" />

or

<context:mbean-export />

And your managed bean should look like this (as explained by Roland) :

@Component("myManagedBean")
@ManagedResource(objectName="your.domain.jmx:name=MyMBean",
                 description="My MBean goal")
public class AnnotationTestBean {

    private int age;

    @ManagedAttribute(description="The age attribute", currencyTimeLimit=15)
    public int getAge() {
        return age;
    }

    @ManagedOperation(description = "Check permissions for the given activity")
    @ManagedOperationParameters( {
        @ManagedOperationParameter(name = "activity",
                                   description = "The activity to check")
    })
    public boolean isAllowedTo(final String activity) {
        // impl
    }
}

Remember to not implements an MBean interface, which would be a StandardMBean !!



来源:https://stackoverflow.com/questions/5258603/description-for-standard-mbean

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!