HelloWorldDynamic
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的更多相关文章
- JmxTest
package mbeanTest; import java.util.Set; import javax.management.Attribute; import javax.management. ...
随机推荐
- geoserver控制服务访问权限-类似百度地图的key
目录 缘起 可行性分析 如何实现key验证访问 如何控制key能访问哪些地图服务? 如何实现服务器ip白名单 流程梳理 申请key 访问地图 实施步骤 拦截器设置 配置key验证规则 配置服务拦截规则 ...
- 常见的yaml写法-CronJob
CronJob其实就是在Job的基础上加上了时间调度,我们可以:在给定的时间点运行一个任务,也可以周期性地在给定时间点运行.这个实际上和我们Linux中的crontab就非常类似了.一个CronJob ...
- 解决tomcat的404问题
遇到的问题 点击startup.bat启动tomcat启动成功,但在网页上输入local:8080却显示Access Error: 404 -- Not Found Cannot locate doc ...
- 问题 B: 比大小
题目描述 给你两个很大的数,你能不能判断出他们两个数的大小呢? 比如123456789123456789要大于-123456 输入 每组测试数据占一行,输入两个不超过1000位的10进制整数a,b 数 ...
- GO语言数据结构之链表
链表是一种物理存储单元上非连续.非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的.链表由一系列结点(链表中每一个元素称为结点)组成,结点可以在运行时动态生成.每个结点包括两个部分: ...
- vue3 学习笔记 (二)——axios 的使用有变化吗?
本篇文章主要目的就是想告诉我身边,正在学 vue3 或者 准备学 vue3 的同学,vue3中网络请求axios该如何使用,防止接触了一点点 vue3 的同学会有个疑问?生命周期.router .vu ...
- ipython和pip,模块安装方法
先下载 pip-.tar.gz 解压文件 cmd进入这个加压后的文件 执行 python setup.py install 然后配置环境变量 把 python 下的 Scripts 文件目录添加到 P ...
- logstash的filter之grok
logstash的filter之grokLogstash中的filter可以支持对数据进行解析过滤. grok:支持120多种内置的表达式,有一些简单常用的内容就可以使用内置的表达式进行解析 http ...
- FastAPI 学习之路(六十一)使用mysql数据库替换sqlite数据库
我们首先需要安装对应的连接的依赖 pip install pymysql 然后在配置testDatabase.py from sqlalchemy import create_engine from ...
- [spojQTREE6]Query on a tree VI
考虑如下构造: 新建一条边$(0,1)$,并将原树以0为根建树,记$fa_{x}$为$x$的父亲(其中$1\le x\le n$) 维护两棵森林,分别记作$T_{0/1}$,每一条边恰属于一棵,其中$ ...