SlideShare une entreprise Scribd logo
1  sur  18
Télécharger pour lire hors ligne
Advanced Java Programming
Topic: Distributed Programming (RMI)

By
Ravi Kant Sahu
Asst. Professor, LPU
Remote method INVoCAtIoN
(RMI)

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Introduction


RMI is a mechanism for communicating (only) between two
machines running Java Virtual Machines.



When Java code on machine A needs a service or a method,
respectively, of (remote Java object) objB on machine B it starts
a remote method invocation.



It does this the same way as invoking a local (Java) object's
method.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Remote Method Invocation


Java RMI is a mechanism that allows one to invoke a method on
an object that exists in another address space.



The other address space could be on the same machine or a
different one.



The RMI mechanism is basically an object-oriented RPC
mechanism.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
RMI ARchItectuRe

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Remote Communication


RMI allows an object to invoke methods on an object running in
another JVM.



RMI provides remote communication between the applications
using two objects:
1. Stub
2. Skeleton



A remote object is an object whose method can be invoked from
another JVM.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Understanding Stub and Skeleton

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Stub



Stub is an object which acts as a gateway for the client side.
All the outgoing requests are routed through Stub.
It represents the remote object at the client side.



Stub performs the following tasks:




1. It initiates a connection with remote JVM.
2. It writes and transmits the parameters to remote JVM
(Marshaling).
3. It reads the returned value or exception (Unmarshaling).
4. Finally, returns the result to the Caller.
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Skeleton


Skeleton is an object which acts as a gateway for the srver side.



All the outgoing requests are routed through Stub.



Skeleton performs the following tasks:
1. It reads the parameters for the remote method.
2. It reads the parameters from caller (Unmarshaling).
3. It invokes the method on the actual remote object.
4. It writes and transmits the result to the caller (Marshaling).

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Writing rMi ApplicAtions

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Writing RMI Programs
Steps to write RMI program:
1. Create a remote Interface.
2. Provide implementation of the remote interface (Remote
class).
3. Compile the implementation class and create the stub and
skeleton objects using rmic tool (rmic remoteclass).
4. Start the registry service by rmiregistry tool (start rmiregistry).
5. Create and start the remote application.
6. Create and start the client application.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Remote InteRface & class

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Remote Class


A Remote class has two parts: the interface and the class itself.

Remote Interface:
The Remote interface must have the following properties:
1. The interface must be public.
2. The interface must extend the interface java.rmi.Remote.
3. Every method in the interface must declare that it throws
java.rmi.RemoteException. Other exceptions may also be
thrown.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Remote Interface
import java.rmi.*;
public interface RemoteInterface extends Remote
{
double sum(double d1, double d2) throws RemoteException;
}

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Remote Class


The Remote class itself has the following properties:
1. It must implement a Remote interface.
2. It should extend the java.rmi.server.UnicastRemoteObject
class.
3. It can have methods that are not in its Remote interface. These
can only be invoked locally.

Note: Objects of such a class exist in the address space of the
server and can be invoked remotely.

Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Remote Class
import java.rmi.*;
import java.rmi.server.*;
public class RemoteClass extends UnicastRemoteObject implements
RemoteInterface
{
public RemoteClass() throws RemoteException
{}
public double sum(double d1, double d2) throws RemoteException
{
return d1 + d2;
}
}
Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
Distributed Programming (RMI)

Contenu connexe

Tendances

String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)
Ravi Kant Sahu
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
nofakeNews
 
Lecture 3 java basics
Lecture 3 java basicsLecture 3 java basics
Lecture 3 java basics
the_wumberlog
 

Tendances (20)

Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2
 
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building BlocksOCA Java SE 8 Exam Chapter 1 Java Building Blocks
OCA Java SE 8 Exam Chapter 1 Java Building Blocks
 
Top 10 Java Interview Questions and Answers 2014
Top 10 Java Interview Questions and Answers 2014 Top 10 Java Interview Questions and Answers 2014
Top 10 Java Interview Questions and Answers 2014
 
java: basics, user input, data type, constructor
java:  basics, user input, data type, constructorjava:  basics, user input, data type, constructor
java: basics, user input, data type, constructor
 
Java se 8 fundamentals
Java se 8 fundamentalsJava se 8 fundamentals
Java se 8 fundamentals
 
Core java
Core javaCore java
Core java
 
Java notes
Java notesJava notes
Java notes
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
Core Java
Core JavaCore Java
Core Java
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 
Java reflection
Java reflectionJava reflection
Java reflection
 
OCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & StatementsOCA Java SE 8 Exam Chapter 2 Operators & Statements
OCA Java SE 8 Exam Chapter 2 Operators & Statements
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on java
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsOCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIs
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
 
Lecture 3 java basics
Lecture 3 java basicsLecture 3 java basics
Lecture 3 java basics
 
Core java lessons
Core java lessonsCore java lessons
Core java lessons
 

En vedette (12)

Jun 2012(1)
Jun 2012(1)Jun 2012(1)
Jun 2012(1)
 
Internationalization
InternationalizationInternationalization
Internationalization
 
Basic IO
Basic IOBasic IO
Basic IO
 
Collection framework
Collection frameworkCollection framework
Collection framework
 
