HelloWorldModelMBean
package mbeanTest; import java.lang.reflect.Constructor; import javax.management.Descriptor;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import javax.management.RuntimeOperationsException;
import javax.management.modelmbean.DescriptorSupport;
import javax.management.modelmbean.InvalidTargetObjectTypeException;
import javax.management.modelmbean.ModelMBeanAttributeInfo;
import javax.management.modelmbean.ModelMBeanConstructorInfo;
import javax.management.modelmbean.ModelMBeanInfo;
import javax.management.modelmbean.ModelMBeanInfoSupport;
import javax.management.modelmbean.ModelMBeanOperationInfo;
import javax.management.modelmbean.RequiredModelMBean; public class HelloWorldModelMBean extends RequiredModelMBean
{
public HelloWorldModelMBean() throws Exception
{} public static RequiredModelMBean createModelBean() throws RuntimeOperationsException, MBeanException,
InstanceNotFoundException, InvalidTargetObjectTypeException
{
// 模型MBean信息
ModelMBeanInfo info = buildModelMBeanInfo();
// 模型MBean
RequiredModelMBean modelMBean = new RequiredModelMBean(info);
// 目前只支持ObjectReference,将来可能会支持ObjectReference", "Handle", "IOR", "EJBHandle",
// or "RMIReference,
// RMIReference从名字上可以看出,如果支持的话,那么以后就可以支持远程MBean引用
modelMBean.setManagedResource(new HelloWorld(), "ObjectReference");
return modelMBean;
} protected static ModelMBeanInfo buildModelMBeanInfo() throws RuntimeOperationsException, MBeanException
{
// --
// attributes
// ------------------------------------------------------------------
ModelMBeanAttributeInfo[] attributes = new ModelMBeanAttributeInfo[1]; // 设置属性
Descriptor nameDesc = new DescriptorSupport();
nameDesc.setField("name", "hello");
nameDesc.setField("value", "这是value的值");
nameDesc.setField("hee", "这是hee的值");
nameDesc.setField("displayName", "myname");
nameDesc.setField("setMethod", "setHello");
nameDesc.setField("getMethod", "getHello");
nameDesc.setField("descriptorType", "attribute");
attributes[0] = new ModelMBeanAttributeInfo("hello",
"java.lang.String", "name say hello to", true, true, false,
nameDesc);
String[] sa = nameDesc.getFields();
// --
// operations
// -------------------------------------------------------------------
ModelMBeanOperationInfo[] operations = new ModelMBeanOperationInfo[2];
String className = HelloWorld.class.getName(); // getName method
Descriptor getDesc = new DescriptorSupport(new String[]
{ "name=getHello", "descriptorType=operation", "class=" + className,
"role=operation" });
operations[0] = new ModelMBeanOperationInfo("getHello", "get hello ",
null, null, MBeanOperationInfo.ACTION, getDesc); Descriptor setDesc = new DescriptorSupport(new String[]
{ "name=setHello", "descriptorType=operation", "class=" + className,
"role=operation" });
operations[1] = new ModelMBeanOperationInfo("setHello", "set hello ",
new MBeanParameterInfo[]
{ new MBeanParameterInfo("a", "java.lang.String",
" a method's arg ") }, null, MBeanOperationInfo.ACTION,
setDesc); // constructors
ModelMBeanConstructorInfo[] constructors = new ModelMBeanConstructorInfo[1];
Constructor<?>[] ctors = HelloWorld.class.getConstructors(); constructors[0] = new ModelMBeanConstructorInfo("default constructor",
ctors[0], null); // ModelMBeanInfo
ModelMBeanInfo mmbeanInfo = new ModelMBeanInfoSupport(className,
"Simple implementation of model bean.", attributes, null,
operations/* null */, null, null); // 设置一个Descriptor策略,这样RequiredModelMBean改变 Attribute值得时候会记录日志
// 当然RequiredModelMBean还需要addAttributeChangeNotificationListener,注册一个监听器
Descriptor globalDescriptor = new DescriptorSupport(new String[]
{ "name=HelloWorldModelMBean", "displayName=globaldescriptor",
"descriptorType=mbean", "log=T", "logfile=hello.log" });
mmbeanInfo.setMBeanDescriptor(globalDescriptor); return mmbeanInfo;
}
}
HelloWorldModelMBean的更多相关文章
- JmxTest
package mbeanTest; import java.util.Set; import javax.management.Attribute; import javax.management. ...
随机推荐
- Ubuntu中python的mysql操作
1.在已经安装了python和MySQL数据库的前提下使用pip3 install PyMySQL命令 2. 建立链接: (1)首先使用命令python 进入编程模式,再导入包: import pym ...
- exec系统调用 && 进程的加载过程
exec系统调用会从指定的文件中读取并加载指令,并替代当前调用进程的指令.从某种程度上来说,这样相当于丢弃了调用进程的内存,并开始执行新加载的指令. exec系统调用会保留当前的文件描述符表单.所以任 ...
- js运算符 及 运算符优先级
「运算符」是用于实现赋值.比较和执行算数运算等功能的符号.常用运算符分类如下符号 算数运算符 递增和递减运算符 比较运算符 逻辑运算符 赋值运算符 算数运算符 运算符 描述 案例 + 加 10+20= ...
- 简单的SQl时间序列生成,每次时间间隔10分钟。
create table #timeseries(Times datetime not null) go declare @firstdate datetime , @lastdate datetim ...
- Typora下载安装教程
Typoa下载和安装 Typora---程序员记事本!!! 这里我们选择Typora作为我们的编辑器,功能的强大需要各位自己去体会. Typora下载地址 点击链接打开,然后选择Download! 根 ...
- 菜鸡的Java笔记第三 - java 自动转换原则
自动转换原则 数据范围保存大的数据类型要转换为数据范围保存小的数据类型,使用强制转换(强制转型就是在变量的前面加括号,在括号里写上需要强制要转的类型.) 数据范围保存小的数据类型可以自动转换为数据范围 ...
- hover 背后的数学和图形学
前端开发中,hover是最常见的鼠标操作行为之一,用起来也很方便,CSS直接提供:hover伪类,js可以通过mouseover+mouseout事件模拟,甚至一些第三方库/框架直接提供了 hover ...
- [cf1219G]Harvester
分类讨论(以下仅考虑行,列的情况):1.4行的,求出每一行的和后找到4个最大值即可:2.3行1列,枚举列,再将每一行最大值减去那一列的值后取3个最大值得和即可:3.2行2列,发现行和列是等价的,因此可 ...
- Hardware assisted virtualization and data execution protection must be enabled in the BIOS. See https://docs.docker.com/docker-for-windows/troubleshoot/#virtualization
解决办法:先关闭 Hyper-V ,然后重新开启 Hyper-V 即可! 来自:https://zhuanlan.zhihu.com/p/51939654
- pyinstaller进行打包exe文件
百度直接pip安装,报错 下载离线文件报错. 百度了一下:还真好使 Python生成可执行文件主要有三种方法,利用py2exe,pyInstaller或cx_Freeze. 这里选择pyinstall ...