Java Dynamic Management Kit 5.1 Tutorial

9.5 Wrapping Legacy Connectors

Although it is recommended that you use the new RMI and JMXMP connector protocols defined by the JMX Remote API, it is possible for you to continue to use your existing legacy connectors alongside the new ones. This is achieved by wrapping the legacy connector so that it appears in a form that is compatible with the new standard connectors. Wrapping your Java DMK 5.0 RMI and HTTP(S) connectors allows applications created using Java DMK 5.1 to interoperate with existing Java DMK applications. In addition, if you want to use HTTP(S) connectors, you must wrap them.

The JmxConnectorServerFactory and JmxConnectorFactory classes are used to create wrapped legacy Java DMK connector servers and clients. These connector servers and clients expose the same interfaces as standard JMX connectors. For the JmxConnectorServerFactory to create a wrapped connector, you must ensure that the jdmkrt.jar is either in your CLASSPATH environment variable, or in the context of the thread that is used to create the wrapped connector.

Java DMK 5.1 defines a new interface, JdmkLegacyConnector, that is used to obtain the wrapped connectors.

The JdmkLegacyConnector interface specifies a new protocol name for each of the legacy connectors. These protocol names are passed into the JMXServiceURL when it is created, in the same way the RMI connector and JMXMP connectors are identified as rmi and jmxmp respectively in the service URLs. The new protocol names are listed below.

The JdmkLegacyConnector also specifies a list of properties to allow the factory to obtain information defined by the user to create the legacy connectors, as follows.

The creation of wrapped legacy RMI and HTTP connector servers is shown in Example 9–5. The code extracts in this section are taken from the classes in the examplesDir/current/Connectors/wrapping directory.


Example 9–5 Wrapping Legacy Connector Servers

public class Server {

    public static void main(String[] args) {
	     try {
           MBeanServer mbs = MBeanServerFactory.createMBeanServer();

           JMXServiceURL httpURL = new JMXServiceURL("jdmk-http", 
                                                      null, 6868);
           JMXConnectorServer httpCS =
              JMXConnectorServerFactory.newJMXConnectorServer(httpURL, 
                                                              null, mbs);
           ObjectName httpON = 
               new ObjectName("legacyWrapper:protocol=jdmk-http,port=6868");
	           mbs.registerMBean(httpCS, httpON);

            httpCS.start();

            JMXServiceURL rmiURL = 
               new JMXServiceURL("jdmk-rmi", null, 8888, "/myRMI");
            JMXConnectorServer rmiCS =
                JMXConnectorServerFactory.newJMXConnectorServer(rmiURL, 
                                                                null, mbs);

	            ObjectName rmiON = 
                new ObjectName("legacyWrapper:protocol=jdmk-rmi,port=8888");
	            mbs.registerMBean(rmiCS, rmiON);
	
            rmiCS.start();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

In Example 9–5, we see that the connector servers are created in a similar way to standard connector servers defined by the JMX Remote API. The only difference is that the connector protocols used to create the JMX service URLs are jdmk-rmi and jmdk-http. For simplicity, this example does not create an HTTPS connector.


Note –

As you can see above, the wrapped connector server is registered in the MBean server before it is started. This order of events must always be respected, otherwise the wrapped connector will not work.



Example 9–6 Wrapping Legacy Connector Clients

public class Client {

  public static void main(String[] args) {
	   try {
	       JMXServiceURL url = new JMXServiceURL("jdmk-http", 
                                              null, 6868);
	       connect(url);
	    
	       url = new JMXServiceURL("jdmk-rmi", null, 8888, 
                                "/myRMI");
	       connect(url);
    } catch (Exception e) {
        e.printStackTrace();
    }
	   System.exit(0);
  }
  
  [...]

As for the creation of the connector servers, in Example 9–6, the legacy connector clients are created by passing the jdmk-http and jdmk-rmi property strings to the JMX service URLs. The rest of the Client example is identical to a standard JMX Remote API connector client.

To Run the Legacy Connector Wrapping Example

The following example uses the classes in the examplesDir/current/Connectors/wrapping directory.

  1. Compile the Java classes


    $ javac -classpath classpath *.java
  2. Start the Server


    $ java -classpath .:classpath Server &

    You will see confirmation of the creation of the wrapped connector servers, and will be prompted to start the Client.

  3. When prompted, start the Client


    $ java -classpath .:classpath Client

    You will see the wrapped HTTP connector client connect to the HTTP server, and perform various MBean operations via the connection. Once the MBean operations have completed, the Client closes the HTTP connection, before opening a connection to the legacy RMI connector server, and performing further MBean operations.

9.5.1 Limitations of Wrapped Legacy Connectors

The wrapped legacy connectors do not provide the full functionality of either their JMX Remote API or their Java DMK 5.0 counterparts. The limitations of the wrapped legacy connectors are listed below.