Accessing Standard and Dynamic MBeans via the RMI Connector

来源:互联网 发布:logic pro windows版 编辑:程序博客网 时间:2024/05/20 06:37

The purpose of this examples is to demostrate the implementation of a standard MBean and a dynamic MBean. It also shows how to perform operations on them, both locally, and remotely through an RMI connection between a server and a remote client.

A standard MBean is one that statically defines its management interface through the name of the methods it contains. A dynamic MBean implements a specific java interface and reveals its attributes and opterations at run time.

The JMX technology defines a connector base on RMI. The RMI connector supports the standard RMI transports, Java Remote Method Protocol(JRMP) and the Internet Inter-Lbject Request Broker(ORB) Protocol(IIOP). This connector allows you to connect to an MBean server from a remote location, and perform operations on it, exactly as if the operations were being performed locally.

due to its size, the Server.java class is shown in several code excerpts.

public static void main(String[] args) {
     try {

// Firstly, the Server.java class creates a new MBean server called mbs by calling the
// createMBeanServer() method of the MBeanServerFactory class.    
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
waitForEnterPressed();

// Then, the default domain in which the MBean server is registered is obtained with a call to the 
// getDefaultDomain() method of the MBeanServer interface. The domain is identified by the the string domain
String domain = mbs.getDefaultDomain(); 
waitForEnterPressed();

         // The MBean class named SimpleStandard is also identified by a variable mbeanClassName .

         // SimpleStandard is the name of java class for the java object of which this MBean is an instance.
         String mbeanClassName = "SimpleStandard";
         String mbeanObjectNameStr =
             domain + ":type=" + mbeanClassName + ",name=1";
         ObjectName mbeanObjectName =
             createSimpleMBean(mbs, mbeanClassName, mbeanObjectNameStr);
         waitForEnterPressed();
         printMBeanInfo(mbs, mbeanObjectName, mbeanClassName);
         waitForEnterPressed();
         manageSimpleMBean(mbs, mbeanObjectName, mbeanClassName);
         waitForEnterPressed();
         mbeanClassName = "SimpleDynamic";
         mbeanObjectNameStr =
             domain + ":type=" + mbeanClassName + ",name=1";
         mbeanObjectName =
             createSimpleMBean(mbs, mbeanClassName, mbeanObjectNameStr);
         waitForEnterPressed();
         printMBeanInfo(mbs, mbeanObjectName, mbeanClassName);
         waitForEnterPressed();
         manageSimpleMBean(mbs, mbeanObjectName, mbeanClassName);
         waitForEnterPressed();
         [...]

原创粉丝点击