rmi

16
RMI Varun Saini Ying Chen

Upload: uriel

Post on 11-Jan-2016

36 views

Category:

Documents


0 download

DESCRIPTION

RMI. Varun Saini. Ying Chen. 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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: RMI

RMI

Varun Saini Ying Chen

Page 2: RMI

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.

Page 3: RMI

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

Page 4: RMI

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

Page 5: RMI

AddServerIntf.java

import java.rmi.*; public interface AddServerIntf extends

Remote{double add (double d1, double d2)

throws RemoteException; }

Page 6: RMI

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

Page 7: RMI

AddServerImpl.javaimport 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 d1+d2;}

}

Page 8: RMI

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

Page 9: RMI

AddServer.javaimport java.rmi.*; public class AddServer{ public static void main(String[] args) { try{ AddServerImpl addServerImpl=new

AddServerImpl(); Naming.rebind("AddServer",addServerImpl);

} catch(Exception e){System.out.println(e);}

}}

Page 10: RMI

AddClient.javaimport java.rmi.*; public class AddClient{ public static void main(String[] args) { try{ String addServerURL = "rmi://"+args[0]+"/AddServer";

AddServerIntf addServerIntf= (AddServerIntf)Naming.lookup(addServerURL);

double d1=Double.valueOf(args[1]).doubleValue(); double d2=Double.valueOf(args[2]).doubleValue(); System.out.println("Sum= "+addServerIntf.add(d1,d2));

} catch(Exception e){System.out.println(e);} }}

Page 11: RMI

Stubs and Skeletons Stub

resides on client Provides interface of the server

Skeleton Resides on server

Generate stubs and skeletons rmic AddServerImpl

Page 12: RMI

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.

Page 13: RMI

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.

Page 14: RMI

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

Page 15: RMI

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

RMI (cross process)

RMI (cross machine)

local

1.6 ms/call 1.8ms/call 700ns/call

Pengwu97

Page 16: RMI

Resources java.sun.com http://gsraj.tripod.com/java/rmi_int

ernals.html http://www-csag.ucsd.edu/individu

al/achien/cs491-f97/reading.html[pengwu97]

Java Complete Reference-Schildt Naughton