RMI - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

RMI

Description:

RMI Varun Saini Ying Chen . What is RPC? 2.RMI is a means to do RPC. 3 Comparison with Other RPC Mechanisms and CORBA. 3.1 Stubs and Skeletons e.g. Simple Example. – PowerPoint PPT presentation

Number of Views:50
Avg rating:3.0/5.0
Slides: 17
Provided by: vsa9
Category:
Tags: rmi

less

Transcript and Presenter's Notes

Title: RMI


1
RMI
Varun Saini
Ying Chen
2
What is RMI?
  • RMI is the action of invoking a method of a
    remote interface on a remote object.
  • It is used to develop applications that
    communicate between virtual machines
  • RMI is a means of doing distributed computing
  • RMI hides the underlying mechanism of
    transporting method arguments and return values
    across the network.

3
Example
  • Server returns sum of two numbers
  • Client calls the add() method of the server and
    passes two numbers
  • We will need four files
  • AddServerIntf.java
  • AddServerImpl.java
  • AddServer.java
  • AddClient.java

Java Complete Reference-Schildt Naughton
4
Remote Interface
  • a remote interface is an interface that declares
    a set of methods that may be invoked from a
    remote Java virtual machine.
  • Must extend java.rmi.Remote
  • The interface java.rmi.Remote is a marker
    interface that defines no methods
  • public interface Remote
  • All methods must throw RemoteException

5
AddServerIntf.java
  • import java.rmi.
  • public interface AddServerIntf extends Remote
  • double add (double d1, double d2)
  • throws RemoteException

6
RMI Registry
  • Simple Name Repository
  • Server binds a name with an object implementation
  • Client can query the registry for checking the
    availability of a server object

7
AddServerImpl.java
  • import java.rmi.
  • import java.rmi.server.
  • public class AddServerImpl extends
    UnicastRemoteObject implements AddServerIntf
  • public AddServerImpl() throws RemoteException
  • public double add (double d1, double d2)
  • throws RemoteException
  • return d1d2

8
Parameter Passing
  • Passing by Copy
  • Local objects and exceptions are passed by copy.
  • Use JAVA object serialization
  • Passing by Reference
  • Remote Object Passed by reference

9
AddServer.java
  • import java.rmi.
  • public class AddServer
  • public static void main(String args)
  • try
  • AddServerImpl addServerImplnew
    AddServerImpl()
  • Naming.rebind("AddServer",addServerImpl)
  • catch(Exception e)System.out.printl
    n(e)

10
AddClient.java
  • import java.rmi.
  • public class AddClient
  • public static void main(String args)
  • try
  • String addServerURL "rmi//"args0"/A
    ddServer"
  • AddServerIntf addServerIntf
  • (AddServerIntf)Naming.lookup(addServerU
    RL)
  • double d1Double.valueOf(args1).doubleValue(
    )
  • double d2Double.valueOf(args2).doubleValue(
    )
  • System.out.println("Sum "addServerIntf.add(d
    1,d2))
  • catch(Exception e)System.out.println(e)

11
Stubs and Skeletons
  • Stub
  • resides on client
  • Provides interface of the server
  • Skeleton
  • Resides on server
  • Generate stubs and skeletons
  • rmic AddServerImpl

12
RMI Sequence of Actions
  • The RMI Server creates an instance of the 'Server
    Object' which extends UnicastRemoteObject
  • The constructor for UnicastRemoteObject "exports"
    the Server Object. A TCP socket which is bound to
    an arbitrary port number is created and a thread
    is also created that listens for connections on
    that socket.
  • The server registers the server object with the
    registry.

13
RMI Sequence of Actions
  • A client obtains the stub by calling the
    registry, which hands it the stub directly.
  • When the client issues a remote method invocation
    to the server, the stub class
  • opens a socket to the server on the port
    specified in the stub itself, and
  • Sends the RMI header information as described in
    the RMI spec.

14
RMI Sequence of Actions
  • The stub class marshalls the arguments
  • On the server side, when a client connects to the
    server socket, a new thread is forked to deal
    with the incoming call.
  • The server calls the "dispatch" method of the
    skeleton class, which calls the appropriate
    method on the object and pushes the result back
    down the wire

15
RMI Performance
  • RMI vs. Local call(200Mhz, NT, JDK no JIT)
  • Call time (no configuration available)
  • setup time RMI 40 slower than CORBA
  • binding RMI 200-1500ms slower than CORBA
  • CORBA vs. RMI
  • 1000 calls, one argument, JDK1.1.1

Pengwu97
16
Resources
  • java.sun.com
  • http//gsraj.tripod.com/java/rmi_internals.html
  • http//www-csag.ucsd.edu/individual/achien/cs491-f
    97/reading.htmlpengwu97
  • Java Complete Reference-Schildt Naughton
Write a Comment
User Comments (0)
About PowerShow.com