Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > ee5115d1de8d9cf1c36a33cc4513700b > files > 1070

mx4j-manual-3.0.1-9.mga4.noarch.rpm

<html><head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Porting old MX4J remoting code to JSR 160</title><link href="styles.css" type="text/css" rel="stylesheet"><meta content="DocBook XSL Stylesheets V1.78.1" name="generator"><link rel="home" href="index.html" title="MX4J English Documentation"><link rel="up" href="ch03.html" title="Chapter&nbsp;3.&nbsp;JSR 160 (JMX Remoting) Explained"><link rel="prev" href="ch03s07.html" title="Using HTTP-based connectors over HTTPS"><link rel="next" href="ch03s09.html" title="MX4J Remote Tools and Utilities"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table summary="Navigation header" width="100%"><tr><th align="center" colspan="3">Porting old MX4J remoting code to JSR 160</th></tr><tr><td align="left" width="20%"><a accesskey="p" href="ch03s07.html">Prev</a>&nbsp;</td><th align="center" width="60%">Chapter&nbsp;3.&nbsp;JSR 160 (JMX Remoting) Explained</th><td align="right" width="20%">&nbsp;<a accesskey="n" href="ch03s09.html">Next</a></td></tr></table><hr></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="N106F0"></a>Porting old MX4J remoting code to JSR 160</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="N106F3"></a>Introduction</h3></div></div></div><p>
         MX4J version 1.x provided a custom implementation of a connector server and connector client based on
         the RMI protocol.
         <br>
         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.
      </p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="N106FA"></a>Porting Examples</h3></div></div></div><p>
         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.
      </p><p>
         </p><div class="example"><a name="N10701"></a><p class="title"><b>Example&nbsp;3.23.&nbsp;Old MX4J 1.x remoting code, server side</b></p><div class="example-contents"><pre class="programlisting">
               
(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();
               
            </pre></div></div><p><br class="example-break">
      </p><p>
         </p><div class="example"><a name="N1070A"></a><p class="title"><b>Example&nbsp;3.24.&nbsp;JSR 160 remoting code, server side</b></p><div class="example-contents"><pre class="programlisting">
               
(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();
               
            </pre></div></div><p><br class="example-break">
      </p><p>
         Note the following differences:
         </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
               How the JNDI name "jrmp" has been replaced by a JMXServiceURL with an URLPath of "/jndi/jrmp".
            </li><li class="listitem">
               How the instantiation of the adaptor has been replaced by usage of a factory.
            </li><li class="listitem">
               How the JNDI properties are passed via a Map.
            </li></ol></div><p>
      </p><p>
         Note that in both cases the adaptor (connector server) must be started in order to be able to accept
         incoming connections (4).
      </p><p>
         Note also that both the JRMPAdaptor and the JMXConnectorServer are MBeans, and as such they can be
         registered inside an MBeanServer (no differences here).
      </p><p>
         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.
      </p><p>
         </p><div class="example"><a name="N10725"></a><p class="title"><b>Example&nbsp;3.25.&nbsp;Old MX4J 1.x remoting code, client side</b></p><div class="example-contents"><pre class="programlisting">
               
(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();
               
            </pre></div></div><p><br class="example-break">
      </p><p>
         </p><div class="example"><a name="N1072E"></a><p class="title"><b>Example&nbsp;3.26.&nbsp;JSR 160 remoting code, client side</b></p><div class="example-contents"><pre class="programlisting">
               
(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();
               
            </pre></div></div><p><br class="example-break">
      </p><p>
         Again, note the following differences:
         </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
               How the JNDI name "jrmp" has been replaced by a JMXServiceURL with an URLPath of "/jndi/jrmp".
            </li><li class="listitem">
               How the instantiation of the connector has been replaced by usage of a factory.
            </li><li class="listitem">
               How the JNDI properties are passed via a Map.
            </li><li class="listitem">
               The different number of arguments passed to the connect() method.
            </li><li class="listitem">
               How the
               <code class="classname">mx4j.connector.RemoteMBeanServer</code> class is replaced by the
               <code class="classname">javax.management.MBeanServerConnection</code> class.
            </li></ol></div><p>
      </p><p>
         Very similar changes apply when the old MX4J 1.x remoting code is using the
         <code class="classname">mx4j.adaptor.rmi.iiop.IIOPAdaptor</code> and the
         <code class="classname">mx4j.connector.rmi.iiop.IIOPConnector</code>.
      </p></div></div><div class="navfooter"><hr><table summary="Navigation footer" width="100%"><tr><td align="left" width="40%"><a accesskey="p" href="ch03s07.html">Prev</a>&nbsp;</td><td align="center" width="20%"><a accesskey="u" href="ch03.html">Up</a></td><td align="right" width="40%">&nbsp;<a accesskey="n" href="ch03s09.html">Next</a></td></tr><tr><td valign="top" align="left" width="40%">Using HTTP-based connectors over HTTPS&nbsp;</td><td align="center" width="20%"><a accesskey="h" href="index.html">Home</a></td><td valign="top" align="right" width="40%">&nbsp;MX4J Remote Tools and Utilities</td></tr></table></div></body></html>