Presentation is loading. Please wait.

Presentation is loading. Please wait.

RMI RMI is the java API that facilitate distributed computing by allowing remote method calls. A remote method call represents a method invocation between.

Similar presentations


Presentation on theme: "RMI RMI is the java API that facilitate distributed computing by allowing remote method calls. A remote method call represents a method invocation between."— Presentation transcript:

1 RMI RMI is the java API that facilitate distributed computing by allowing remote method calls. A remote method call represents a method invocation between different JVM. RMI Client Remote Object or RMI server Remote Method Call

2 RMI provides basic infrastructure required for distributed computing. Commonly used terms or terminology of RMI. 1) Remote object / RMI server :- A remote object /RMI server is a distributed object that exposes remote method which can be invoke on the remote object in a distributed manner from different JVM. 2) RMI client: is an object that invokes a remote method using RMI.

3 Domain name Server Domain Name Web Application Web Server ISP Client 1.1 domains name are provided 1.0 registered IP Address

4 3) Stub :- A stub represents a proxy of remote object that hides the internal details of remote method invocation from the RMI client. 4) Skeleton:- A skeleton is the proxy of RMI client that hides the internal details of RMI from the remote object. In order to invoke remote method using RMI following sequence of operation are required.

5 Directory Server NameStub 1.2 Remote Object 1.1 Skeleton 1.0 RMI Client 2.0 2.2 2.1 Stub 2.3 2.4 2.5 2.6 2.7 Proxy for server Proxy for client JVM

6 1.0 Remote object is created 1.1 Stub & skeleton for the remote object is created. 1.2 Remote stub is registered with a logical name in directory server 2.0 search remote stub. 2.1 Remote stub is obtained 2.2 invokes remote method 2.3 establises connection with its skeleton & marshals method call to the skeleton 2.4 unmarshalls method call and invokes method on actual object

7 2.5 method completes and result is returned to skeleton 2.6 skeleton marshals result of method call to the stub. 2.7 stub unmarshals result and provide it to client. STEPS TO CREATE RMI BASED APPLICATION:- 1) Define a remote interface, each remote object exposes remote interface to its clients.this interface extends java.rmi.remote interface and provides remote method. Each remote method in the remote interface through java java.rmi.RemoteException.

8 2) Define a class that implements remote interface & provides Exporting logic.java.rmi.server.UnicastRemoteObject class provides exporting logic logic(Statements to create stub & skeleton for a remote object ) This class must be extended by the implementation class. 3) compile implementation class & generate its stub & skeleton class. rmic:(rmi compiler ) tools provided with jdk is used to generate stub & skeleton class for a rmi object. Syntax: rmic className of RemoteObject Ex. Rmic Myadder MyAdder_Stub.class & MyAdder_skeleton.class

9 4) start a directory service to facilitate registration & lookup of remote stub. An implementation of directory service is provided with jdk that provides the facility of registration & lookup of remote stub. syntax to start rmiregistry: 1) on default port(1099) Rmiregistry 2) on a specific port :- rmiregistry port number 5) Create remote object and register its stub with the directory server. Enter

10 Java.rmi.Naming : class provides static method to register or lookup a remote object with RMI registry. bind():- register a remote stub with the given name in the RMI registry. Public static void bind(String name, Remote Object)throws RemoteException, AlreadyBindException. rebind(): public static void rebind(String name,remote object)throws RemoteException ; Lookup():- is used for search remote stub. Public static Remote lookup(String lookup String)throws RemoteException; Formate of lookup String:- protocal/host Address/port/registered name Note: protocal/host address is optional if rmiregistry is running on default port on localhost.

11 5) Define a class to represent client: in client class obtain the reference of remote stub from the directory server and invoke remote method on it. If rmi registry is running on a different port then default method of registering remote stub is changed.i.e at the time of registration address of the host as well as port number of the rmi registry is used. For this purpose registry & LocateRegistryClass provided in java.rmi.registry package.

12 LocateRegistry class is a factory that provides method to obtain registry object. A registry object is used to bound,unbound or lookup a stub in the rmi registry. You can see easily using >javap java.rmi.registry.LocateRegistry >a.txt. > a.txt getRegistry() method of LocateRegistry class is used to create a registry object. 1)Public static registry getRegistry(String hostName) remote exception. 2) Public static Registry getRegistry(int port)throws remote exception.

13 Public static registry getRegistry(String host name,int port)throws remote exception; A registry class provides bind & rebind method to register an object to the directory server.


Download ppt "RMI RMI is the java API that facilitate distributed computing by allowing remote method calls. A remote method call represents a method invocation between."

Similar presentations


Ads by Google