SlideShare a Scribd company logo
JAVA RMI – INTRODUCTION
RMI stands for Remote Method Invocation. It is a mechanism that allows an object residing in one
systemto access/invoke anobject running on another JVM.
RMI is used to build distributedapplications; it providesremote communication between Java
programs. It is providedin the package java.rmi.
Architecture of an RMI Application
In an RMI application, we write two programs, a server programand a client program.
Inside the server program, a remote object is createdand reference of that object is made available
for the client .
The client program requeststhe remote objectson the server and tries to invoke its methods.
The following diagram shows the architecture of an RMI application.
Let us now discuss the componentsof this architecture.
Transport Layer − Thislayer connectsthe client and the server. It manages the existing connection
and
also sets up new connections.
Stub − A stub is a representationof the remote object at client. It resides in the client system; it acts
as a gateway for the client program.
JVM
residesontheserver
residesontheclient
usingtheregistry
Skeleton− This is the object which resides on the server side. stub communicateswith this skeleton
to pass request to the remote object.
RRL − It is the layer which manages the referencesmade by the client to the remote object.
Working of an RMI Application
The following points summarize how an RMI application works−
When the client makes a callto the remote object, it is receivedby the stub which eventually passes
this request to the RRL.
When the client-side RRL receivesthe request, it invokesa 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 Skeletonwhich finally invokesthe
requiredobject on the server.
The result is passed all the way back to the client.
Marshalling and Unmarshalling
Whenever a client invokesa method that acceptsparameters on a remote object, the parameters are
bundled intoa message before being sent over the network. These parameters may be of primitive
type or objects. Incase of primitive type, the parametersare put together and a header is attached to
it. In case the parameters are objects, then they are serialized. Thisprocessis known as marshalling.
At the server side, the packed parametersare unbundled and then the required method is invoked.
Thisprocessis known as unmarshalling.
RMI Registry
RMI registry is a namespace on which all server objectsare placed. Each time the server createsan
object, it registersthis object with the RMIregistry (using bind or reBind methods). These are
registeredusing 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 lookupmethod).
The following illustration explains the entire process−
RemoteReferenceLayer proxyontheserver
Goals of RMI
Following are the goals of RMI −
To minimize the complexity of the application.
To preserve type safety.
Distributed garbage collection.
Minimize the difference between working with localand remote objects.
To developan RMI Application we require the followingclasses and interfaces.
1.interface
2.Implementation class
3.Server Application
4.Client Application.
Defining Interface.
Add.java
import java.rmi.*;
public interface Addextends Remote
{
public int sum(int a,int b) throws RemoteException;
}
DefiningImplementationClass.
AddImpl.java
importjava.rmi.*;
importjava.rmi.server.*;
publicclassAddImpl extendsUnicastRemoteObjectimplementsAdd
{
publicAddImpl()throwsRemoteException
{
super();
}
publicintsum(inta,intb) throwsRemoteException
{
intc=a+b;
returnc;
}
}
ServerProgram
AddServer.java
importjava.rmi.*;
importjava.rmi.server.*;
publicclassAddServer
{
publicstaticvoidmain(Stringargs[])
{
tTry
{
Addob=newAddImpl();
Naming.rebind(“khaja”,ob);
System.out.println(“Serverready”);
}
catch(Exceptione)
{
System.out.println(e);
}
}
}
ClientProgram
AddClient.java
importjava.rmi.*;
importjava.util.*;
publicclassAddClient
{
publicstaticvoidmain(Stringargs[])
{
try
{
Addob=(Add)Naming.lookup(“khaja”);
Scannersc=newScanner(System.in);
System.out.println(“Enterthe FirstNumber“);
inta=sc.nextInt();
System.out.println(“Enterthe Second Number“);
intb=sc.nextInt();
intc=ob.sum(a,b);
System.out.println(“sum=”+c);
}
catch(Exceptione)
{
System.out.println(e);
}
}
}
CompilationandExecutionSteps
Step1:compile 4 .javafiles
Step2:create stubsandskeleton(optional fromjdk1.5)
>rmic AddImpl
Step3:startrmiregistry
>start rmiregistry
Step4:startserver
>start javaAddServer
Step5:Run Client
>javaAddClient

More Related Content

