The
java.rmi.registry package
The Registry Interface
A Registry is used to locate RMI services. The server is responsible
for registering remote objects. A client must first locate the exported
remote objects. Once a client has retrieved a reference to a remote
object, subsequent objects can be accessed through other means, namely
return values. The java.rmi.registry.Registry
interface provides methods for lookup, binding, rebinding, and listing
the contents of a registry. Actually, the methods of java.rmi.Naming
class call the methods of a remote object that implements the Registry
interface.
Methods
- public void bind(String
name, Remote obj) - This method binds the specified
"name"
to a remote object. It throws an AlreadyBoundException,
if the name is already bound to an object. Binding means
associating a name for a remote object that can be used to look up
that remote object.
- public String[] list()
- It returns an array of the Strings bound in the registry. Each String
object contains a name that is bound to a remote object. The names
are URL-formatted strings.
- public Remote lookup(String
name) - The lookup method is used to get a remote object from
a registry. It returns a stub for the remote object associated with
the specified
"name".
It takes a string containing the URL to a remote object reference
on the server.
- public void rebind(String
name, Remote obj) - It rebinds the specified name to a remote
object. It replaces an object that is already bound with the registry
with the new object specified with obj.
- public void unbind(String
name) - It removes an object reference from the registry. It
throws a
NotBoundException
if there was no binding.
The LocateRegistry
Class
The LocateRegistry class can
be used to find or create a new registry.
Methods
- public static Registry createRegistry(int
port) - This method is used to create and export a registry
on the local host that accepts requests on the specified port.
The port must be available otherwise an exception will be thrown.
- public static Registry getRegistry()
- This method returns a reference to the registry on port no.
1099.
- public static Registry getRegistry(int
port) - This method attempts to return a reference to the registry
on the specified port.
- public static Registry getRegistry(String
host) - This method returns a reference to the registry
on the specified host on port no. 1099. If host is null, the local
host is assumed. If the given host cannot be resolved, an UnknownHostException
is thrown.
- public static Registry getRegistry(String
host, int port) - This method returns a reference to the registry
on the specified host and port. If the given host cannot be resolved,
an UnknownHostException is
thrown.
- public static Registry getRegistry(String
host, int port,RMIClientSocketFactory csf) - This method returns
a locally created remote reference to the registry on the specified
host and port. Communication with the registry will use the
supplied RMIClientSocketFactory
csf.
There are two ways to start a registry:
Use
the RMI registry application (rmiregistry)
Use
java.rmi.registry package
to write your own registry service.
|