MX4J version 1.x provided a custom implementation of a connector server and connector client based on
the RMI protocol.
That old code is now obsolete due to the fact that MX4J implements JSR 160. In the following sections will
be explained how to port old MX4J 1.x remoting code to the standard JSR 160 API.
The following example will show old MX4J 1.x remoting code compared to JSR 160 code, with respect to creating and starting a connector server over JRMP on server side.
Example 3.23. Old MX4J 1.x remoting code, server side
(1) String jndiName = "jrmp"; (2) mx4j.adaptor.rmi.jrmp.JRMPAdaptor adaptor = new mx4j.adaptor.rmi.jrmp.JRMPAdaptor(); (3) adaptor.putJNDIProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); adaptor.putJNDIProperty(Context.PROVIDER_URL, "rmi://localhost:1099"); adaptor.setJNDIName(jndiName); (4) adaptor.start();
Example 3.24. JSR 160 remoting code, server side
(1) JMXServiceURL address = new JMXServiceURL("rmi", "localhost", 0, "/jndi/jrmp"); (3) Map environment = new HashMap(); environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); environment.put(Context.PROVIDER_URL, "rmi://localhost:1099"); (2) JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnector(address, environment, null); (2) (4) cntorServer.start();
Note the following differences:
Note that in both cases the adaptor (connector server) must be started in order to be able to accept incoming connections (4).
Note also that both the JRMPAdaptor and the JMXConnectorServer are MBeans, and as such they can be registered inside an MBeanServer (no differences here).
The following example will show old MX4J 1.x remoting code compared to JSR 160 code, with respect to creating and connecting a connector over JRMP on client side.
Example 3.25. Old MX4J 1.x remoting code, client side
(1) String jndiName = "jrmp"; (2) mx4j.connector.rmi.jrmp.JRMPConnector connector = new mx4j.connector.rmi.jrmp.JRMPConnector(); (3) Hashtable environment = new Hashtable(); environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); environment.put(Context.PROVIDER_URL, "rmi://localhost:1099"); (4) connector.connect(jndiName, environment); (5) mx4j.connector.RemoteMBeanServer server = connector.getRemoteMBeanServer();
Example 3.26. JSR 160 remoting code, client side
(1) JMXServiceURL address = new JMXServiceURL("rmi", "localhost", 0, "/jndi/jrmp"); (3) Map environment = new HashMap(); environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); environment.put(Context.PROVIDER_URL, "rmi://localhost:1099"); (2) JMXConnector connector = JMXConnectorFactory.newJMXConnector(address, environment); (4) connector.connect(environment); (5) MBeanServerConnection server = connector.getMBeanServerConnection();
Again, note the following differences:
Very similar changes apply when the old MX4J 1.x remoting code is using the mx4j.adaptor.rmi.iiop.IIOPAdaptor and the mx4j.connector.rmi.iiop.IIOPConnector.