Advanced Java Programming - Old Questions

12. What is RMI? Discuss architecture of RMI.

5 marks | Asked in 2073

Remote Method Invocation (RMI) is a mechanism that allows an object running in one java virtual machine (JVM) to invoke methods on an object running in another java virtual machine (JVM). It provides remote communication between java programs. Objects with methods that can be invoked across JVMs are called remote objects. The remote object is called the server object.

Architecture of RMI

In an RMI application, we write two programs, a server program (resides on the server) and a client program (resides on the client).

  • Inside the server program, a remote object is created and reference of that object is made available for the client (using the registry).
  • The client program requests the remote objects on the server and tries to invoke its methods.

The RMI architecture consists of four layers:

1. Application Layer: This layer is the actual systems i.e. client and server which are involved in communication. The java program on the client side communicates with the java program on the server-side.

2. Proxy Layer: This layer contains the client stub and server skeleton objects.

  • Stub is an object that resides on the client machine and it acts as a proxy for the remote object. It is like a gateway for the client program. When the client calls on the stub object, the stub forwards this request to a remote object (Skeleton) via RMI infrastructure which is then executed on the server.
  • The server object which resides in a server machine is known as Skeleton. Stub communicates with server application with the help of an intermediate Skeleton object. The responsibility of the skeleton object is to send parameters to method implementation and send the return values back to the client.

3. Remote Reference Layer: This layer is responsible to maintain the session during the method call. i.e. It manages the references made by the client to the remote server object. This layer is also responsible for handling duplicated objects. The invocation semantics of the RMI connection is defined and supported by this layer.

4. Transport Layer: The transport layer is responsible for setting up communication between the two machines. This layer uses standard TCP/IP protocol for connection. The actual transportation of data is performed through this layer.