CONTENTS | PREV | NEXT Java Remote Method Invocation


6.2 The LocateRegistry Class

The class java.rmi.registry.LocateRegistry is used to obtain a reference to a bootstrap remote object registry on a particular host (including the local host), or to create a remote object regsitry that accepts calls on a specific port.

Note that a getRegistry call does not actually make a connection to the remote host. It simply creates a local reference to the remote registry and will succeed even if no registry is running on the remote host. Therefore, a subsequent method invocation to a remote registry return as a result of this method may fail.

The first four getRegistry methods return a reference to a registry on the current host, current host at a specified port, a specified host, or at a particular port on a specified host. What is returned is the remote stub for the registry with the specified host and port information.

The fifth getRegistry method (that takes an RMIClientSocketFactory as one of its arguments), returns a locally created remote reerence to the remote object Registry on the specified host and port. Communication with this remote registry will use the supplied RMIClientSocketFactory, csf, to create Socket connections to the registry on the remote host and port.

package java.rmi.registry;
public final class LocateRegistry {
	public static Registry getRegistry()
		throws java.rmi.RemoteException;

	public static Registry getRegistry(int port)
		throws java.rmi.RemoteException;

	public static Registry getRegistry(String host)
		throws java.rmi.RemoteException;

	public static Registry getRegistry(String host, int port)
		throws java.rmi.RemoteException;

	public static Registry getRegistry(String host, int port,
											 RMIClientSocketFactory csf)
		throws RemoteException;

	public static Registry createRegistry(int port)
		throws java.rmi.RemoteException;

	public static Registry createRegistry(int port,
										RMIClientSocketFactory csf, 
										RMIServerSocketFactory ssf) 
		throws RemoteException;
}


The createRegistry methods creates and exports a registry on the local host on the specified port.

The second createRegistry method allows more flexiblity in communicating with the registry. This call creates and exports a Registry on the local host that uses custom socket factories for communication with that registry. The registry that is created listens for incoming requests on the given port using a ServerSocket created from the supplied RMIServerSocketFactory. A client that receives a reference to this registry will use a Socket created from the supplied RMIClientSocketFactory.

The registry implements a simple flat naming syntax that binds the name of a remote object (a string) to a remote object reference. The name and remote object bindings are not remembered across server restarts.


Note - Starting a registry with the createRegistry method does not keep the server process alive.


CONTENTS | PREV | NEXT
Copyright © 1997-1998 Sun Microsystems, Inc. All Rights Reserved.