SlideShare a Scribd company logo
1 of 22
Download to read offline
Remote Method Invocation

  Based on Notes by D. Hollinger
 Also based on Sun’s Online Java
             Tutorial

        Netprog 2002 Java RMI      1
Network Programming
          Paradigms
• Sockets programming: design a
  protocol first, then implement clients
  and servers that support the protocol.
• RMI: Develop an application, then
  (statically) move some objects to
  remote machines.
  – Not concerned with the details of the actual
    communication between processes –
    everything is just method calls.
             Netprog 2002 Java RMI             2
Call Semantics
• Method Call Semantics – what does it mean
  to make a call to a method?
  – How many times is the method run?
  – How do we know the method ran at all?
• RMI does a great job of providing natural call
  semantics for remote objects/methods.
  – Simply a few additional Exceptions that you need
    to handle.
  – Objects implementing the Remote interface are
    passed by reference. Non-remote (serializable)
    objects and primitive types are passed by value.
              Netprog 2002 Java RMI                    3
Finding Remote Objects
• It would be awkward if we needed to include
  a hostname, port and protocol with every
  remote method invocation.
• RMI provides a Naming Service through the
  RMI Registry that simplifies how programs
  specify the location of remote objects.
  – This naming service is a JDK utility called
    rmiregistry that runs at a well known address
    (by default).

             Netprog 2002 Java RMI                  4
RMI Adds a few layers


   Client App.                         Server App.

     Stubs                               Skeleton

Remote Reference                     Remote Reference

   Transport                            Transport




             Netprog 2002 Java RMI                      5
Remote Object References
• The client acquires a reference to a remote
  object.
  – This part is different from creating a local object.


• The client calls methods on the remote object
  – No (syntactic) difference!
  – Just need to worry about a few new exceptions.




               Netprog 2002 Java RMI                       6
Overview of RMI
             Programming
• Define an interface that declares the methods that
  will be available remotely.
• The server program must include a class that
  implements this interface.
• The server program must create a remote object and
  register it with the naming service.

• The client program creates a remote object by asking
  the naming service for an object reference.


               Netprog 2002 Java RMI                   7
Java Interfaces
• Similar to Class
• No implementation! All methods are
  abstract (virtual for C++ folks).
• Everything is public.
• No fields defined, just Methods.
• No constructor
• an Interface is an API that can be
  implemented by a Class.
           Netprog 2002 Java RMI       8
Interfaces and Inheritance
• In Java a class can only extend a single
  superclass (single inheritance).
• A class can implement any number of
  interfaces.
  – end result is very similar to multiple
    inheritance.



             Netprog 2002 Java RMI           9
Sample Interface
public interface Shape {
  public double getArea();
  public void draw();
  public void fill(Color c);
}




          Netprog 2002 Java RMI   10
Implementing an Interface
public class Circle implements Shape {
     private double radius;
     private Point center;

     // define a constructor and other
     // methods

     // MUST define the methods:
     //   getArea();
     //   draw();
     //   fill(Color c);
}

            Netprog 2002 Java RMI        11
Server Details – extending
           Remote
• Create an interface the extends the
  java.rmi.Remote interface.
  – This new interface includes all the public methods
    that will be available as remote methods.

import java.rmi.*;
public interface MyRemote extends Remote {
  public int foo(int x) throws RemoteException;
  public String blah(int y) throws RemoteException;
  . . .
}

              Netprog 2002 Java RMI                  12
How the interface will be used
Remote Interface                       RemoteServer Class
                         provides methods
   extends               needed by          extends

 Your Interface                       UnicastRemoteObject
 implements
                                            extends

              Class implementing
              your remote service


              Netprog 2002 Java RMI                    13
Server Details –
           Implementation Class
• Create a class that implements the
  interface.
  – The class should extend UnicastRemoteObject*
• This class needs a constructor that throws
  RemoteException !
• This class is now used by rmic to create
  the stub and skeleton code.
 *It doesn’t have to extend UnicastRemoteObject, there is another way…

                      Netprog 2002 Java RMI                              14
Remote Object Implementation Class
public class MyRemoteImpl extends
  UnicastRemoteObject implements MyRemote {

     public MyRemoteImpl() throws RemoteException
      {}

     public int foo(int x) {
       return(x+1);
     }
     public String blah(int y) {
       return(“Your number is “ + y);
     }
}
               Netprog 2002 Java RMI          15
Generating stubs and skeleton
• Compile the remote interface and
  implementation:

> javac MyRemote.java MyRemoteImpl.java


• Use rmic to generate MyRemoteImpl_stub.class,
  MyRemoteImpl_skel.class

> rmic MyRemoteImpl


              Netprog 2002 Java RMI               16
Server Detail – main()
• The server main() needs to:
  – create a remote object.
  – register the object with the Naming service.

public static void main(String args[]) {
  try {
     MyRemoteImpl r = new MyRemoteImpl();
     Naming.bind(“joe”,r);
  } catch (RemoteException e) {
     . . .

             Netprog 2002 Java RMI            17
Client Details
• The client needs to ask the naming service
  for a reference to a remote object.
  – The client needs to know the hostname or IP
    address of the machine running the server.
  – The client needs to know the name of the remote
    object.
• The naming service uses URIs to identify
  remote objects.


              Netprog 2002 Java RMI                   18
Using The Naming service
• Naming.lookup() method takes a string
  parameter that holds a URI indicating the
  remote object to lookup.
      rmi://hostname/objectname

• Naming.lookup() returns an Object!
• Naming.lookup() can throw
   – RemoteException
   – MalformedURLException
             Netprog 2002 Java RMI            19
Getting a Remote Object
try {
  Object o =
  Naming.lookup(“rmi://monica.cs.rpi.edu/joe”);

  MyRemote r = (MyRemote) o;
  // . . . Use r like any other Java object!
} catch (RemoteException re) {
  . . .
} catch (MalformedURLException up) {
   throw up;
}


             Netprog 2002 Java RMI         20
Starting the Server
• First you need to run the Naming
  service server:
     rmiregistry
• Now run the server:
    java MyRemoteImpl



           Netprog 2002 Java RMI     21
Sample Code
• There is sample RMI code on the
  course homepage:
  – BankAccount: remote access to a bank
    account
  – SimpleRMI: remote integer arithmetic
  – AlternativeSimpleRMI: Implementation
    class doesn’t extend UnicastRemoteObject
  – RemoteSort: remote sort server – uses
    Java List objects
            Netprog 2002 Java RMI          22

More Related Content

What's hot

Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMIbackdoor
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocationashishspace
 
Core Java Certification
Core Java CertificationCore Java Certification
Core Java CertificationVskills
 
Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and BytecodeYoav Avrahami
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with codekamal kotecha
 
Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924yohanbeschi
 
Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMashleypuls
 
Distributes objects and Rmi
Distributes objects and RmiDistributes objects and Rmi
Distributes objects and RmiMayank Jain
 
C++ programming with jni
C++ programming with jniC++ programming with jni
C++ programming with jniPeter Hagemeyer
 
Effective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjectsEffective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjectsSrikanth Shenoy
 
No locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureNo locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureAndrew Petukhov
 

What's hot (20)

Distributed Programming using RMI
Distributed Programming using RMIDistributed Programming using RMI
Distributed Programming using RMI
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Java RMI
Java RMIJava RMI
Java RMI
 
Core Java Certification
Core Java CertificationCore Java Certification
Core Java Certification
 
Rmi
RmiRmi
Rmi
 
Playing with Java Classes and Bytecode
Playing with Java Classes and BytecodePlaying with Java Classes and Bytecode
Playing with Java Classes and Bytecode
 
Invoke dynamics
Invoke dynamicsInvoke dynamics
Invoke dynamics
 
Java rmi example program with code
Java rmi example program with codeJava rmi example program with code
Java rmi example program with code
 
Rmi presentation
Rmi presentationRmi presentation
Rmi presentation
 
Java rmi tutorial
Java rmi tutorialJava rmi tutorial
Java rmi tutorial
 
Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924
 
Rmi ppt
Rmi pptRmi ppt
Rmi ppt
 
Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASM
 
learn design
learn designlearn design
learn design
 
Distributes objects and Rmi
Distributes objects and RmiDistributes objects and Rmi
Distributes objects and Rmi
 
C++ programming with jni
C++ programming with jniC++ programming with jni
C++ programming with jni
 
Introduction To Rmi
Introduction To RmiIntroduction To Rmi
Introduction To Rmi
 
Effective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjectsEffective JavaFX architecture with FxObjects
Effective JavaFX architecture with FxObjects
 
No locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureNo locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructure
 
What is Java? Presentation On Introduction To Core Java By PSK Technologies
What is Java? Presentation On Introduction To Core Java By PSK TechnologiesWhat is Java? Presentation On Introduction To Core Java By PSK Technologies
What is Java? Presentation On Introduction To Core Java By PSK Technologies
 

Viewers also liked

Remote method invocation (as part of the the PTT lecture)
Remote method invocation (as part of the the PTT lecture)Remote method invocation (as part of the the PTT lecture)
Remote method invocation (as part of the the PTT lecture)Ralf Laemmel
 
Inter-Process communication using pipe in FPGA based adaptive communication
Inter-Process communication using pipe in FPGA based adaptive communicationInter-Process communication using pipe in FPGA based adaptive communication
Inter-Process communication using pipe in FPGA based adaptive communicationMayur Shah
 
Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)Abdelrahman Al-Ogail
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure callSunita Sahu
 
Introduction to Remote Method Invocation (RMI)
Introduction to Remote Method Invocation (RMI)Introduction to Remote Method Invocation (RMI)
Introduction to Remote Method Invocation (RMI)eLink Business Innovations
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Peter R. Egli
 
Chapter 4 a interprocess communication
Chapter 4 a interprocess communicationChapter 4 a interprocess communication
Chapter 4 a interprocess communicationAbDul ThaYyal
 
Java RMI Presentation
Java RMI PresentationJava RMI Presentation
Java RMI PresentationMasud Rahman
 
remote procedure calls
  remote procedure calls  remote procedure calls
remote procedure callsAshish Kumar
 
Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...
Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...
Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...Varun Patel
 
Java - Remote method invocation
Java - Remote method invocationJava - Remote method invocation
Java - Remote method invocationRiccardo Cardin
 

Viewers also liked (17)

IPC SOCKET
IPC SOCKETIPC SOCKET
IPC SOCKET
 
Remote method invocation (as part of the the PTT lecture)
Remote method invocation (as part of the the PTT lecture)Remote method invocation (as part of the the PTT lecture)
Remote method invocation (as part of the the PTT lecture)
 
Inter-Process communication using pipe in FPGA based adaptive communication
Inter-Process communication using pipe in FPGA based adaptive communicationInter-Process communication using pipe in FPGA based adaptive communication
Inter-Process communication using pipe in FPGA based adaptive communication
 
Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)Introduction to C++ Remote Procedure Call (RPC)
Introduction to C++ Remote Procedure Call (RPC)
 
Java rmi
Java rmiJava rmi
Java rmi
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure call
 
RMI
RMIRMI
RMI
 
Introduction to Remote Method Invocation (RMI)
Introduction to Remote Method Invocation (RMI)Introduction to Remote Method Invocation (RMI)
Introduction to Remote Method Invocation (RMI)
 
Java rmi
Java rmiJava rmi
Java rmi
 
Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)
 
