CONTENTS | PREV | NEXT | Java Remote Method Invocation |
LocateRegistry
Class
The classjava.rmi.registry.LocateRegistry
is used to obtain a reference (construct a stub) to a bootstrap remote object registry on a particular host (including the local host), or to create a remote object registry that accepts calls on a specific port.The registry implements a simple flat naming syntax that associates the name of a remote object (a string) with a remote object reference. The name and remote object bindings are not remembered across server restarts.
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 returned as a result of this method may fail.
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 first fourgetRegistry
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 anRMIClientSocketFactory
as one of its arguments), returns a locally created remote stub to the remote objectRegistry
on the specified host and port. Communication with the remote registry whose stub is constructed with this method will use the suppliedRMIClientSocketFactory
, csf, to createSocket
connections to the registry on the remote host and port.
Note - A registry returned from thegetRegistry
method is a specially constructed stub that contains a well-known object identifier. Passing a registry stub from one JVM to another is not supported (it may or may not work depending on the implementation). Use theLocateRegistry.getRegistry
methods to obtain the appropriate registry for a host.
ThecreateRegistry
method creates and exports a registry on the local host on the specified port.The second
createRegistry
method allows more flexibility in communicating with the registry. This call creates and exports aRegistry
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 aServerSocket
created from the suppliedRMIServerSocketFactory
. A client that receives a reference to this registry will use aSocket
created from the suppliedRMIClientSocketFactory
.
Note - Starting a registry with thecreateRegistry
method does not keep the server process alive.