PPT
Remote method invocation
PDF
Module 3 remote method invocation-2
PPTX
Rmi architecture
PDF
Java rmi tutorial
PPSX
Java rmi
PPTX
Introduction To Rmi
PPT
Remote Method Invocation
Remote method invocation
Module 3 remote method invocation-2
Rmi architecture
Java rmi tutorial
Java rmi
Introduction To Rmi
Remote Method Invocation

What's hot (17)

PPTX
PPTX
Java RMI
PPTX
Remote Method Innovation (RMI) In JAVA
PPTX
PPS
Java rmi
PPTX
PDF
Remote Method Invocation in JAVA
PDF
Java RMI Detailed Tutorial
PPT
PPT
PPTX
Architectural Patterns - Interactive and Event Handling Patterns
DOCX
remote method invocation
PPTX
Remote Method Invocation (Java RMI)
PDF
Java rmi
PDF
Opendaylight overview
PDF
Active Object Design Pattern
PDF
Java RMI
Remote Method Innovation (RMI) In JAVA
Java rmi
Remote Method Invocation in JAVA
Java RMI Detailed Tutorial
Architectural Patterns - Interactive and Event Handling Patterns
remote method invocation
Remote Method Invocation (Java RMI)
Java rmi
Opendaylight overview
Active Object Design Pattern
Ad

Similar to Java rmi (20)

PPTX
Java RMI(Remote Method Invocation)
PPSX
Javarmi 130925082348-phpapp01
PDF
Distributed objects
DOCX
Report on mini project(Student database handling using RMI)
DOCX
Oracle docs rmi applications
PPTX
Remote method invocatiom
PDF
Remote Method Invocation
PPTX
Remote method invocation
PPT
PDF
RMI (Remote Method Invocation)
PDF
Remote Method Invocation, Advanced programming
PPTX
Remoting and serialization
PPT
A Short Java RMI Tutorial
PPT
DOCX
Remote Method Invocation
PDF
DS R16 - UNIT-3.pdf
PPTX
#4 (Remote Method Invocation)
PDF
javarmi
PPTX
Rmi presentation
PPTX
Remote Method Invocation
Java RMI(Remote Method Invocation)
Javarmi 130925082348-phpapp01
Distributed objects
Report on mini project(Student database handling using RMI)
Oracle docs rmi applications
Remote method invocatiom
Remote Method Invocation
Remote method invocation
RMI (Remote Method Invocation)
Remote Method Invocation, Advanced programming
Remoting and serialization
A Short Java RMI Tutorial
Remote Method Invocation
DS R16 - UNIT-3.pdf
#4 (Remote Method Invocation)
javarmi
Rmi presentation
Remote Method Invocation
Ad

Recently uploaded (20)

PDF
MSPs in 10 Words - Created by US MSP Network
PDF
Nidhal Samdaie CV - International Business Consultant
PPTX
ICG2025_ICG 6th steering committee 30-8-24.pptx
PDF
BsN 7th Sem Course GridNNNNNNNN CCN.pdf
PPT
340036916-American-Literature-Literary-Period-Overview.ppt
PPTX
Lecture (1)-Introduction.pptx business communication
PDF
WRN_Investor_Presentation_August 2025.pdf
DOCX
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
PDF
Types of control:Qualitative vs Quantitative
PDF
DOC-20250806-WA0002._20250806_112011_0000.pdf
PDF
Chapter 5_Foreign Exchange Market in .pdf
PDF
Power and position in leadershipDOC-20250808-WA0011..pdf
PDF
A Brief Introduction About Julia Allison
PDF
Reconciliation AND MEMORANDUM RECONCILATION
PDF
Ôn tập tiếng anh trong kinh doanh nâng cao
PDF
Outsourced Audit & Assurance in USA Why Globus Finanza is Your Trusted Choice
PPTX
Belch_12e_PPT_Ch18_Accessible_university.pptx
DOCX
Euro SEO Services 1st 3 General Updates.docx
PDF
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
PPTX
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx
MSPs in 10 Words - Created by US MSP Network
Nidhal Samdaie CV - International Business Consultant
ICG2025_ICG 6th steering committee 30-8-24.pptx
BsN 7th Sem Course GridNNNNNNNN CCN.pdf
340036916-American-Literature-Literary-Period-Overview.ppt
Lecture (1)-Introduction.pptx business communication
WRN_Investor_Presentation_August 2025.pdf
unit 2 cost accounting- Tender and Quotation & Reconciliation Statement
Types of control:Qualitative vs Quantitative
DOC-20250806-WA0002._20250806_112011_0000.pdf
Chapter 5_Foreign Exchange Market in .pdf
Power and position in leadershipDOC-20250808-WA0011..pdf
A Brief Introduction About Julia Allison
Reconciliation AND MEMORANDUM RECONCILATION
Ôn tập tiếng anh trong kinh doanh nâng cao
Outsourced Audit & Assurance in USA Why Globus Finanza is Your Trusted Choice
Belch_12e_PPT_Ch18_Accessible_university.pptx
Euro SEO Services 1st 3 General Updates.docx
Stem Cell Market Report | Trends, Growth & Forecast 2025-2034
CkgxkgxydkydyldylydlydyldlyddolydyoyyU2.pptx

