[TOC] [Prev] [Next]

Client Interfaces


When writing an Applet or an application that uses remote objects, the programmer may need to be aware of the RMI system's client visible interfaces.

Topics:

The Remote Interface

package java.rmi;

public interface Remote {}
The Remote interface serves to identify all remote objects, any object that is a remote object must directly or indirectly implement this interface.

The RemoteException Class

All remote exceptions are subclasses of java.rmi.RemoteException. This allows interfaces to handle all types of remote exceptions and to distinguish local exceptions and exceptions specific to the method from exceptions thrown by the underlying distributed object mechanisms.

package java.rmi;
public class RemoteException 
	extends java.lang.Exception
{
	public RemoteException(String s);
	public RemoteException(String s, Exception e);
}

The RemoteObject Class

This class implements the java.lang.Object behavior for remote objects. The hashCode and equals methods are implemented to allow remote object references to be stored in hashtables and compared. The equals method returns true if two Remote objects refer to the same remote object. It compares the remote object references of the remote objects.

The toString method returns a string describing the remote object. The contents and syntax of this string is implementation specific and may vary.

All of the other methods of java.lang.Object retain their original implementations.

package java.rmi.server;
public abstract class RemoteObject
	implements Remote
{
	public int hashCode();
	public boolean equals(Object obj);
	public String toString();
}

The RemoteStub Class

The RemoteStub class is the common superclass to all client stubs and provides the framework to support a wide range of remote reference semantics.

package java.rmi.server;
public abstract class RemoteStub extends RemoteObject {}

The Naming Class

The Naming interface 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 class Naming {
	public static Remote lookup(String url)
		throws RemoteException, NotBoundException, 
			AccessException, UnknownHostException;

	public static void bind(String url, Remote obj)
		throws RemoteException, AlreadyBoundException,
				AccessException, UnknownHostException;
	
	public static void rebind(String url, Remote obj)
		throws RemoteException, AccessException,
			UnknownHostException;

	public static void unbind(String url)
		throws RemoteException, NotBoundException,
				AccessException, UnknownHostException;

	public static String[] list(String url)
		throws RemoteException, AccessException,
			UnknownHostException;
}
The lookup method returns the Remote interface 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. The file part of the URL is ignored.

Exceptions

These are the general remote object exceptions that the client is most likely to encounter



[TOC] [Prev] [Next]

rmi-comments@jse.East.Sun.COM
Copyright © 1996 Sun Microsystems, Inc. All rights reserved.