CONTENTS | PREV | NEXT Java Remote Method Invocation


4.3 The Naming Class

The java.rmi.Naming class allows remote objects to be retrieved and defined using the familiar Uniform Resource Locator (URL) syntax. The URL consists of protocol, host, port, and name fields. The Registry service on the specified host and port is used to perform the specified operation. The protocol should be specified as rmi, as in rmi://java.sun.com:2001/root.

package java.rmi;
public final class Naming {
	public static Remote lookup(String url)
		throws NotBoundException, java.net.MalformedURLException,
		UnknownHostException, RemoteException;

	public static void bind(String url, Remote obj)
		throws AlreadyBoundException,
		java.net.MalformedURLException, UnknownHostException,
		RemoteException;
	
	public static void rebind(String url, Remote obj)
		throws RemoteException, java.net.MalformedURLException,
		UnknownHostException;

	public static void unbind(String url)
		throws RemoteException, NotBoundException,
		java.net.MalformedURLException, UnknownHostException;

	public static String[] list(String url)
		throws RemoteException, java.net.MalformedURLException,
		UnknownHostException;
}


The lookup method returns the remote object associated with the file portion of the name; so in the preceding example it would return the object named root. The NotBoundException is thrown if the name has not been bound to an object.

The bind method binds the specified name to the remote object. It throws the AlreadyBoundException if the name is already bound to an object.

The rebind method always binds the name to the object even if the name is already bound. The old binding is lost.

The unbind method removes the binding between the name and the remote object. It will throw the NotBoundException if there was no binding.

The list method returns an array of Strings containing a snapshot of the URLs bound in the registry. Only the host and port information of the URL is needed to contact a registry for the list of its contents; thus, the "file" part of the URL is ignored.


Note - The java.rmi.AccessException may also be thrown as a result of any of these methods. The AccessException indicates that the caller does not have permission to execute the specific operation. For example, only clients that are local to the host on which the registry runs are permitted to execute the operations, bind, rebind, and unbind. A lookup operation, however can be invoked from any non-local client.


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