Show TOC Start of Content Area

Background documentation MBean Registration  Locate the document in its SAP Library structure

Registering a Local MBean

There are cases when you want to register a locally created object as an MBean. The crucial part here is the creation of the ObjectName. It must be done using the ObjectNameFactory, wherever possible. For more information, see com.sap.jmx.ObjectNameFactory.

In the first example, the object is registered as a local MBean, so that it is visible from other cluster elements:

Example

import javax.management.MBeanServer;

import javax.management.ObjectName;

import com.sap.jmx.ObjectNameFactory;

import com.sap.xyz.MyMBean;

...

MBeanServer mbs;

// Create the MBean manually

MyBean mbean = new MyMBean();

...

// Create the ObjectName for a local MBean

//

// The result will be:

// ":j2eeType=SAP_MyMBean,name=MyBean,SAP_J2EECluster=\"\", SAP_J2EEClusterNode=\"\""

//

// The empty keys SAP_J2EECluster and SAP_J2EEClusterNode will be filled by the MBeanServer with the

// appropriate values for local MBeans. Finally, for the registration, something like this will be used:

// "com.sap.default:j2eeType=SAP_MyMBean,name=MyBean,SAP_J2EECluster=BIN, SAP_J2EEClusterNode=4001"

//

ObjectName name = ObjectNameFactory.getNameForServerChildPerNode
(
"SAP_MyMBean", "MyBean", null, null);

// Register the MBean

mbs.registerMBean(mbean, name);

 

Registering a Remote MBean

You can register an MBean locally only – that is, the SAP_J2EEClusterNode key must either be empty (as in the example above), or it must point to the local cluster element. However, you can also request the MBeanServer to create the MBean. In which case, you can also create MBeans on a remote element.

Typically, the class of the MBean you want to create is not visible for the class loader of the MBeanServer, that is, you have to specify the class loader to be used. The class loaders of the AS Java are virtually registered as MBeans, so that you can specify an ObjectName for the loaderName parameter of the createMBean(...) methods. Again, the ObjectNameFactory helps to create such a name by taking an AS Java class loader name as the parameter. The following code shows how you create an MBean on a remote element:

Example

import javax.management.MBeanServerConnection;

import javax.management.ObjectName;

import com.sap.jmx.ObjectNameFactory;

import com.sap.xyz.MyMBean;

...

MBeanServerConnection mbsc;

...

// create the MBean remotely, assuming the class is loaded by the class loader of

// service "myservice" on node 5001

mbsc.createMBean(

  MyMBean.class.getName(),

  ObjectNameFactory.getNameForServerChildPerNode("SAP_MyType", "MyBean", "5001", null),

  ObjectNameFactory.getNameForClassLoader("service:myservice", null, null));

 

A class loader that exists on one client element may not exist on the target element. Many services are not available.

The life cycle of a local and internal MBeans does not follow any convention. However, for clustered MBeans you must "synchronize" the life cycle of all instances in the cluster. Typically, a service registers/unregisters the instances of its clustered MBeans during startup/shutdown. Applications cannot manage the life cycle of clustered MBeans on their own.

 

 

End of Content Area