Overview of RMI Interfaces and Classes - rsanchez-wsu/jfiles GitHub Wiki

The interfaces and data structures that dictate the behavior of Java's RMI system are located in the java.rmi package.

java.rmi.Remote Interface

A remote interface is any interface that declares a group of methods that can be invoked from a JVM.

In order for it to be considered a remote interface, it must:

  • directly or indirectly extend java.rmi.Remote
  • methods must be declared in such a way as to satisfy remote method declaration, that is:
    • must have the java.rmi.RemoteException in its throws clause
    • remote objects passed as parameters or return values must be declared as the remote interface, not as the implementation class from which it was directly instantiated

A remote interface must extend java.rmi.Remote, but can also extend non-remote interfaces if the extended non-remote interface's methods satisfy the aforementioned requirements of a remote method declaration.

The RemoteException Class

To guarantee robustness in an RMI application, all remote methods must include the java.rmi.RemoteException super class in the throws clause.

Examples of when this exception might be thrown:

  • A communication failure; the server cannot be reached or was closed
  • "Failure during parameter or return value marshalling or unmarshalling"
  • An error occurred with the protocol

RemoteException is not a runtime exception; it must be handled by the caller.

The RemoteObject Class and its Subclasses

RMI services are provided by the RemoteObject class and the subclasses:

  • java.rmi.server.RemoteServer "provides implementations for the java.lang.Object methods, hashcode, equals, and toString."
  • java.rmi.server.UnicastRemoteObject contains the methods needed to create remote objects and make them available to the client(s).
  • java.rmi.activation.Activatable is an abstract class that instantiates an activatable remote object that runs when its remote methods are called.

reference: https://docs.oracle.com/javase/7/docs/platform/rmi/spec/rmi-objmodel5.html