Topics:
package java.rmi; public interface Remote {}
java.rmi.Remote
interface serves to identify all remote objects, any object that is a remote object must directly or indirectly implement this interface. All remote interfaces must be declared public
.
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.io.IOException { // The actual exception or error that occured. public Throwable detail; // Create a remote exception. public RemoteException() // Create a remote exception with the specified string. public RemoteException(String s) // Create remote exception with specified string and exception. public RemoteException(String s, Throwable ex) // Produce message, including message from any nested exception. public String getMessage() }
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; }
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. The file part of the URL is ignored.The
java.rmi.AccessException
may also be thrown as a result of any of these methods.