0% found this document useful (0 votes)
4 views12 pages

Introduction to RMI

The document provides an introduction to Remote Method Invocation (RMI) in Java, explaining its purpose in enabling method invocation on remote objects across different JVMs. It details the RMI architecture, including components like the transport layer, stub, skeleton, and remote reference layer, as well as the processes of marshalling and unmarshalling. Additionally, it outlines the steps to develop an RMI application, including defining remote interfaces, implementing classes, and executing the client and server programs.

Uploaded by

sanyamdiwan0000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views12 pages

Introduction to RMI

The document provides an introduction to Remote Method Invocation (RMI) in Java, explaining its purpose in enabling method invocation on remote objects across different JVMs. It details the RMI architecture, including components like the transport layer, stub, skeleton, and remote reference layer, as well as the processes of marshalling and unmarshalling. Additionally, it outlines the steps to develop an RMI application, including defining remote interfaces, implementing classes, and executing the client and server programs.

Uploaded by

sanyamdiwan0000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Introduction to RMI

Shruti Mittal
JCBUST, YMCA
What is RMI
• RMI = Remote Method Invocation
• Enables a Java program to invoke methods on an object running in
another JVM
• Facilitates distributed computing in Java
• Built on top of TCP/IP
RMI architecture
•Transport Layer − This layer connects the
client and the server. It manages the
existing connection and also sets up new
connections.
•Stub − A stub is a representation (proxy)
of the remote object at client. It resides in
the client system; it acts as a gateway for
the client program.
•Skeleton − This is the object which resides
on the server side. stub communicates
with this skeleton to pass request to the
remote object.
•RRL(Remote Reference Layer) − It is the layer
which manages the references made by
the client to the remote object.
Working of an RMI Application

• When the client makes a call to the remote object, it is


received by the stub which eventually passes this
request to the RRL.
• When the client-side RRL receives the request, it
invokes a method called invoke() of the object remoteRef.
It passes the request to the RRL on the server side.
• The RRL on the server side passes the request to the
Skeleton (proxy on the server) which finally invokes the
required object on the server.
• The result is passed all the way back to the client.
Marshalling and Unmarshalling
• Whenever a client invokes a method that accepts
parameters on a remote object, the parameters are
bundled into a message before being sent over the
network. These parameters may be of primitive type or
objects. In case of primitive type, the parameters are
put together and a header is attached to it. In case the
parameters are objects, then they are serialized. This
process is known as marshalling.
• At the server side, the packed parameters are
unbundled and then the required method is invoked.
This process is known as unmarshalling.
RMI Registry

Each time the server creates an object, it registers


this object with the RMIregistry
(using bind() or reBind() methods). These are
registered using a unique name known as bind
name.

To invoke a remote object, the client needs a


reference of that object. At that time, the client
fetches the object from the registry using its bind
name (using lookup() method).
Steps to write an RMI Java application
• Define the remote interface
• Develop the implementation class (remote object)
• Develop the server program
• Develop the client program
• Compile the application
• Execute the application
Defining the Remote Interface
• Create an interface that extends
the predefined
interface Remote which belongs to
the package.
• Declare all the business methods
that can be invoked by the client
in this interface.
• Since there is a chance of
network issues during remote
calls, an exception
named RemoteException may
occur; throw it.
Developing the Implementation Class
(Remote Object)

• Implement the interface


created in the previous
step.
• Provide implementation
to all the abstract
methods of the remote
interface.
Developing the Server Program

• Create a client class from where you want


invoke the remote object.
• Create a remote object by instantiating the
implementation class as shown below.
• Export the remote object using the
method exportObject() of the class
named UnicastRemoteObject which belongs to the
package java.rmi.server.
• Get the RMI registry using
the getRegistry() method of the LocateRegistry class
which belongs to the package java.rmi.registry.
• Bind the remote object created to the registry
using the bind() method of the class
named Registry. To this method, pass a string
representing the bind name and the object
exported, as parameters.
Developing the Client Program
• Create a client class from where your
intended to invoke the remote object.
• Get the RMI registry using
the getRegistry() method of
the LocateRegistry class which belongs to
the package java.rmi.registry.
• Fetch the object from the registry using
the method lookup() of the
class Registry which belongs to the
package java.rmi.registry.
• To this method, you need to pass a
string value representing the bind name
as a parameter. This will return you the
remote object.
• The lookup() returns an object of type
remote, down cast it to the type Hello.
• Finally invoke the required method
using the obtained remote object.
Compiling the Application Executing the Application
1. Compile the Remote interface. 1. Start rmiregistry
2. Compile the implementation class.
2. Run the server class.
3. Compile the server program.
3. Run the client class
4. Compile the client program.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy