SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Downloaden Sie, um offline zu lesen
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)

Weitere ähnliche Inhalte

Was ist angesagt?

Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1Sherihan Anver
 
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 CardHari kiran G
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2Sherihan Anver
 
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İbrahim Kürce
 
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 iimjobs and hirist
 
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, constructorShivam Singhal
 
Java se 8 fundamentals
Java se 8 fundamentalsJava se 8 fundamentals
Java se 8 fundamentalsmegharajk
 
Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java ProgrammingMath-Circle
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interviewKuntal Bhowmick
 
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İbrahim Kürce
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)Ravi Kant Sahu
 
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İbrahim Kürce
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfnofakeNews
 
Lecture 3 java basics
Lecture 3 java basicsLecture 3 java basics
Lecture 3 java basicsthe_wumberlog
 
Core java lessons
Core java lessonsCore java lessons
Core java lessonsvivek shah
 

Was ist angesagt? (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
 

Andere mochten auch (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
 

Ähnlich wie Distributed Programming (RMI)

Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method InvocationPaul Pajo
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocationVeni7
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocationDew Shishir
 
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)shraddha mane
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method InvocationSonali Parab
 
#4 (Remote Method Invocation)
#4 (Remote Method Invocation)#4 (Remote Method Invocation)
#4 (Remote Method Invocation)Ghadeer AlHasan
 
Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Sonali Parab
 
Module 3 remote method invocation-2
Module 3   remote method  invocation-2Module 3   remote method  invocation-2
Module 3 remote method invocation-2Ankit Dubey
 
Javarmi 130925082348-phpapp01
Javarmi 130925082348-phpapp01Javarmi 130925082348-phpapp01
Javarmi 130925082348-phpapp01heenamithadiya
 
Remote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVARemote Method Innovation (RMI) In JAVA
Remote Method Innovation (RMI) In JAVAPrankit Mishra
 

Ähnlich wie 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
 

Kürzlich hochgeladen

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 

Kürzlich hochgeladen (20)

CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 

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)