The Java DMK RMI connector server supports the standard RMI transports, Java Remote Method Protocol (JRMP) and the Internet Inter-Object Request Broker (ORB) Protocol (IIOP). An example of an RMI connector is provided in the examplesDir that demonstrates an RMI connection between a server and a remote client.
The Server class from the RMI connector example is is shown in Example 9–1.
public static void main(String[] args) { try { // Instantiate the MBean server // MBeanServer mbs = MBeanServerFactory.createMBeanServer(); // Create an RMI connector server // JMXServiceURL url = new JMXServiceURL( "service:jmx:rmi:///jndi/rmi://localhost:9999/server"); JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); cs.start(); } catch (Exception e) { e.printStackTrace(); } } }
Firstly, the Server class creates a new MBean server called mbs by calling the createMBeanServer() method of the MBeanServerFactory class. A call to JMXServiceURL creates a new service URL called url, which serves as an address for the connector server. This service URL defines the following:
The connector will use the default RMI transport, JRMP, denoted by rmi.
The RMI registry in which the RMI connector stub will be stored will be running on port 9999 on the local host, and the server will be registered under the name server. The port 9999 specified in the example is arbitrary; you can use any available port.
Finally, an RMI connector server named cs is created by calling the JMXConnectorServerFactory constructor, with the service URL url, a null environment map, and the MBean server mbs as parameters. The connector server cs is launched by calling the start() method of JMXConnectorServer, whereupon the instance of RMIConnectorServer that is created exports its underlying RMI server stub server to the RMI registry.