CONTENTS | PREV | NEXT Java Remote Method Invocation


6.1 The Registry Interface

The java.rmi.registry.Registry remote interface provides methods for lookup, binding, rebinding, unbinding, and listing the contents of a registry. The java.rmi.Naming class uses the registry remote interface to provide URL-based naming.

package java.rmi.registry;

public interface Registry extends java.rmi.Remote {

public static final int REGISTRY_PORT = 1099;

public java.rmi.Remote lookup(String name) throws java.rmi.RemoteException, java.rmi.NotBoundException, java.rmi.AccessException; public void bind(String name, java.rmi.Remote obj) throws java.rmi.RemoteException, java.rmi.AlreadyBoundException, java.rmi.AccessException; public void rebind(String name, java.rmi.Remote obj) throws java.rmi.RemoteException, java.rmi.AccessException; public void unbind(String name) throws java.rmi.RemoteException, java.rmi.NotBoundException, java.rmi.AccessException; public String[] list() throws java.rmi.RemoteException, java.rmi.AccessException; }

The REGISTRY_PORT is the default port of the registry.

The lookup method returns the remote object bound to the specified name. The remote object implements a set of remote interfaces. Clients can cast the remote object to the expected remote interface. (This cast can fail in the usual ways that casts can fail with a ClassCastException.)

The bind method associates the name with the remote object, obj. If the name is already bound to an object, AlreadyBoundException is thrown.

The rebind method associates the name with the remote object, obj. Any previous binding of the name is discarded.

The unbind method removes the binding between the name and the remote object, obj. If the name is not already bound to an object, NotBoundException is thrown.

The list method returns an array of Strings containing a snapshot of the names bound in the registry. The return value contains a snapshot of the contents of the registry.

Clients can access the registry either by using the LocateRegistry and Registry interfaces, or by using the methods of the URL-based java.rmi.Naming class. The registry supports bind, unbind, and rebind only from clients on the same host as the server; a lookup can be done from any host.



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