
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.
/**
*The MBean interface
*/
public interface TestResourceMBean {
public String anOperation(String parameter);
}
/**
* The managed object
*
* @see TestResourceMBean
*/
public class TestResource implements TestResourceMBean {
// visible for management clients
public String anOperation(String parameter) {
// not visible for management clients
return echoOperation (parameter);
}
// not visible for management clients
public String echoOperation(String string) {
return 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.
// 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 .