The XMOJO Project
<< Prev Chapter 2.1 Standard MBean Next >>

Standard MBean


A class that implements its own MBean interface is called Standard MBean. This is the simplest type of instrumentation available when developing new JMX-manageable resources. Standard MBeans are most appropriate for static management information. (The attributes and operations that are exposed for management will be static)

 Semantics for a Standard MBean 

In Standard MBeans, the attributes and operations are obtained by introspecting the MBean interface.

 Attributes 

Attributes are the fields or properties of the MBean, and they are present in the management interface of MBeans. Attributes represent the data available for management. Any Java object can be represented as an attribute. For a Java object to be represented as an attribute, there are some semantics to be followed in the code.

 Semantics for Attribute 

To define a read write attribute with the name "Name" of Java datatype String, the management interface should define the getter and setter methods as mentioned below:

public String getName();
public void setName(String some_name);


From the above method prototype, one can observe the following things:
  1. There are two public methods, getName and setName.
  2. getName does not take any arguments and returns a object of type String.
  3. setName takes only one argument, and returns nothing. Further, the argument is an object of type String that is the return data type of the getName method.
If the management interface defines only the getName method, the attribute Name will be a read only attribute.
If the management interface defines only the setName method, the attribute Name will be a write only attribute.

The general semantics for defining a read write attribute in the management interface is:

public AttributeType get<AttributeName>();
public void set<AttributeName>(AttributeType obj);


Here, AttributeType can be of any Java type, including array types.

For boolean type attributes, the getter method can also be defined using the prototype:

public boolean is<AttributeName>();

instead of public boolean get<AttributeName>();


Attribute Names cannot be overloaded, that is, there cannot be two setters or getter and setter pair for the same name that operates on different types. We will see more about this attribute name overloading with some sample code snippets in the next topic. An object with overloaded attribute names is not a compliant MBean.

 Operations 

Operations are the actions that a JMX-manageable resource makes available to management applications. Any method in the management interface that is not identified as attribute will be exposed as an operation. The name of the operation is the name of the corresponding method.

An operation can be defined with any number of arguments of any type and can return value of any type.

For example, public void destroy(); is exposed as an operation with the name destroy.

Points to Remember
  1. Standard MBean must be a concrete class having at least one public constructor and should implement its own interface.
  2. In a Standard MBean, the attributes and operations are formed by MBean introspection.
  3. AttributeNames cannot be overloaded.
  4. A boolean attribute can follow the lexical design pattern is<AttributeName>. It can be represented by either of the patterns is<AttributeName> or get<AttributeName> but not both in the same MBean.

<< Prev Home Next >>
Instrumentation Level Writing a Standard MBean