Remote Method Invocation

Sitharanishadini
3 min readJul 18, 2020

--

In my last blog I wrote about RPC. This is about Remote Method Invocation, shortly called RMI which an API we use to create distributed systems in java invoking methods of an object (remote object) which is running on another Java Virtual Machine (JVM). This could be on same machine or on a remote machine. Simply RMI is the Java version of what we known as a remote procedure call (RPC), but it has the ability to pass one or more objects along with the request.

What really happens?

  • 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.

RMI uses stub and skeleton object for communication with the remote object.

Stub

Stub is the gateway for client side objects. Requests from the client side to the server side are sent through the stub in the client side. This builds an information block inside the client and send it to the server side.

This information block contains following elements.

  • An identifier of the remote object to be used
  • Method name which is to be invoked
  • Parameters to the remote JVM

what stub does?

  1. First it initiate the connection with the remote JVM which it needs to communicate.
  2. Then it marshalls the message that contains parameters and send it to the remote JVM.
  3. It waits until the remote JVM send the result.
  4. After receiving the result stub unmarshalls it and send it to the caller.

Skeleton

This is same as the stub, but it works in the server side. So the Skeleton is the gateway for server side objects.

  1. Receive the requests from client.
  2. Then reads the parameters sent to invoke the relevant method.
  3. After getting a result then the result is sent to the caller after marshalling.

By using RMI we can obtain type safety and minimize the complexities of applications.

The remote interface

A remote interface provides the description of all the methods of a particular remote object. The client communicates with this remote interface.

Server Application

Client Application

Execute!

Thank you!

--

--

Sitharanishadini
Sitharanishadini

Written by Sitharanishadini

Explore the world. You will always find new things to learn.

No responses yet