您的位置:首页 > 其它

JMX ModelMBean

2013-01-23 15:38 225 查看
    Model Mbean是唯一的,因为开发者不需要写MBean类。组成Model MBean的类和接口由JMX规范定义,且在每个JMX agent中都可以获取。Model MBean是可以在MBean server中实例化的通用的MBean,可以被用户配置来管理任何资源。

    Model MBean通过javax.management.modelbmean.RequiredModelMBean来定义。实际上ReqiuiredModelMBean是下了ModelMBean接口,且ModelMBean继承了DynamicMBean接口。ModelMBean管理接口在MBean的外部定义,通过set方法插入MBean。Model MBean的创建步骤:

    1)application启动

    2)调用MBean server的createMBean方法,创建RequiredModelMBean实例。

    3)设置被管理的管理资源

    4)创建ModelMBeanInfoSupport类的实例,此对象像MBeanInfo一样,封装了新ModelMBean的管理接口。

    5)invoke ModelMBean上的操作。

    ModelMBean可以持久化,通过持久化,ModelMBean可以在JMX agent整个生命周期存活,创建ModelMBean是尅配置多长时间保存它的状态。ModelMBean可以记录每次通知的输出,在输出通知时,允许指定日志文件位置。

    ModelMbean可以缓存属性值。缓存多久被更新,可以被缓存策略指定。
private ModelMBean createRawModelMBean(){
RequiredModelMBean modelmbean = null;
try
{
final ModelMBeanInfoSupport modelMBeanInfo =
new ModelMBeanInfoSupport(
SimpleCalculator.class.getName(),
"A simple integer calculator.",
null,      // attributes
null,      // constructors
buildModelMBeanOperationInfo(),
null,      // notifications
buildDescriptor() );
modelmbean = new RequiredModelMBean(modelMBeanInfo);
setModelMBeanManagedResource(modelmbean);
}
catch (MBeanException mbeanEx)
{
System.err.println(  "ERROR trying to create a ModelMBean:\n"
+ mbeanEx.getMessage() );
}
return modelmbean;
}
modelMBean.setManagedResource(new SimpleCalculator(),"ObjectReference");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: