Remote method invocation


Published on

It's a presentation on Java Remote Method Invocation.

Published in: Technology, Education
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Slide dekhebolleihobe
  • Remote method invocation

    2. 2. Overview  Introduction of RMI  Uses of RMI  Interfaces and Classes  RMI Architecture  RMI Application Overview  Remote Object and Interface Explained  A short demonstration of RMI application
    3. 3. What is RMI?  Remote Method Invocation (RMI), allows one host to run programs on another host that is running a program on a remote host from a local machine. In Brief:  It’s a core JAVA API  Enables programs calling methods in objects running on different host even though both program exists in two physically different hosts.
    4. 4. Why We Need RMI? Let’s think a scenario -  Suppose you’re an owner of a large company. You’re company have branches all over the country.  Now if one of your company branch need to get services/data from head office, how they’ll do it? Answer is : RMI We’ll show you how that work and what it does
    5. 5. Interface and Classes in Package java.rmi RemoteObject RemoteServer Activatable UnicastRemoteobject Remote Interface Classes
    6. 6. RMI Architecture  The server must first bind its name to the registry  The client lookup the server name in the registry to establish remote references.  The Stub serializing the parameters to skeleton, the skeleton invoking the remote method and serializing the result back to the stub.
    7. 7. The Stubs and Skeleton RMI Client Stubs Skeleton RMI Server Call Return  A client invokes a remote method, the call is first forwarded to stub.  The stub is responsible for sending the remote call over to the serverside skeleton  The stub opening a socket to the remote server, marshaling the object parameters and forwarding the data stream to the skeleton.  A skeleton contains a method that receives the remote calls, unmarshals the parameters, and invokes the actual remote object implementation.
    8. 8. RMI Application Overview  RMI applications consist of two separate programs, a server and a client.  Server program creates some remote objects, makes references to these objects accessible, and waits for clients to invoke methods on these objects.  Client program obtains a remote reference to one or more remote objects on a server and then invokes methods on them.
    9. 9. Remote Object  An object with methods that may be invoked from a different Java virtual machine than the one running on a different computer.  Each remote object implements one or more remote interfaces that declare which methods of the remote object can be invoked by the foreign system.
    10. 10. Remote interfaces, Objects and Methods Remote Object  Objects with methods that can be invoked across Java virtual machines are called remote objects  Remote Object implements Remote Interface  A Remote Interface extends java.rmi.Remote interface  Each method of the interface declares java.rmi.RemoteException in its throws clause
    11. 11. Remote Interface Explained  Let’s take a sample code snippet import java.rmi.*; public interface HomeWork extends Remote { public String giveMeYourHomeWork( ) throws RemoteException; }
    12. 12. Remote Interface Explained (cont…)  Java program running on your workstation (e.g. JVM on could look up the current HomeWork object in the RMI registry at remote virtual machine (e.g. JVM on  The registry would send it a reference to the object running in remote ( 's) virtual machine.  Your program could then use this reference to invoke the giveMeYourHomeWork( ) method.  The giveMeYourHomeWork( ) method would execute on the server in remote machine not on your local machine. However, it would return the String value back to your local program running in your local machine.
    13. 13. A Short RMI Example  What this program does?  This is a simple program which pass two integers to Server through RMI and invoke remote method from Client to calculate their Sum.  There are 3 classes and 1 interface  SumInterface  SumImpl  RMIServer  RMIClient
    14. 14.
    15. 15.
    16. 16.
    17. 17.
    18. 18. Compiling and Running from Terminal Compiling … After compiling following classes are generated …
    19. 19. Generating Stubs and Starting RMI Registry Generating Stubs and Starting RMI Registry … After generating Stubs directory looks like …
    20. 20. Starting Server and Client Open a new Terminal and start the server … Open another new Terminal and start the Client … (You’ll get result immediately)
    21. 21. References  varmi.html  /spec/rmi-arch2.html  _invocation  package-summary.html