The RMI protocol
The RMI protocol uses a combination of two other protocols to turn
simple method invocations into remote method invocations:
Object
Serialization
HTTP
The object serialization protocol
is used to marshal data and the HTTP protocol is used to post a remote
method invocation.
Overview
of RMI Interfaces and Classes
The
Remote Interface
The interface java.rmi.Remote is a
marker interface that contains no methods:
public interface Remote {}
This interface is used to identify objects that can be referenced remotely.
All remote objects must directly or indirectly implement this interface.
A single class can implement more than one remote interface. The following
is an example that declares one method that can be invoked remotely.
public interface RemoteInterface extends Remote{
public String remoteMethod1()throws
RemoteException;
}
The RemoteException
Class
The class RemoteException is the superclass
for a number of communication-related exceptions that may occur during
the execution of a remote method call. Each method of a remote interface
must list RemoteException
in its throws clause. RemoteException is a checked exception.
The
RemoteObject Class
RMI server functions are provided by the java.rmi.server.RemoteObject
and its subclasses, java.rmi.server.RemoteServer,
java.rmi.server.UnicastRemoteObject. The RemoteObject
class implements the java.lang.Object
behavior for remote objects. RemoteObject
class provides the remote semantics of Object by implementing methods
for hashCode(), equals(), and
toString(). RemoteObject class is abstract, so it cannot be instantiated.
Methods
- public RemoteRef getRef()
- Returns the remote reference for the remote object.
- public static Remote toStub(Remote
obj) - Returns the stub for the remote object "obj" passed
as a parameter. This operation is only valid after the object has
been exported.
The
RemoteServer Class
The java.rmi.server.RemoteServer
class is the super class of the server implementation classes java.rmi.server.UnicastRemoteObject
and java.rmi.activation.Activatable.
Subclasses of RemoteServer
handle the tasks of exporting the remote object. RemoteServer
class is abstract, so it cannot be instantiated.
Methods
- public static String getClientHost()
- Returns the hostname of the client calling the method.
- public static void setLog(OutputStream
out) - This method enables to set the log output stream. If
out is null, call logging is turned off.
- public static PrintStream
getLog() - Returns stream for the RMI call log, so that
application-specific information can be written to the call log in
a synchronized manner.
|