`
scanfprintf123
  • 浏览: 80352 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

JMX Model MBean

阅读更多

  As we know, Standard MBean is easy to use and implement, but it requires that the MBean interface has to be stable. If the manageable resoures are evolving over time, we need Dynamic MBean to help us out of this situation, but what if modifying the existing class is not an option? Then Model MBean come to your rescue. Actually the Model MBean is Dynamic MBean since it extends from Dynamic MBean interface, some peopel might get confused about this, why can't we just use Dynamic MBean to handle this since the Model MBean is also Dynamic MBean? That's a good question. Recall from the development of Dynamic MBean, we have to modify our manageable resource to implement Dynamic MBean interface, right? And the creation of MBeanInfo is inside the Dynamic MBean. But the Model MBean is different, you can create your MBeanInfo outside of the Model MBean and you don't have to develop your MBean since JMX has offered a default implementation for you, RequiredModelMBean.

   Now, let's take a look at the architecture of the Model MBean provided by Sun first.



  

      Well, as we can see from the above image, Model MBean extends from DynamicMBean,PersistentMBean and ModelMBeanNotificationBroadcaster. PersistentMBean  provides the persistence mechanism for ModelMBean, you can save your ModelMBean to the local file or a remote database depends on the implementation of your PersistentMBean. And ModelMBeanNotificationBroadcaster is actually a NotificationBroadcaster, you can send out attribute change-related notifications or the general notifications via it since this interface has offered the sendNotification(Notification ntfyObj) method and sendAttributeChangeNotification(AttributeChangeNotification notification) method respectively.

      In the meantime, Model MBean provide some additional features, such as Attribute value caching, Notification logging and Operation delegating. In fact, these features are implementing by using the Descriptor interface. Before we talk about the Descriptor interface, we need to examin the metadata in the Model MBean first. As stated earlier, Model MBean is Dynamic MBean, thus its management interface is created at runtime like Dynamic MBean. Model MBean has its own metadata like MBeanFeatureInfo in Dynamic MBean, and the following image will give you a clear understanding of metadatas in Model MBean and their relationships with those ones in Dynamic MBean.

    

      Besides that, we can also see that every metadata class of Model MBean contains a Descriptor instance. As we said earlier, Model MBean use Descriptor to implements its additional features like Attribute value caching we mentioned earlier. A Descriptor contains a number of fieldName-fieldValue pairs, each fieldName is represented by a String Object while each fieldValue is represented by a Object instance. Each Descriptor instance in different metadata class of Model MBean contains different predefined attributes, take Descriptor instance in ModelAttributeMBeanInfo for example, the predefined attributes are as below:
 

 

     I am sure you can understand most of them without explanations. And the attribute value caching feature in the ModelMBean is implemented by using the predefined attributes:currencyTimeLimit and lastUpdatedTimeStamp. As the description of currencyTimeLimit shows, when its value is less than 0, the attribute will be never cached, and if its value is equal to 0, then the attribute will be always cached, otherwise its value indicates the time period that the cached value is valid, in this case, if the sum of currencyTimeLimit and lastUpdatedTimeStamp is greater than the present time, then the cached attribute value will be refreshed. And you might be wondering where the cached attribute value will be stored. In fact, the cached attribute value will be stored in the predefined attribute 'value' of corresponding Descriptor instance, which you can find in the above table.

    When you comprehend the theory of Attribute value caching, it is easy to understand other additional features provided by Model MBean, like operation delegating. Operation delegation allows you invoke some operations that is not defined in your managed resource. This feature is also implemented by its Descriptor's predefined attribute:targetObject and targetType



    If you set an object that is different from your managed resource  in the targetObject attribute of Descriptor instance, when invoking an operation, it will try to invoke this operation on the Model MBean first , then the targetObject and your managed resource finally.

 

    After we examine the metedata of the Model MBean, let's get back to our Model MBean interface again.

 

public interface ModelMBean extends 
	 DynamicMBean,
	 PersistentMBean,
	 ModelMBeanNotificationBroadcaster 
{

public void setModelMBeanInfo(ModelMBeanInfo inModelMBeanInfo) 
	    throws MBeanException, RuntimeOperationsException;

public void setManagedResource(Object mr, String mr_type)
	throws MBeanException, RuntimeOperationsException, 
		 InstanceNotFoundException, InvalidTargetObjectTypeException ;

}

    ModelMBean interface exposes two operations, one for setting its managed resource and the other for setting its ModelMBeanInfo metadata.And as we mentioned earlier, ModelMBean is also a DynamicMBean,  and recall how we develop the DynamicMBean, you will find that the ModelMBeanInfo passing to the setModelMBeanInfo() method is actually the one returned by DynamicMBean#getMBeanInfo() method at most time. In fact, when you are implementing a ModelMBean, you're actually implementing a Dynamic MBean. Instead of using RequiredModelMBean, you can also implement your own ModelMBean, at most of time, there is no need for us to use so many features. Maybe you don't want all the additional features come with the Descriptor and maybe you think MBeanInfo is enough(after all, you need to do more when using a ModelMBeanInfo, for example, ModelMBeaninfo requires a additional param Descriptor when creating while MBeanInfo not). Then you can implement your own Model MBean like the following,

public interface ModelMBean extends  DynamicMBean
{

public void setMBeanInfo(MBeanInfo mbeanInfo) ;
	    
public void setManagedResource(Object mr);
	
}

   That's to say, you can define your ModelMBean interface at your will according to your requirements.

 

    Same as DynamicMBean, it's a great challenge to construct its ModelMBeanInfo, the common way is write a helper to ease the development of constructing ModelMBeanInfo, like the following codes show:

   

 public void addModelMBeanAttribute( String fname,String ftype,
                            boolean read, boolean write, 
                            boolean is,
                            String description, Descriptor desc )
    {
        attributes.put( fname, new ModelMBeanAttributeInfo(fname,
                            ftype,
                            description,read,write,is, desc ) );
    }
    
    public void addModelMBeanConstructor( Constructor c, 
                           String description,
                           Descriptor desc )
    {
        this.constructors.put( c, 
          new ModelMBeanConstructorInfo( description,
                               c, desc ) );
    }

   And a better way is to configure them in a propery file such as xml file, and then map them into corresponding Model MBean metadata like spring does.

  • 大小: 15.4 KB
  • 大小: 15.6 KB
  • 大小: 2.6 KB
2
1
分享到:
评论
3 楼 theoffspring 2011-10-11  
model mbean资料真难找啊,找了2天都没找到一份权威的。你们都怎么学的?
2 楼 scanfprintf123 2009-10-20  
Commons modeler 和SPRING实际上差不多,代码上COMMON MODELER要简单一点,思想是一样的,你可以自己抽一个Commons modeler出来看看。
1 楼 hugo 2009-10-18  
不知道spring怎么做的,用commons modeler好像也很不错

相关推荐

    JMX IN ACTION(七)

    Model MBean由`javax.management.modelmbean.RequiredModelMBean`类定义,它是JMX代理的一个必需部分。与Dynamic MBean类似,Model MBean的管理接口是在运行时定义的。`RequiredModelMBean`类实现了`ModelMBean`接口...

    面试官问我 JMX 了解不,我说:什么? - 知乎1

    Model MBean通过实现`javax.management.modelmbean.ModelMBeanInfo`接口来定义其行为。 JMX不仅用于JVM监控,还可以用于日志级别的动态修改,例如log4j支持通过JMX来动态调整日志级别。此外,许多监控工具,如...

    jmx学习整理里1

    Model MBean通过`javax.management.modelmbean.ModelMBean`接口和一个描述符文件(如`car-mbean-descriptor.xml`)定义其行为。 描述符文件(如`car-mbean-descriptor.xml`)包含了MBean的元数据,包括属性、操作、...

    Model MBean Instrumentor-开源

    JMX Instrumentor 是一个微型 Java 工具,用于将任意对象检测为 JMX 模型 MBean。 它通过反射检查对象的类并构造相应的 ModelMBeanInfo。 甚至可以通过特殊的 JMX 注释来改进此信息。

    jmx技术介绍(ppt)

    动态MBean则提供了更大的灵活性,包括Open MBean和Model MBean,用于管理动态或复杂的数据结构。 **总结** JMX技术为Java开发者提供了一套强大而灵活的工具,用于构建和集成管理功能。通过MBean,开发者可以轻松地...

    JMX、MXBean学习

    Standard MBeans是预定义了管理接口的类,Dynamic MBeans则可以在运行时动态定义其管理接口,而Model MBeans是一种抽象层,可以将任何Java对象转换为MBean。 MXBean是JMX中的一个特殊概念,它是标准MBean的扩展,...

    java利用JMX做出不一样的的JVM.docx

    MBean有四种类型:Standard MBean、Dynamic MBean、Open MBean和Model MBean。Standard MBean是最常见且最简单的形式,类似于普通的Java Bean。Dynamic MBean允许动态地获取和设置属性,适合于已存在的、不易转换为...

    JMX配置与使用

    Model MBeans是最通用的,它们基于元数据来定义MBean的行为。 5. 监控与通知: 通过JMX,可以注册监听器来接收关于MBean状态变化的通知。这可以用来实现自动化的故障检测、日志记录或者性能监控。此外,JMX还可以...

    JMX技术学习非常好的资料

    JMX还提供了一些附加管理协议API,如SNMP(Simple Network Management Protocol)、TMN(Telecommunications Management Network)和CIM/WBEM(Common Information Model/Web-Based Enterprise Management)。...

    JMX 相关

    4. **Model MBean**: 基于XML配置,将管理接口与实现分离。 ### MBean Server MBean Server是JMX框架的核心,它负责注册和管理MBeans,提供命名和寻址机制。它还提供了MBeans之间的交互,以及与其他管理系统(如...

    jmx资料

    MBeans分为标准MBean、Dynamic MBean和Model MBean三种类型,以适应不同的需求。Server是运行MBeans的环境,它负责注册、管理MBeans,并提供给Clients访问接口。Clients则通过连接到Server来访问和操作MBeans,实现...

    JMX specification 1.4

    - **MBean服务器(MBean Server)**:负责管理和存储MBeans的对象,它是所有JMX操作的基础。 - **对象名称(ObjectName)**:用于唯一标识MBean的名字。 - **操作(Operation)**:定义了MBean可执行的方法。 - **属性...

    JMX: Developer's Quick Start Guide

    - **Model MBeans**:模型MBeans是另一种形式的MBean,它利用反射机制自动创建一个MBean实例,而无需实现特定的接口。这种类型的MBean通常用于现有类的管理,而不需要修改源代码。 #### 五、通知机制 JMX支持一种...

    SpringJMX.pdf

    - **MBean元数据类**:描述MBean的结构和行为。 #### 五、Standard MBeans实例 - **接口定义**:Standard MBeans通常通过接口定义其公共API,接口中包含特定命名规则的方法。 - **实现类**:实现类需遵循接口定义的...

    Java Management Extensions

    实现模型MBeans通常需要使用`ModelMBean`接口,并通过`ModelMBeanInfo`类来描述MBean的行为。 #### 五、MBean服务器 MBean服务器是JMX的核心组件之一,负责注册和管理所有的MBeans。了解如何与MBean服务器交互是...

    weblogic的MX程序设计

    创建一个MBean通常需要实现`javax.management.MBean`接口或者继承自`javax.management.ModelMBean`类,并在其中定义属性和操作。完成MBean的定义后,可以将其注册到MBeanServer上。例如,以下代码展示了如何创建并...

    [课堂课件讲解]Java微服务实践-Spring Boot 监管.pptx

    JMX 还提供了通知模型(Notification Model),允许 MBean 广播管理事件,这种操作称之为通知。管理应用和其他对象注册成监听器。元信息类包含描述所有 MBean 管理接口的组件接口,其中包括属性、操作、通知和构造器...

    Java Management Extensions管理扩展原理解析

    - **Model MBean**:使用`javax.management.modelmbean.RequiredModelMBean`,无需编写MBean类,管理资源通常在外部定义。 2. **适配层**:MBean服务器是JMX架构的核心,它负责注册MBeans,执行MBean操作,以及...

Global site tag (gtag.js) - Google Analytics