Show TOC Start of Content Area

Procedure documentation Writing MBeans  Locate the document in its SAP Library structure

...

Use

Use this procedure to learn how to instrument a resource by providing a standard MBean. However, there are some limitations in the naming of the MBean interface, which sometimes make it impossible to write a standard MBean. For that reason the JMX™ 1.2 Specification introduces a wrapper class StandardMBean, which itself is a dynamic MBean that takes the managed object and the MBean interface as parameters. By using the StandardMBean no restrictions on class/interface names exist any more.

Procedure

       1.      Specify in the MBean interface all attributes and operations that you want to be manageable by the MBeanServer:

// the MBean interface

interface MyResourceMBean {

  public String anOperation(String);

}

// the managed object

class MyResource implements MyResourceMBean {

  // visible for management clients

  public String anOperation(String);

  // not visible for management clients

  public String anotherOperation(String);

}

 

The standard MBean management interface is discovered according to an inheritance pattern upon registration. For more information, see the JMX™ 1.2 Specification on http://java.sun.com.

       2.      Set the wrapper class StandardMBean:

// the MBean interface

interface Foo {

  public String anOperation(String);

}

// the managed object

class MyResource implements Foo {

  // visible for management clients

  public String anOperation(String);

  // not visible for management clients

  public String anotherOperation(String);

}

import javax.management.StandardMBean;

...

// instantiate the MBean

StandardMBean mBean = new StandardMBean(new MyResource, Foo.class);

 

It is sometimes necessary to subclass the managed object from StandardMBean instead of passing it as a parameter to the constructor. This is the case if the managed object wants to implement the NotificationBroadcaster or MBeanRegistration interfaces, or must be instantiated by a remote MBeanServer.

For more information, see the API documentation of javax.management.StandardMBean and com.sap.pj.jmx.mbeaninfo.StandardMBeanWrapper. The latter allows for provision of additional meta data attached to the MBeanInfo.

 

 

End of Content Area