1 / 15

Remote Method Invocation (RMI)

Remote Method Invocation (RMI). RMI is a mechanism for communicating (only) between two machines running Java Virtual Machines. The  stub object  (on machine A) has to build an information block thats consists of an identifier of the remote object to be used,

royal
Télécharger la présentation

Remote Method Invocation (RMI)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Remote Method Invocation (RMI) • RMI is a mechanism for communicating (only) between two machines running Java Virtual Machines

  2. The stub object (on machine A) has to • build an information block thats consists of • an identifier of the remote object to be used, • an operation number describing the method to be called and • the marshalled parameters (method parameters have to be encoded into a format suitable for transporting them across the net) • send this information to the server

  3. The tasks of the skeleton object (on machine B) are • to unmarshal the parameters, • to call the desired method on the real object lying on the server, • to capture the return value or exception of the call on the server, • to marshal this value, • to send a package consisting of the value in the marshalled form back to the stub on the client, machine A.

  4. ArithmeticInterface.java

  5. import java.rmi.*; public interface ArithmeticInterface extends Remote { int add(inta,int b)throws RemoteException; }

  6. ArithmeticImplement.java

  7. import java.rmi.*; import java.rmi.server.*; public class ArithmeticImplement extends UnicastRemoteObject implements ArithmeticInterface { intx,y; public ArithmeticImplement()throws RemoteException { super(); }

  8. public int add(inta,int b)throws RemoteException { return a+b; } public static void main(String[] args)throws Exception { ArithmeticImplementaImp=new ArithmeticImplement(); Naming.rebind("rmi://localhost:1099/ArithmeticInterface",aImp); } }

  9. ArithmeticClient.java

  10. import java.rmi.*; import java.io.*; public class ArithmeticClient { public ArithmeticClient() { String rmObj="rmi://localhost:1099/ArithmeticInterface"; try{ ArithmeticInterfaceaInterf= ArithmeticInterface)Naming.lookup(rmObj); intx,y;

  11. InputStreamReader ir=new InputStreamReader(System.in); BufferedReaderkbdInput=new BufferedReader(ir); System.out.println("Enter nos:"); x=Integer.parseInt(kbdInput.readLine()); y=Integer.parseInt(kbdInput.readLine()); System.out.println("Result is "+aInterf.add(x,y)); } catch (Exception e) {} }

  12. public static void main(String[] args)throws Exception { ArithmeticClient client=new ArithmeticClient(); } }

  13. Executing RMI

  14. Compile all Java files - javac *.java Create Stub & Skelton - rmicArithmeticImplement Start RMI registry - First Command Prompt rmiregistry 1099 Start Server - Second Command Prompt java ArithmeticImplement Start Client - Third Command Prompt java ArithmeticClient

More Related