Java rmi

  • 1. JAVA RMI – INTRODUCTION RMI stands for Remote Method Invocation. It is a mechanism that allows an object residing in one systemto access/invoke anobject running on another JVM. RMI is used to build distributedapplications; it providesremote communication between Java programs. It is providedin the package java.rmi. Architecture of an RMI Application In an RMI application, we write two programs, a server programand a client program. Inside the server program, a remote object is createdand reference of that object is made available for the client . The client program requeststhe remote objectson the server and tries to invoke its methods. The following diagram shows the architecture of an RMI application. Let us now discuss the componentsof this architecture. Transport Layer − Thislayer connectsthe client and the server. It manages the existing connection and also sets up new connections. Stub − A stub is a representationof the remote object at client. It resides in the client system; it acts as a gateway for the client program. JVM residesontheserver residesontheclient usingtheregistry Skeleton− This is the object which resides on the server side. stub communicateswith this skeleton to pass request to the remote object. RRL − It is the layer which manages the referencesmade by the client to the remote object.
  • 2. Working of an RMI Application The following points summarize how an RMI application works− When the client makes a callto the remote object, it is receivedby the stub which eventually passes this request to the RRL. When the client-side RRL receivesthe request, it invokesa 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 Skeletonwhich finally invokesthe requiredobject on the server. The result is passed all the way back to the client. Marshalling and Unmarshalling Whenever a client invokesa method that acceptsparameters on a remote object, the parameters are bundled intoa message before being sent over the network. These parameters may be of primitive type or objects. Incase of primitive type, the parametersare put together and a header is attached to it. In case the parameters are objects, then they are serialized. Thisprocessis known as marshalling. At the server side, the packed parametersare unbundled and then the required method is invoked. Thisprocessis known as unmarshalling. RMI Registry RMI registry is a namespace on which all server objectsare placed. Each time the server createsan object, it registersthis object with the RMIregistry (using bind or reBind methods). These are registeredusing 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 lookupmethod). The following illustration explains the entire process− RemoteReferenceLayer proxyontheserver Goals of RMI Following are the goals of RMI − To minimize the complexity of the application. To preserve type safety. Distributed garbage collection. Minimize the difference between working with localand remote objects. To developan RMI Application we require the followingclasses and interfaces. 1.interface 2.Implementation class 3.Server Application 4.Client Application. Defining Interface. Add.java import java.rmi.*; public interface Addextends Remote { public int sum(int a,int b) throws RemoteException; }
  • 4. ClientProgram AddClient.java importjava.rmi.*; importjava.util.*; publicclassAddClient { publicstaticvoidmain(Stringargs[]) { try { Addob=(Add)Naming.lookup(“khaja”); Scannersc=newScanner(System.in); System.out.println(“Enterthe FirstNumber“); inta=sc.nextInt(); System.out.println(“Enterthe Second Number“); intb=sc.nextInt(); intc=ob.sum(a,b); System.out.println(“sum=”+c); } catch(Exceptione) { System.out.println(e); } } } CompilationandExecutionSteps Step1:compile 4 .javafiles Step2:create stubsandskeleton(optional fromjdk1.5) >rmic AddImpl Step3:startrmiregistry >start rmiregistry Step4:startserver >start javaAddServer Step5:Run Client >javaAddClient