We use the createMBean method to instantiate and register an object from its class name. This class must already be available in the agent application's classpath.
private void doWithoutProxyExample(String mbeanName) {
try {
// build the MBean ObjectName instance
//
ObjectName mbeanObjectName = null;
String domain = connectorClient.getDefaultDomain();
mbeanObjectName = new ObjectName( domain + ":type=" + mbeanName );
// create and register an MBean in the MBeanServer of the agent
//
echo("\nCurrent MBean count in the agent = "+
connectorClient.getMBeanCount());
echo("\n>>> CREATE the " + mbeanName +
" MBean in the MBeanServer of the agent:");
String mbeanClassName = mbeanName;
ObjectInstance mbeanObjectInstance =
connectorClient.createMBean( mbeanClassName, mbeanObjectName );
echo("\tMBEAN CLASS NAME = " +
mbeanObjectInstance.getClassName() );
echo("\tMBEAN OBJECT NAME = " +
mbeanObjectInstance.getObjectName() );
echo("\nCurrent MBean count in the agent = "+
connectorClient.getMBeanCount() );
[...] // Retrieve MBeanInfo and access the MBean (see below)
// unregister the MBean from the agent
//
echo("\n>>> UNREGISTERING the "+ mbeanName +" MBean");
connectorClient.unregisterMBean(
mbeanObjectInstance.getObjectName() );
[...]
} catch (Exception e) {
e.printStackTrace();
}
}
|
Example 21–4 shows the use of other calls to the remote agent, such as getDefaultDomain and getMBeanCount that have the same purpose as in an agent application.