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
JMX Standard MBean_第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
JMX Standard MBean_第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
JMX Standard MBean_第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:


JMX Standard MBean_第4张图片
 

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

   #Diagram 4

  
JMX Standard MBean_第5张图片
    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

 
JMX Standard MBean_第6张图片
  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?

你可能感兴趣的:(Go)