Remote Method Invocation Architecture

Divya Bandara
4 min readJul 16, 2020

RMI architecture

What is this RMI architecture?

Remote Method Invocation is an API provided by Java. The RMI architecture is used to communicate between two different remote or different applications. By using the RMI architecture, it is able for an object in one Java Virtual Machine to access an object running on another Java Virtual Machine. This architecture allows users to communicate directly across the platforms and the code can be execute on the remote JVM s and most of the existing systems can adapt because this technology is available from JDK 1.02.

A main disadvantage of RMI architecture is it can be used only on java supported platforms.

Above figure shows the RMI architecture. Following are described details about the RMI architecture shown above.

Client and Server Applications: JVMs of client and server machines are mentioned as client application and server application.

Stub: Client object- an object with is acting as a gateway for the client program which located in the client machine. A proxy to the remote object.

Functions of the stub

· Initiates the connection with remote JVM

· Passing parameters to the remote JVM

· Waiting for the result

· Reads the result

· Pass the result to the caller

Skeleton: Server object- — an object with is acting as a gateway for the server program which located in the server machine.

Functions of the skeleton

· Read the parameter getting from the client

· Pass the result to caller

Remote Reference Layer: Stub and skeleton are connected to the remote reference layer for communication and transfer objects in-between client and server machines.

Transport Layer: Responsible for setting up communication using TCP/IP protocol.

Following is a java RMI example

At first, we have to create 3 java files. One interface file and two java class files. Naming,

· RMIInterface.java

· ServerOperation.java

· ClientOperation.java

Following class files are generated in the process of compilation.

· ClientOperation.class

· RMIInterface.class

· ServerOperation.class

RMIInterface.java — interface

First, we design remote interface which implements both client and server. This designing interface should be both public and extend Remote.

The Remote interface consists only one method which receives string parameter and returns a string.

ServerOperation.java — class

The server implements the created interface and it extends UniCastRemoteObject.

We bind the server on localhost using the name “MyServer” inside the main method.

ClientOperation.java — class

Finally, the Client is created to find the Server. The Client uses an RMIInterface Object that “looks” To invoke a remote object, the client needs a reference of that object to “find” the Server. That time, the client fetches the object from the registry using its bind name (using lookup() method). Server and receive responses could be called with that RMIInterface.

Then we are going to run the application. For that we have to go the location of our project and open the source file which contains our created 3 java files.

Select on the address bar and type cmd to get the relevant command prompt.

Then the command prompt will appear.

Now you we have to compile the 3 java files using command prompt. It will see as the following figure.

After the compilation, the folder will be displayed as follows with the created class files.

Then we start the rmiregistry. If the rmiregistry started successfully, it will open a new command window.

Now we are ready to run the client by opening a new command prompt window.

When the ClientOperation runs it asks us for an input.

Once we input the text, the server side show the text “Divya is trying to contact!” and client side shows the “Server says hello to Divya”.

--

--