Chapter 4 a interprocess communication
Chapter 4 a interprocess communicationChapter 4 a interprocess communication
Chapter 4 a interprocess communication
 
Java RMI Presentation
Java RMI PresentationJava RMI Presentation
Java RMI Presentation
 
Network Sockets
Network SocketsNetwork Sockets
Network Sockets
 
remote procedure calls
  remote procedure calls  remote procedure calls
remote procedure calls
 
Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...
Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...
Piping Training course-How to be an Expert in Pipe & Fittings for Oil & Gas c...
 
Java - Remote method invocation
Java - Remote method invocationJava - Remote method invocation
Java - Remote method invocation
 

Similar to Remote Method Invocation

Similar to Remote Method Invocation (20)

17rmi
17rmi17rmi
17rmi
 
Rmi
RmiRmi
Rmi
 
Remote method invocatiom
Remote method invocatiomRemote method invocatiom
Remote method invocatiom
 
Rmi3
Rmi3Rmi3
Rmi3
 
Remote Method Invocation
Remote Method InvocationRemote Method Invocation
Remote Method Invocation
 
Rmi
RmiRmi
Rmi
 
Remote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programmingRemote Method Invocation, Advanced programming
Remote Method Invocation, Advanced programming
 
ADB Lab Manual.docx
ADB Lab Manual.docxADB Lab Manual.docx
ADB Lab Manual.docx
 
Remote Method Invocation in JAVA
Remote Method Invocation in JAVARemote Method Invocation in JAVA
Remote Method Invocation in JAVA
 
DS
DSDS
DS
 
Remote method invocation
Remote method invocationRemote method invocation
Remote method invocation
 
Distributed Programming using RMI
 Distributed Programming using RMI Distributed Programming using RMI
Distributed Programming using RMI
 
Rmi
RmiRmi
Rmi
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
 
JRuby - Enterprise 2.0
JRuby - Enterprise 2.0JRuby - Enterprise 2.0
JRuby - Enterprise 2.0
 
Java RMI
Java RMIJava RMI
Java RMI
 
#4 (Remote Method Invocation)
#4 (Remote Method Invocation)#4 (Remote Method Invocation)
#4 (Remote Method Invocation)
 
Distributed Objects and JAVA
Distributed Objects and JAVADistributed Objects and JAVA
Distributed Objects and JAVA
 
CORBA & RMI in java
CORBA & RMI in javaCORBA & RMI in java
CORBA & RMI in java
 
A Short Java RMI Tutorial
A Short Java RMI TutorialA Short Java RMI Tutorial
A Short Java RMI Tutorial
 

More from elliando dias

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slideselliando dias
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScriptelliando dias
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structureselliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de containerelliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agilityelliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Librarieselliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Webelliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduinoelliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorceryelliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Designelliando dias
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makeselliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebookelliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Studyelliando dias
 

More from elliando dias (20)

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
 
Geometria Projetiva
Geometria ProjetivaGeometria Projetiva
Geometria Projetiva
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
 
Ragel talk
Ragel talkRagel talk
Ragel talk
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
 
Minicurso arduino
Minicurso arduinoMinicurso arduino
Minicurso arduino
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
 
Rango
RangoRango
Rango
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
 

Recently uploaded

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
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 WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
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 WorkerThousandEyes
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
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
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Remote Method Invocation

  • 1. Remote Method Invocation Based on Notes by D. Hollinger Also based on Sun’s Online Java Tutorial Netprog 2002 Java RMI 1
  • 2. Network Programming Paradigms • Sockets programming: design a protocol first, then implement clients and servers that support the protocol. • RMI: Develop an application, then (statically) move some objects to remote machines. – Not concerned with the details of the actual communication between processes – everything is just method calls. Netprog 2002 Java RMI 2
  • 3. Call Semantics • Method Call Semantics – what does it mean to make a call to a method? – How many times is the method run? – How do we know the method ran at all? • RMI does a great job of providing natural call semantics for remote objects/methods. – Simply a few additional Exceptions that you need to handle. – Objects implementing the Remote interface are passed by reference. Non-remote (serializable) objects and primitive types are passed by value. Netprog 2002 Java RMI 3
  • 4. Finding Remote Objects • It would be awkward if we needed to include a hostname, port and protocol with every remote method invocation. • RMI provides a Naming Service through the RMI Registry that simplifies how programs specify the location of remote objects. – This naming service is a JDK utility called rmiregistry that runs at a well known address (by default). Netprog 2002 Java RMI 4
  • 5. RMI Adds a few layers Client App. Server App. Stubs Skeleton Remote Reference Remote Reference Transport Transport Netprog 2002 Java RMI 5
  • 6. Remote Object References • The client acquires a reference to a remote object. – This part is different from creating a local object. • The client calls methods on the remote object – No (syntactic) difference! – Just need to worry about a few new exceptions. Netprog 2002 Java RMI 6
  • 7. Overview of RMI Programming • Define an interface that declares the methods that will be available remotely. • The server program must include a class that implements this interface. • The server program must create a remote object and register it with the naming service. • The client program creates a remote object by asking the naming service for an object reference. Netprog 2002 Java RMI 7
  • 8. Java Interfaces • Similar to Class • No implementation! All methods are abstract (virtual for C++ folks). • Everything is public. • No fields defined, just Methods. • No constructor • an Interface is an API that can be implemented by a Class. Netprog 2002 Java RMI 8
  • 9. Interfaces and Inheritance • In Java a class can only extend a single superclass (single inheritance). • A class can implement any number of interfaces. – end result is very similar to multiple inheritance. Netprog 2002 Java RMI 9
  • 10. Sample Interface public interface Shape { public double getArea(); public void draw(); public void fill(Color c); } Netprog 2002 Java RMI 10
  • 11. Implementing an Interface public class Circle implements Shape { private double radius; private Point center; // define a constructor and other // methods // MUST define the methods: // getArea(); // draw(); // fill(Color c); } Netprog 2002 Java RMI 11
  • 12. Server Details – extending Remote • Create an interface the extends the java.rmi.Remote interface. – This new interface includes all the public methods that will be available as remote methods. import java.rmi.*; public interface MyRemote extends Remote { public int foo(int x) throws RemoteException; public String blah(int y) throws RemoteException; . . . } Netprog 2002 Java RMI 12
  • 13. How the interface will be used Remote Interface RemoteServer Class provides methods extends needed by extends Your Interface UnicastRemoteObject implements extends Class implementing your remote service Netprog 2002 Java RMI 13
  • 14. Server Details – Implementation Class • Create a class that implements the interface. – The class should extend UnicastRemoteObject* • This class needs a constructor that throws RemoteException ! • This class is now used by rmic to create the stub and skeleton code. *It doesn’t have to extend UnicastRemoteObject, there is another way… Netprog 2002 Java RMI 14
  • 15. Remote Object Implementation Class public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote { public MyRemoteImpl() throws RemoteException {} public int foo(int x) { return(x+1); } public String blah(int y) { return(“Your number is “ + y); } } Netprog 2002 Java RMI 15
  • 16. Generating stubs and skeleton • Compile the remote interface and implementation: > javac MyRemote.java MyRemoteImpl.java • Use rmic to generate MyRemoteImpl_stub.class, MyRemoteImpl_skel.class > rmic MyRemoteImpl Netprog 2002 Java RMI 16
  • 17. Server Detail – main() • The server main() needs to: – create a remote object. – register the object with the Naming service. public static void main(String args[]) { try { MyRemoteImpl r = new MyRemoteImpl(); Naming.bind(“joe”,r); } catch (RemoteException e) { . . . Netprog 2002 Java RMI 17
  • 18. Client Details • The client needs to ask the naming service for a reference to a remote object. – The client needs to know the hostname or IP address of the machine running the server. – The client needs to know the name of the remote object. • The naming service uses URIs to identify remote objects. Netprog 2002 Java RMI 18
  • 19. Using The Naming service • Naming.lookup() method takes a string parameter that holds a URI indicating the remote object to lookup. rmi://hostname/objectname • Naming.lookup() returns an Object! • Naming.lookup() can throw – RemoteException – MalformedURLException Netprog 2002 Java RMI 19
  • 20. Getting a Remote Object try { Object o = Naming.lookup(“rmi://monica.cs.rpi.edu/joe”); MyRemote r = (MyRemote) o; // . . . Use r like any other Java object! } catch (RemoteException re) { . . . } catch (MalformedURLException up) { throw up; } Netprog 2002 Java RMI 20
  • 21. Starting the Server • First you need to run the Naming service server: rmiregistry • Now run the server: java MyRemoteImpl Netprog 2002 Java RMI 21
  • 22. Sample Code • There is sample RMI code on the course homepage: – BankAccount: remote access to a bank account – SimpleRMI: remote integer arithmetic – AlternativeSimpleRMI: Implementation class doesn’t extend UnicastRemoteObject – RemoteSort: remote sort server – uses Java List objects Netprog 2002 Java RMI 22