0
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 J...
Remote Method Invocation


Java RMI is a mechanism that allows one to invoke a method on
an object that exists in another...
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 remot...
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....
Skeleton


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



All the outgoing requests are routed thr...
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 int...
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 ...
Remote Interface
import java.rmi.*;
public interface RemoteInterface extends Remote
{
double sum(double d1, double d2) thr...
Remote Class


The Remote class itself has the following properties:
1. It must implement a Remote interface.
2. It shoul...
Remote Class
import java.rmi.*;
import java.rmi.server.*;
public class RemoteClass extends UnicastRemoteObject implements
...
Distributed Programming (RMI)
Upcoming SlideShare
Loading in...5
×

Distributed Programming (RMI)

464

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
464
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
36
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Distributed Programming (RMI)"

  1. 1. Advanced Java Programming Topic: Distributed Programming (RMI) By Ravi Kant Sahu Asst. Professor, LPU
  2. 2. Remote method INVoCAtIoN (RMI) Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  3. 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. 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. 5. Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  6. 6. RMI ARchItectuRe Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  7. 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. 8. Understanding Stub and Skeleton Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  9. 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. 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. 11. Writing rMi ApplicAtions Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  12. 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. 13. Remote InteRface & class Ravi Kant Sahu, Asst. Professor @ Lovely Professional University, Punjab (India)
  14. 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. 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. 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. 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)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×