view src/share/classes/javax/management/remote/rmi/package.html @ 0:37a05a11f281

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
children 00cd9dc3c2b5
line wrap: on
line source
    <title>RMI connector</title>
Copyright 2002-2006 Sun Microsystems, Inc.  All Rights Reserved.

This code is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 only, as
published by the Free Software Foundation.  Sun designates this
particular file as subject to the "Classpath" exception as provided
by Sun in the LICENSE file that accompanied this code.

This code is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
version 2 for more details (a copy is included in the LICENSE file that
accompanied this code).

You should have received a copy of the GNU General Public License version
2 along with this work; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
CA 95054 USA or visit if you need additional information or
have any questions.
<body bgcolor="white">
    <p>The RMI connector is a connector for the JMX Remote API that
      uses RMI to transmit client requests to a remote MBean server.
      This package defines the classes that the user of an RMI
      connector needs to reference directly, for both the client and
      server sides.  It also defines certain classes that the user
      will not usually reference directly, but that must be defined so
      that different implementations of the RMI connector can

    <p>The RMI connector supports both the JRMP and the IIOP transports
      for RMI.</p>

    <p>Like most connectors in the JMX Remote API, an RMI connector
      usually has an address, which
      is a {@link
      JMXServiceURL}.  The protocol part of this address is
      <code>rmi</code> for a connector that uses the default RMI
      transport (JRMP), or <code>iiop</code> for a connector that
      uses RMI/IIOP.</p>

    <p>There are two forms for RMI connector addresses:</p>

	In the <em>JNDI form</em>, the URL indicates <em>where to find
	an RMI stub for the connector</em>.  This RMI stub is a Java
	object of type {@link
	RMIServer} that gives remote access to the connector server.
	With this address form, the RMI stub is obtained from an
	external directory entry included in the URL.  An external
	directory is any directory recognized by {@link javax.naming
	JNDI}, typically the RMI registry, LDAP, or COS Naming.

	In the <em>encoded form</em>, the URL directly includes the
	information needed to connect to the connector server.  When
	using RMI/JRMP, the encoded form is the serialized RMI stub
	for the server object, encoded using BASE64 without embedded
	newlines.  When using RMI/IIOP, the encoded form is the CORBA
	IOR for the server object.
    <p>Addresses are covered in more detail below.</p>

    <h3>Creating an RMI connector server</h3>

    <p>The usual way to create an RMI connector server is to supply an
      RMI connector address to the method {@link
      JMXConnectorServerFactory.newJMXConnectorServer}.  The MBean
      server to which the connector server is attached can be
      specified as a parameter to that method.  Alternatively, the
      connector server can be registered as an MBean in that MBean

    <p>An RMI connector server can also be created by constructing an
      instance of {@link
      RMIConnectorServer}, explicitly or through the MBean server's
      <code>createMBean</code> method.</p>

    <h4>Choosing the RMI transport</h4>

    <p>You can choose the RMI transport (JRMP or IIOP) by specifying
      <code>rmi</code> or <code>iiop</code> in the
      <code><em>protocol</em></code> part of the
      <code>serviceURL</code> when creating the connector server.  You
      can also create specialised connector servers by instantiating
      an appropriate subclass of {@link RMIServerImpl} and
      supplying it to the <code>RMIConnectorServer</code>

    <h4><a name="servergen">Connector addresses generated by the

    <p>If the <code>serviceURL</code> you specify has an empty URL
      path (after the optional host and port), or if you do not
      specify a <code>serviceURL</code>, then the connector server
      will fabricate a new <code>JMXServiceURL</code> that clients can
      use to connect:</p>


      <li><p>If the <code>serviceURL</code> looks like:</p>


	<p>then the connector server will generate an {@link
	RMIJRMPServerImpl} and the returned <code>JMXServiceURL</code>
	looks like:</p>


	<p>where <code><em>XXXX</em></code> is the serialized form of the
	stub for the generated object, encoded in BASE64 without

      <li><p>If the <code>serviceURL</code> looks like:</p>

	<p>then the connector server will generate an {@link
	RMIIIOPServerImpl} and the returned
	<code>JMXServiceURL</code> looks like:</p>


	<p>where <code>IOR:<em>XXXX</em></code> is the standard CORBA
	encoding of the Interoperable Object Reference for the
	generated object.</p>

      <li><p>If there is no <code>serviceURL</code>, there must be a
	user-provided <code>RMIServerImpl</code>.  If the {@link toStub}
	method on this object returns an instance of {@link
	javax.rmi.CORBA.Stub}, then the connector server will generate
	a <code>JMXServiceURL</code> using the <code>iiop</code>
	form above.  Otherwise, it will generate a
	<code>JMXServiceURL</code> using the <code>rmi</code>


    <p>The <code><em>host</em></code> in a user-provided
      <code>serviceURL</code> is optional.  If present, it is copied
      into the generated <code>JMXServiceURL</code> but otherwise
      ignored.  If absent, the generated <code>JXMServiceURL</code>
      will have the local host name.</p>

    <p>The <code><em>port</em></code> in a user-provided
      <code>serviceURL</code> is also optional.  If present, it is
      also copied into the generated <code>JMXServiceURL</code>;
      otherwise, the generated <code>JMXServiceURL</code> has no port.
      For an <code>serviceURL</code> using the <code>rmi</code>
      protocol, the <code><em>port</em></code>, if present, indicates
      what port the generated remote object should be exported on.  It
      has no other effect.</p>

    <p>If the user provides an <code>RMIServerImpl</code> rather than a
      <code>JMXServiceURL</code>, then the generated
      <code>JMXServiceURL</code> will have the local host name in its
      <code><em>host</em></code> part and no

    <h4><a name="directory">Connector addresses based on directory

    <p>As an alternative to the generated addresses just described,
      the <code>serviceURL</code> address supplied when creating a
      connector server can specify a <em>directory address</em> in
      which to store the provided or generated <code>RMIServer</code>
      stub.  This directory address is then used by both client and

    <p>In this case, the <code>serviceURL</code> has one of these two


    <p>Here, <code><em>jndi-name</em></code> is a string that can be
      supplied to {@link javax.naming.InitialContext#bind

    <p>As usual, the <code><em>host</em></code> and
      <code>:<em>port</em></code> can be omitted.</p>

    <p>The connector server will generate an
      <code>RMIServerImpl</code> based on the protocol
      (<code>rmi</code> or <code>iiop</code>) and, for
      <code>rmi</code>, the <code><em>port</em></code> if any.  When
      the connector server is started, it will derive a stub from this
      object using its {@link toStub} method
      and store the object using the given
      <code><em>jndi-name</em></code>.  The properties defined by the
      JNDI API are consulted as usual.</p>

    <p>For example, if the <code>JMXServiceURL</code> is:


      then the connector server will generate an
      <code>RMIJRMPServerImpl</code> and store its stub using the JNDI


      which means entry <code>myname</code> in the RMI registry
      running on the default port of host <code>myhost</code>.  Note
      that the RMI registry only allows registration from the local
      host.  So, in this case, <code>myhost</code> must be the name
      (or a name) of the host that the connector server is running

    <p>In this <code>JMXServiceURL</code>, the first <code>rmi:</code>
      specifies the RMI
      connector, while the second <code>rmi:</code> specifies the RMI

    <p>As another example, if the <code>JMXServiceURL</code> is:


      then the connector server will generate an
      <code>RMIIIOPServerImpl</code> and store its stub using the JNDI


      which means entry <code>cn=this,ou=that</code> in the LDAP
      directory running on port 9999 of host <code>dirhost</code>.</p>

    <p>If the <code>JMXServiceURL</code> is:


      then the connector server will generate an
      <code>RMIIIOPServerImpl</code> and store its stub using the JNDI


      For this case to work, the JNDI API must have been configured
      appropriately to supply the information about what directory to

    <p>In these examples, the host name <code>ignoredhost</code> is
      not used by the connector server or its clients.  It can be
      omitted, for example:</p>


    <p>However, it is good practice to use the name of the host
      where the connector server is running.  This is often different
      from the name of the directory host.</p>

    <h4>Connector server attributes</h4>

    <p>When using the default JRMP transport, RMI socket factories can
      be specified using the attributes
      <code>jmx.remote.rmi.client.socket.factory</code> and
      <code>jmx.remote.rmi.server.socket.factory</code> in the
      <code>environment</code> given to the
      <code>RMIConnectorServer</code> constructor.  The values of these
      attributes must be of type {@link
      java.rmi.server.RMIClientSocketFactory} and {@link
      java.rmi.server.RMIServerSocketFactory}, respectively.  These
      factories are used when creating the RMI objects associated with
      the connector.</p>

    <h3>Creating an RMI connector client</h3>

    <p>An RMI connector client is usually constructed using {@link}, with a
      <code>JMXServiceURL</code> that has <code>rmi</code> or
      <code>iiop</code> as its protocol.</p>

    <p>If the <code>JMXServiceURL</code> was generated by the server,
      as described above under <a href="#servergen">"connector
      addresses generated by the server"</a>, then the client will
      need to obtain it directly or indirectly from the server.
      Typically, the server makes the <code>JMXServiceURL</code>
      available by storing it in a file or a lookup service.</p>

    <p>If the <code>JMXServiceURL</code> uses the directory syntax, as
      described above under <a href="#directory">"connector addresses
      based on directory entries"</a>, then the client may obtain it
      as just explained, or client and server may both know the
      appropriate directory entry to use.  For example, if the
      connector server for the Whatsit agent uses the entry
      <code>whatsit-agent-connector</code> in the RMI registry on host
      <code>myhost</code>, then client and server can both know
      that the appropriate <code>JMXServiceURL</code> is:</p>


    <p>If you have an RMI stub of type {@link RMIServer}, you can
      construct an RMI connection directly by using the appropriate
      constructor of {@link

    <h3>Specifying an ORB for the RMI/IIOP connector</h3>

    <p>When using the IIOP transport, the client and server can
      specify what ORB to use
      with the attribute <code>java.naming.corba.orb</code>.
      Connection to the ORB happens at {@link start} time 
      for the connector server, and at {@link 
      connect} time for the connector client.
      If the <code>java.naming.corba.orb</code> attribute is contained
      in the environment Map, then its value (an {@link 
      org.omg.CORBA.ORB ORB}), is used to connect the IIOP Stubs. 
      Otherwise, a new org.omg.CORBA.ORB is created by calling {@link 
      org.omg.CORBA.ORB.init((String[])null,(Properties)null)}.  A
      later RMI connector client or server in the same JVM can reuse
      this ORB, or it can create another one in the same way.</p>

     <p>If the <code>java.naming.corba.orb</code> attribute is 
      specified and does not point to an {@link org.omg.CORBA.ORB ORB},
      then an <code>{@link java.lang.IllegalArgumentException}</code> 
      will be thrown.</p>

     <p>The mechanism described here does not apply when the IIOP
      Remote objects (Stubs or Servers) are created and connected to
      an ORB manually before being passed to the RMIConnector and

    <h3>Dynamic code downloading</h3>

    <p>If an RMI connector client or server receives from its peer an
      instance of a class that it does not know, and if dynamic code
      downloading is active for the RMI connection, then the class can
      be downloaded from a codebase specified by the peer.  The
      article <a
    code downloading using Java RMI</em></a> explains this in more

    @see <a href="{@docRoot}/../technotes/guides/rmi/index.html">
	Java<sup><font size="-1">TM</font></sup> Remote Method
	Invocation (RMI)</a>

    @see <a href="{@docRoot}/../technotes/guides/jndi/index.html">
	Java Naming and Directory Interface<sup><font
	size="-1">TM</font></sup> (JNDI)</a>

    @see <a href="">RFC 2045,
    section 6.8, "Base64 Content-Transfer-Encoding"</a>

    @since 1.5