本文介绍了如何向JMX MXBean添加描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Apache-Tomcat 7.0上公开我的MXBean.尽管我的MXBean成功注册,但是我无法向这些MXBean公开的操作添加描述.

I want to expose my MXBeans on Apache-Tomcat 7.0.Though my MXBean registers successfully, I am unable to add description to the Operations that are exposed by thoese MXBeans.

注册MXBeans

MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName m_mxbeanOName = new ObjectName( "MyMXBean:type=" + "MyComponent"+",name=MyMXBean");
MyMXBean m_mxbean = new MyMXBean ();
if(!mbs.isRegistered(m_mxbeanOName))
    mbs.registerMBean(m_mxbean,  m_mxbeanOName);

MyMXBean接口

MyMXBean Interface

public interface MyMXBean {
    public int add (int x, int y);
}

MyMXBean实现

MyMXBean Implementation

import com.sun.org.glassfish.gmbal.Description;
import com.sun.org.glassfish.gmbal.DescriptorFields;
import com.sun.org.glassfish.gmbal.Impact;
import com.sun.org.glassfish.gmbal.ManagedOperation;

public class MyMXBeanImpl implements MyMXBean {
    @ManagedOperation(impact=Impact.ACTION_INFO)
    @Description("Integer Addition: First parameter is the augend and second parameter is the addend.")
    @DescriptorFields({"p1=augend","p2=addend"})
    public int add(int x, int y) {
        return x + y;
    }

注释@ ManagedOperation,@ Description,@ DescriptorFields对jconsole不起作用. JConsole继续显示默认值

The annotation @ManagedOperation, @Description, @DescriptorFields has no effect on the jconsole. JConsole continues to show default values

请告诉我如何在JConsole上显示有关MXBean操作的描述.

Please tell me ways to show the description about my MXBean operations on JConsole.

推荐答案

我发现的最干净的方法是使用StandardMBean(或StandardEmitterMBean)作为您向JMX注册的实际对象.然后,子类StandardMBean并重写各种getDescription方法.在这些方法中,阅读包含描述的注释.

The cleanest way I have found to do this is to use StandardMBean (or StandardEmitterMBean) as the actual object you register with JMX. Then, subclass StandardMBean and override the various getDescription methods. In those methods, read your annotations that contain the descriptions.

这篇关于如何向JMX MXBean添加描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 03:25