Jdbc
JdbcJdbc
Jdbc
 
Questions for Class I & II
Questions for Class I & IIQuestions for Class I & II
Questions for Class I & II
 
Event handling
Event handlingEvent handling
Event handling
 
Servlets
ServletsServlets
Servlets
 
List classes
List classesList classes
List classes
 
Sms several papers
Sms several papersSms several papers
Sms several papers
 
Classes and Nested Classes in Java
Classes and Nested Classes in JavaClasses and Nested Classes in Java
Classes and Nested Classes in Java
 
Generics
GenericsGenerics
Generics
 

Similaire à Distributed Programming (RMI)

Similaire à Distributed Programming (RMI) (20)

Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
 
Java rmi tutorial
Java rmi tutorialJava rmi tutorial
Java rmi tutorial
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
 
Report on mini project(Student database handling using RMI)
Report on mini project(Student database handling using RMI)Report on mini project(Student database handling using RMI)
Report on mini project(Student database handling using RMI)
 
Oracle docs rmi applications
Oracle docs rmi applicationsOracle docs rmi applications
Oracle docs rmi applications
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
#4 (Remote Method Invocation)
#4 (Remote Method Invocation)#4 (Remote Method Invocation)
#4 (Remote Method Invocation)
 
Java RMI
Java RMIJava RMI
Java RMI
 
Rmi
RmiRmi
Rmi
 
Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)
 
Module 3 remote method invocation-2
Module 3   remote method  invocation-2Module 3   remote method  invocation-2
Module 3 remote method invocation-2
 
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
 
Basic java
Basic java Basic java
Basic java
 
Javarmi 130925082348-phpapp01
Javarmi 130925082348-phpapp01Javarmi 130925082348-phpapp01
Javarmi 130925082348-phpapp01
 
Java rmi
Java rmiJava rmi
Java rmi
 
Remote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVARemote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVA
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
 
ADB Lab Manual.docx
ADB Lab Manual.docxADB Lab Manual.docx
ADB Lab Manual.docx
 

Dernier

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

Distributed Programming (RMI)

  • 1. Advanced Java Programming Topic: Distributed Programming (RMI) By Ravi Kant Sahu Asst. Professor, LPU
  • 2. Remote method INVoCAtIoN (RMI) Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 3. Introduction  RMI is a mechanism for communicating (only) between two machines running Java Virtual Machines.  When Java code on machine A needs a service or a method, respectively, of (remote Java object) objB on machine B it starts a remote method invocation.  It does this the same way as invoking a local (Java) object's method. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 4. Remote Method Invocation  Java RMI is a mechanism that allows one to invoke a method on an object that exists in another address space.  The other address space could be on the same machine or a different one.  The RMI mechanism is basically an object-oriented RPC mechanism. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 5. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 6. RMI ARchItectuRe Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 7. Remote Communication  RMI allows an object to invoke methods on an object running in another JVM.  RMI provides remote communication between the applications using two objects: 1. Stub 2. Skeleton  A remote object is an object whose method can be invoked from another JVM. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 8. Understanding Stub and Skeleton Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 9. Stub  Stub is an object which acts as a gateway for the client side. All the outgoing requests are routed through Stub. It represents the remote object at the client side.  Stub performs the following tasks:   1. It initiates a connection with remote JVM. 2. It writes and transmits the parameters to remote JVM (Marshaling). 3. It reads the returned value or exception (Unmarshaling). 4. Finally, returns the result to the Caller. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 10. Skeleton  Skeleton is an object which acts as a gateway for the srver side.  All the outgoing requests are routed through Stub.  Skeleton performs the following tasks: 1. It reads the parameters for the remote method. 2. It reads the parameters from caller (Unmarshaling). 3. It invokes the method on the actual remote object. 4. It writes and transmits the result to the caller (Marshaling). Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 11. Writing rMi ApplicAtions Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 12. Writing RMI Programs Steps to write RMI program: 1. Create a remote Interface. 2. Provide implementation of the remote interface (Remote class). 3. Compile the implementation class and create the stub and skeleton objects using rmic tool (rmic remoteclass). 4. Start the registry service by rmiregistry tool (start rmiregistry). 5. Create and start the remote application. 6. Create and start the client application. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 13. Remote InteRface & class Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 14. Remote Class  A Remote class has two parts: the interface and the class itself. Remote Interface: The Remote interface must have the following properties: 1. The interface must be public. 2. The interface must extend the interface java.rmi.Remote. 3. Every method in the interface must declare that it throws java.rmi.RemoteException. Other exceptions may also be thrown. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 15. Remote Interface import java.rmi.*; public interface RemoteInterface extends Remote { double sum(double d1, double d2) throws RemoteException; } Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 16. Remote Class  The Remote class itself has the following properties: 1. It must implement a Remote interface. 2. It should extend the java.rmi.server.UnicastRemoteObject class. 3. It can have methods that are not in its Remote interface. These can only be invoked locally. Note: Objects of such a class exist in the address space of the server and can be invoked remotely. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  • 17. Remote Class import java.rmi.*; import java.rmi.server.*; public class RemoteClass extends UnicastRemoteObject implements RemoteInterface { public RemoteClass() throws RemoteException {} public double sum(double d1, double d2) throws RemoteException { return d1 + d2; } } Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)