package mbeanTest;

import java.lang.reflect.Method;

import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.DynamicMBean;
import javax.management.InvalidAttributeValueException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.ReflectionException; public class HelloWorldDynamic implements DynamicMBean
{
public String hello; public HelloWorldDynamic()
{
this.hello = "Hello World! I am a Dynamic MBean";
} public HelloWorldDynamic(String hello)
{
this.hello = hello;
} public String getHello()
{
return hello;
} public Object getInstance()
{
return new Object();
} public void setHello(String hello)
{
this.hello = hello;
} @Override
public Object getAttribute(String attribute)
throws AttributeNotFoundException, MBeanException,
ReflectionException
{
// 设置getAttribute的执行逻辑
if ("getInstance".equals(attribute))
{
return getInstance();
}
if("gh".equals(attribute))
{
return "fffffff";
} return null;
} @Override
public AttributeList getAttributes(String[] attributes)
{
// TODO Auto-generated method stub
return null;
} MBeanInfo info = null; @Override
public MBeanInfo getMBeanInfo()
{
try
{
Class cls = this.getClass();
// 用反射获得 "getHello" 属性的读方法
// DynamicMBean中,
Method readMethod = cls.getMethod("getHello", new Class[0]);
MBeanAttributeInfo attribute = new MBeanAttributeInfo("gh",
" the first attribute ", readMethod, null);
// 执行java类的method需要的一些元数据,由MBeanOperationInfo提供
MBeanOperationInfo operation = new MBeanOperationInfo(
" the first operation ", cls.getMethod("getInstance", null));
info = new MBeanInfo(cls.getName(), " this is a dynamic MBean ",
new MBeanAttributeInfo[]
{ attribute }, null, new MBeanOperationInfo[]
{ operation }, null);
} catch (Exception e)
{
System.out.println(e);
}
return info;
} @Override
public Object invoke(String actionName, Object[] params, String[] signature)
throws MBeanException, ReflectionException
{
System.out.println(" the HelloWorldDynamic's method invoke ");
return null;
} @Override
public void setAttribute(Attribute attribute)
throws AttributeNotFoundException, InvalidAttributeValueException,
MBeanException, ReflectionException
{ } @Override
public AttributeList setAttributes(AttributeList attributes)
{
return null;
} }

HelloWorldDynamic的更多相关文章

  1. JmxTest

    package mbeanTest; import java.util.Set; import javax.management.Attribute; import javax.management. ...

随机推荐

  1. 启用或禁用普通用户Exchange Online PowerShell功能

    默认情况下,允许在 Microsoft 365 中创建的所有帐户都可以使用 Exchange Online PowerShell.管理员可以使用 Exchange Online PowerShell ...

  2. VMware软件虚拟机不能全屏的问题 & CentOS 安装Vmware Tools

    修改设置 1) 如下图右单击虚拟机名,选择[settings-],调出虚拟机设置界面. 2) 在设置界面选择[hardware]->[CD/DVD2(IDE)]->[Connection] ...

  3. redux 的简单实用案例

    redux 的简单实用案例 整体思想与结构 创建一个Action 创建一个Reducer 创建Store 在App组件开始使用 整体思想与结构 文件目录如下: 构建 action,通过创建一个函数,然 ...

  4. SqlServer新建表操作DDL

    创建新表:1,五要素 2,not null 3,默认值 4,字段注释,表名称 5,索引 6,指定约束名称 -- ------------------------------ Table structu ...

  5. tomcat9启动报错too low setting for -Xss

    在tomcat下部署war包启动时报错,关键错误信息如下: Caused by: java.lang.IllegalStateException: Unable to complete the sca ...

  6. Windows内核中的CPU架构-8-任务段TSS(task state segment)

    Windows内核中的CPU架构-8-任务段TSS(task state segment) 任务段tss(task state segment)是针对于CPU的一个概念. 举一个简单的例子,你一个电脑 ...

  7. 大一C语言学习笔记(4)---自省篇

    博主"曾经"做过的傻事: #你有的*没打全 #你用/的时候没考虑()是一对的 #printf随后加\n #所有变量只要用,就一定要定义数据类型 #sqrt()代表根号 #inclu ...

  8. Mui中mui.openWindow()方法具体参数信息(内容来自Mui问题专区)

    mui.openWindow({ url: 'xxx.html', //String类型,要打开的界面的地址 id: 'id', //String类型,要打开的界面的id styles: { //We ...

  9. Django笔记&教程 7-1 基于类的视图(Class-based views)介绍

    Django 自学笔记兼学习教程第7章第1节--基于类的视图(Class-based views)介绍 点击查看教程总目录 1 介绍 Class-based views (CBVs) are view ...

  10. scrapy获取汽车之家数据

    1.创建scrapy项目 >scrapy startproject scrapy_carhome 2.找到对应接口 3.创建爬虫文件 > cd scrapy_carhome\scrapy_ ...