What is RMI ?
RMI ( Remote Method Invocation )
There are different approaches used for developing applications. The internet and the Web are examples of distrinuted systems that have been developed using the Client/Server approach. The transfer of data is one of the most important processes in distributed applications.
The default implementation of the message passing method in Java Virtual Machine (JVM). Another way to achieve the same in using Remote Method Invocation (RMI), which allows objects in different hosts to send and receive messages. Both the methods achieve the same goal.
However, the method calls approach used by RMI in much easier to use. RMI allows objects in different JVMs belonging to different hosts to send and receive message.
RMI is built upon the specification of how local and remote objects interoperate. Local objects are objects that execute on the local machine. Remote objects are objects that execute on all the other machines. Objects on remote hosts are exported so that they can be invoked remotely.
An object exports itself by registering itself with a Remote Registry Server.
A Remote Registry Server is a service that runs on a server and helps the objects on other hosts to remotely access its registered objects. The registry service maintains a database of all the named remote objects.
A Distributed Application Created Using RMI
Objects that are exported for remote access must implemented the interface Remote Interface. This interface identifies the object to be accessed remotely. All the methods that are to be invoked remotely must throw a Remote Exception. The exception is used to handle the errors that may occur during the invocation of a remote method.
Java’s RMI approach is organized into a client/server framework. A local object that invokes a method of a remote object is referred to as a client object, and the remote object whose method are invoked is referred to as a server object.
Java’s RMI approach makes use of stubs and skeletons. A stubs is a local object on the client’s machine that acts as a proxy for a remote object. The stub provides the methods of the remote object.
Local objects invoke the methods of the stubs as of they were methods of the remote objects. The stub communicates this method invocation to the remote object through a skeleton that is implemented on a remote host. The skeleton is the proxy of the client machine’s object that is located on the remote host.
Usage of Stubs and Skeletons to support Client/Server Communication
The stub and the skeleton communication through a remote reference layer. This layer provides stubs the capability to communicate with skeletons through a transport protocol. RMI uses the TCP protocol for transporting information.