Java Tutorial/Trail: RMI

RMI
The Java Remote Method Invocation (RMI) system is a network communication framework for client–server communication. RMI is java-centric because the framework expects both sides of the communication to be implemented in Java; other frameworks are more usually at least specified language agnostic. The java-centric design makes RMI quite convenient for network communication in the Java programming language. The RMI system has, however, been retrofitted to support the Corba Internet Inter-ORB protocol (RMI-IIOP) in addition to the native protocol JRMP.

Server
The RMI server (cvs) exports an implementing class (in this example ), which is derived from an interface (in this example  ) that specifies the methods available through RMI. All methods of the interface must throw the and the interface must extend the  interface, thus marking the interface as an exportable interface. The interface is a tagging interface and thus does not require the implementing class to implement any methods.

Client
A simple RMI client (cvs) can connect to the server and make the interface locally available in a different virtual machine and possibly on a different computer.

(source code from vsrs.svn.sourceforge.net)

Serializable
The interface must be implemented by all classes that are meant to be transported through an RMI connection; this interface is also a tagging interface, which tells  that the object in question is suitable for serialization.

It is recommended but not required for classes that implement the interface to declare a special static final variable:

This variable substitutes version information that is otherwise generated by the virtual machine and that is meant to ensure that the classes on both sides of the RMI connection are compatible with each other. If the classes implement a well-defined interface (or wire format) one could, for instance, use the current version of the interface that is implemented as the  (e.g 100000000 for 1.0.0, 100100000 for 1.1.0 and so on).

The Java RMI compiler
The Java RMI compiler rmic (or grmic for the GNU variant) generates internal objects that are required for RMI connections. The simplest invocation of rmic is, which compiles the class "Class" in the package "package", provided that the compiled class can be found in the directory corresponding to the package name.