CONTENTS | PREV | NEXT | Java Remote Method Invocation |
java.rmi.Remote
Interfacejava.rmi.Remote
.java.rmi.RemoteException
(or one of its superclasses
such as java.io.IOException
or
java.lang.Exception
) in its throws clause, in addition
to any application-specific exceptions (note that application
specific exceptions do not have to extend
java.rmi.RemoteException
).java.rmi.Remote
is a marker interface
that defines no methods:
public interface Remote {}A remote interface must at least extend the interface
java.rmi.Remote
(or another remote interface that
extends java.rmi.Remote
). However, a remote interface
may extend a non-remote interface under the following condition:
BankAccount
defines a remote interface for accessing a bank account. It
contains remote methods to deposit to the account, to get the
account balance, and to withdraw from the account:
public interface BankAccount extends java.rmi.Remote { public void deposit(float amount) throws java.rmi.RemoteException; public void withdraw(float amount) throws OverdrawnException, java.rmi.RemoteException; public float getBalance() throws java.rmi.RemoteException; }The next example shows a valid remote interface
Beta
that extends a non-remote
interface Alpha
, which has remote methods, and the
interface java.rmi.Remote
:
public interface Alpha { public final String okay = "constants are okay too"; public Object foo(Object obj) throws java.rmi.RemoteException; public void bar() throws java.io.IOException; public int baz() throws java.lang.Exception; } public interface Beta extends Alpha, java.rmi.Remote { public void ping() throws java.rmi.RemoteException; }
RemoteException
Classjava.rmi.RemoteException
class is the superclass of
exceptions thrown by the RMI runtime during a remote method
invocation. To ensure the robustness of applications using the RMI
system, each remote method declared in a remote interface must
specify java.rmi.RemoteException
(or one of its
superclasses such as java.io.IOException
or
java.lang.Exception
) in its throws clause.
The exception
java.rmi.RemoteException
is thrown when a remote
method invocation fails for some reason. Some reasons for remote
method invocation failure include:
RemoteException
is a checked exception (one
that must be handled by the caller of a remote method and is
checked by the compiler), not a RuntimeException
.
RemoteObject
Class and its Subclassesjava.rmi.server.RemoteObject
and its
subclasses, java.rmi.server.RemoteServer
and
java.rmi.server.UnicastRemoteObject
and
java.rmi.activation.Activatable
.
java.rmi.server.RemoteObject
provides
implementations for the java.lang.Object
methods,
hashCode
, equals
, and
toString
that are sensible for remote objects.UnicastRemoteObject
and Activatable
. The
subclass identifies the semantics of the remote reference, for
example whether the server is a simple remote object or is an
activatable remote object (one that executes when invoked).java.rmi.server.UnicastRemoteObject
class
defines a singleton (unicast) remote object whose references are
valid only while the server process is alive.java.rmi.activation.Activatable
is an
abstract class that defines an activatable remote object
that starts executing when its remote methods are invoked and can
shut itself down when necessary.