Remote method invocation

Remote method invocation is an API. It allows an object to invoke a method on an object that located in another address space. It could be on same computer or a remote computer. RMI is used to build distributed applications. It provides remote communication between two programs. In RMI application, there will be two programs; server program and client program.

Inside server program, remote object is created and reference of that object is made available for client. Client program requests remote objects on server and tries to invoke its method.

Architecture of RMI application

Architecture of RMI application
Architecture of RMI application

Transport layer connects client and server. It manages the existing connection and also sets new connections.

Stub is representation of remote object at client. It exists on client system; it acts as a gateway for client program. All outgoing requests are routed through it. When caller invokes method on the stub object following tasks will be done.

  1. Initialize connection with remote virtual machine

Skeleton is object which exists on server side. Stub communicates with skeleton to pass request to the remote object. When skeleton receives incoming request, following tasks will be done.

  1. Reads parameter for remote method

RRL manages the references made by the client to the remote object.

Work fellow in RMI application

  1. When client makes call to remote object, it is received by the stub which eventually passes this request to RRL.

Goals of RMI are Minimize complexity of application, Preserve type safety, Distributed garbage collection and Minimize difference between working with local and remote objects.

Lets look a simple example of Java RMI example.

create the remote interface

Provide the implementation of the remote interface

Create the stub and skeleton objects using the rmic tool

rmic AdderRemote

Start the registry service by the rmiregistry tool

rmiregistry 5000

Create and run the server application

Create and run the client application



Software Engineer