Show TOC

 MBean RegistrationLocate this document in the navigation structure

Registering a Local Mbean visible in cluster

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 could be done by specifying all properties in the constructor of javax.management  using ObjectName or ObjectNameFactory , wherever possible. For more information, see com.sap.jmx.ObjectNameFactory .

In the first example, the object is registered with name that it is visible from other cluster nodes:

Tip
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

The method registerMBean is used to register an MBean that is already created and works locally only - that is. The SAP _J2EEClusterNode key in the ObjectName must either be empty (as in the example above), or it must point to the local cluster node. However, you can also request the MBeanServer to create the MBean using createMBeanmethods. In this case, you can also create MBeans on a remote node.

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:

Tip
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.