如何向JMX MXBean添加描述

编程入门 行业动态 更新时间:2024-10-12 03:17:07
本文介绍了如何向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.glassfish.gmbal.Description; import com.sun.glassfish.gmbal.DescriptorFields; import com.sun.glassfish.gmbal.Impact; import com.sun.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添加描述

本文发布于:2023-11-12 11:22:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581360.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:JMX   MXBean

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!