Java Reference
In-Depth Information
The Interfaces
The
Remote
interface is another marker interface, similar to the
Serializable
interface dis-
cussed earlier. The term
remote
indicates that the methods defined may be accessed from a
different virtual machine than the one containing the remote object. For an object to be con-
sidered a remote object, the
Remote
interface must be implemented. Implementing this
interface is accomplished by extending
java.rmi.Remote
.
Any public method defined in the
Remote
interface must throw a
java.rmi.RemoteException
or a super interface of
java.rmi.RemoteException
such as an
IOException
,
Throwable
, or
Exception
. This is the super class for all communication exceptions that occur during the
invocation of a remote method.
RemoteException
is a checked exception and must therefore
be enclosed in the try/catch block or specified in the method signature of any object that
uses a remote object. A
RemoteException
may occur for either of the following reasons:
•
The server is down, unreachable, or has terminated communication with the client.
•
Errors were encountered during marshaling of params and return values.
One more interface is needed to create a remote object. The abstract class
java.rmi.
RemoteObject
, which is displayed in Figure 6-7, must also be extended. You can think of
RemoteObject
as a remote object analog to
java.lang.Object
.
RemoteObject
provides the
network implementations for the
java.lang.Object
methods
toString()
,
hashCode()
, and
equals()
that are appropriate for remote objects. Figure 6-8 shows the RMI layers.
Figure 6-8.
RMI layers