RMI for Computer Science and MCA students

Explain RMI architecture

RMI Architecture
The RMI architecture consists of four layers. These layers perform the specific functions like establishing a connection, transmitting the objects.

The layers are as follows:

1. Application Layer
  • It is the actual implementation of the client server application. The high level calls are made here in order to access and export the remote objects. The remote method can be accessed by the client through an interface that inherits from java.rmi.Remote interface. Once this method described in the remote interface is implemented the object is exported. The remote object is implicitly exported only if the object inherits from java.rmi.server.UnicastRemoteObject class. The application will then register itself with a naming server or registry. It is used by the client to obtain a reference of the remote objects.
2. Proxy Layer
  • It is also known as the Stub and Skeleton Layer. They are simply class files that represent the client and server side of a remote object. Stub is placed on the client side and Skeleton is placed on the server side.
Responsibility of Stub class
  • It works with the JVM and the RMI system on the client machine to serialize the arguments to the remote method call and it sends the information to the server machine.
  • It receives any result from the remote method and returns it to the client.
Responsibility of the Skeleton class
  • It receives the remote method call and any of the associated arguments. It works with the JVM and RMI system on the server machine to deserialize any of the arguments for this remote method call.
  • Any return value is received from the method call and works with the JVM and the RMI system on the server machine to serialize the return value and sends the information back to the client application.
3. Remote Reference Layer

It is effectively between the Stub and Skeleton classes and the transport layer which handles the actual communication protocol. The transmission of the parameter or object through the network it should be in the form of a stream.

This layer is used for the following reasons:
  • It handles the replicated objects. This feature is incorporated in the RMI system so the replicated objects allow simple dispatch to many programs that are exporting substantially the same remote objects.
  • It establishes the persistence and strategies for the recovery of the lost connections.
4. Transport Layer

The responsibilities of this layer are:
  • It manages the connection.
  • It sets up the connection to the remote machine.
  • The connections are monitored to make sure that the remote machines are live.
  • A stream is created which is accessed by the remote reference layer to send and receive data.
  • It is also responsible for handling the actual machine to machine communication.