JMX Standard MBean

   As we metioned before, JMX has three types of MBean, and the standard MBean is the simplest MBean of them, the other two are Dynamic MBean and Model MBean which we will cover in later articles.

   However, a standard MBean must adhere to the following rules:

  • An MBean must be an concreate class.
  • An MBean must have a public constructor.
  • An MBean must implements an MBean interface which name must follows the name schema classNameMBean.
  • An MBean can only implements only a single MBean interface.

   Since Standard MBean is simple, there is not much to talk about it except for its MBean interface, now let's examine how its management interface forms.

   First, let's take a look at a simple case:

   #Diagram 1

     From the class diagram above, we could know that the MBean interface PrintableMBean composes the Printable class's management interface, and it exposes one attribute(Message) and one operation(print()), after we register a Printable instance in the MBean server, we can invoke its operation or set or get its attribute according to its management interface.

     And let's make it a little complexer,

#Diagram 2

 If we register the Readable instance in the MBean Server, what is its management interface? Still the same as PrintableMBean?If so, how about the following case?

#Diagram 3

   In fact, how to compose the management interface follows certain rules:

  1. It will examin all the interfaces which MBean implements directly.If one of them matches the naming schema classNameMBean, return this matched interface, otherwise goes to step2.
  2. For all the interfaces implemented by MBean directly, examin their super interfaces, that is the interfaces extended by the ones implemented by MBean directly, to check if one of them can matches the condition, if not, goes to step 3.
  3. Search from MBean's parent class if any, and repeat step 1 and step 2.

    The following diagram will help you get a better understand of the above rules:



 

   After learning the rules for composing the management interface, let's use it to examin an example:

   #Diagram 4

  

    What are the management interface of Printable and Readable respectively? For Readable instance, does its management interface contains 'Message' attribute and 'print()' operation? No, it won't. According to the rules of composing the management interface, once the suitable MBean interface is found, it will stop searching at once, not go searching with MBean's parent class any more. Therefore, the management interface of Readable only contains two operations: readFile(path:String) and copy(fromPath : String, toPath : String), that is because the suitable MBean interface of Readable is ReadableMBean interface which also contains the operation copy(fromPath : String, toPath : String). The management interface of Printable will leave to you as practice.

 

   And there is one more thing you should know about is that what will JMX take as an exposed attribute and what will JMX take as an exposed operation?

   #Diagram 5

 

  From the above MBean interface, how many attributes and operations are exposed? The answer is that three operations are exposed and only one attribute is exposed, it's readable and writable. The exposed attribute must follows JavaBean specification, its setter method must have one parameter and its return type must be void while its getter method must not have parameter and its return type must not be void. Like the + setMessage(msg : String) : void and + getMessage() : String  method shows. What if the setter method has two parameters like + setAge(int age1,int age2) : void, is it an exposed attribute? No, it isn't. It is an exposed operation. Got it?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值