Presentation is loading. Please wait.

Presentation is loading. Please wait.

RMI Varun SainiYing 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.

Similar presentations


Presentation on theme: "RMI Varun SainiYing 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."— Presentation transcript:

1 RMI Varun SainiYing 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 d1+d2;} }

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 addServerImpl=new AddServerImpl(); Naming.rebind("AddServer",addServerImpl); } catch(Exception e){System.out.println(e);} }

10 AddClient.java import 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);} }

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 ms slower than CORBA CORBA vs. RMI 1000 calls, one argument, JDK1.1.1 Pengwu97

16 Resources java.sun.com ls.html ls.html csag.ucsd.edu/individual/achien/cs491- f97/reading.html[pengwu97] csag.ucsd.edu/individual/achien/cs491- f97/reading.html Java Complete Reference-Schildt Naughton


Download ppt "RMI Varun SainiYing 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."

Similar presentations


Ads by Google