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. Mysql教程:(四)连接查询

    连接查询 1.左连接查询: mysql> select stu.*,sc.*,maths+sc.chinese+sc.english from student stu left join sco ...

  2. 在Express 中获取表单请求体数据

    在Express 中获取表单请求体数据 获取 GET 请求参数 获取 POST 请求体数据 安装 配置 获取 GET 请求参数 Express 内置了一个 API , 可以直接通过 req.query ...

  3. 菜鸡的Java笔记 第七 - java 数组

    数组的基本概念     笔试中经常出现的试题或是问题    1.1 概念        数组指的是一组相关变量的集合         如果用最原始的方式定义100个变量的话没问题但是这些变量的关联实在 ...

  4. 介绍一款docker管理工具——portainer

    介绍一款docker管理工具--portainer 目录 介绍一款docker管理工具--portainer 1.背景 1.1 管理docker方法上一般有两种 1.1.1 命令行形式 1.1.2 U ...

  5. C#窗体学习

    //进度条控件 private void button1_Click(object sender, EventArgs e)        {            int i;            ...

  6. [atAGC022D]Shopping

    称0到$L$的方向为左,同时为了方便,可以假设$0<t_{i}\le 2L$ 当我们确定是进入店中的方向,根据这个店的位置以及购物时间,不难确定出来时火车经过0或$L$的次数,由于$0<t ...

  7. [bzoj4651]网格

    考虑将最上中最左的跳蚤孤立,容易发现他的上面和左面没有跳蚤,因此只需要将他的右边和下边替换掉就可以了答案为-1有两种情况:1.c>=n*m-1;2.c=n*m-2且这两只跳蚤相邻对于其他情况,将 ...

  8. 如何反向推断基因型文件中的参考碱基(REF/ALT)?

    目录 需求 解决 方法一 方法二 需求 客户随手丢来一个基因型文件,类似于hapmap格式,只是少了中间多余的那几列,像这种类hapmap格式文件,往往是芯片数据. 这样的数据因为缺乏等位基因:参考碱 ...

  9. spring-boot spring-MVC自动配置

    Spring MVC auto-configuration Spring Boot 自动配置好了SpringMVC 以下是SpringBoot对SpringMVC的默认配置:==(WebMvcAuto ...

  10. 基于MS SQL Server的数据库学习安排

    序号 分类 学习内容 目标/要求 方式 学时 考核 参考资料 1 基础知识 数据库理论 理解数据库基本理论 面授 1 能阐述元素.数据记录.数据表.数据库的基本概念T-SQL语法要求 https:// ...