Distributed Computing with Objects RMI/Corba - PowerPoint PPT Presentation

distributed computing with objects rmi corba n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Distributed Computing with Objects RMI/Corba PowerPoint Presentation
Download Presentation
Distributed Computing with Objects RMI/Corba

play fullscreen
1 / 33
Distributed Computing with Objects RMI/Corba
0 Views
Download Presentation
janyce
Download Presentation

Distributed Computing with Objects RMI/Corba

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick

  2. Remote Method Invocation • RMI • JAVA-TO-JAVA • Object running on one JVM can invoke methods on an object running on another JVM • RMI provides communication between remote Java programs

  3. Overview • Sever Creates Remote Objects • Server Makes References to Them Accessible • Server Waits on Remote Method Calls • Client get References to Remote Objects • Invokes Methods on Them • Distributed Objects

  4. Distributed Objects • Locate Remote Objects • Register • Pass and Return References • Communicate with Remote Objects (Transparent to Programmer) • Load Bytecode and transmit data over network

  5. Dynamic Code Loading • Download code of an objects class if class not defined in receiver’s virtual machine • RMI passes objects by true type • Change behavior of application dynamically • Compute Example

  6. Remote Interfaces, Objects, and Methods • Distrubed application made up of interfaces and classes • Some implementations reside on remote machines • Objects with methods on remote VM’s are remote objects • Object is remote by implementing remote interface

  7. Remote Interfaces • Extends java.rmi.Remote • Each remote method must declare java.rmi.RemoteException • Remote objects are passed by reference between virtual machines, not a copy

  8. Stubs • Remote reference is a stub • Local representative or proxy • Caller invokes method on stub which carries out method call on remote object • Stub implements the same set of remote interfaces as remote object • Only those methods defined in remote interface available to caller

  9. Steps • Design and Implement Components of Distributed Application • Compile Sources and Generate Stubs and Skeletons • Make Classes Network Accessible • Start the Application

  10. Details • Object becomes remote by implementing a remote interface • java.rmi.Remote • Methods java.rmi.RemoteException in throws clause • Stub is local proxy for remote object. Generated by rmic compiler • Skeleton interfaces object and object manager on Server

  11. Details, contd. • Define Remote Interface: specifies remote methods • Implement Remote Objects: Implement the remote interface • Implement Clients • Put classes in Web accessible directory: remote interfaces, stubs, other download classes • Start registry, start application

  12. Example • Generic Compute Engine • What it computes is not defined when engine is written • Take advantage of central powerful machine • Dynamic

  13. An Example

  14. How it works

  15. Interface Details • Compute allows jobs to be submitted to the engine • Task defines how the compute engine executes the given task. Passed by value between VM’s • Return value is an Object

  16. Example 16

  17. Implementing a Remote Interface • Declare remote interfaces • Define constructor for Remote object • Provide implementations for remote methods • Create and install security manager • create instance of remote object • register remote object with registry

  18. UnicastRemoteObject • UnicastRemoteObject: Point to point communications with socket transport. Constructor exports object for calls. • RMISecurityManager as restrictive asApplet • Create instance and bind to registry. Instance is of type Compute. Name is hostwhere registry is.

  19. Register • Front-end for binding (registering) and looking up remote object is java.rmi.Naming interface • Remote VM’s can look up objects by name in RMI registry. • Name should inlcude name of host where registry and remote object run, and a name that identifies remote object in registry.

  20. Binding • Bind remote object to registry • URL type format for host and name • Default port is 1099 • rmi::/<host>:<port>/Compute • RMI runtime substitutes reference tostub for remote object reference. Remote object implementations never leave JVM where created. • RMI keeps ComputeEngine running

  21. Stubs • When client invokes remote method, it actually calls a regular method on a local JVM. • This method is encapsulate in a stub class (surrogate) • Stub encodes parameters (marshalling) • Sends information over network to server

  22. Skeleton • Makes sense out of information in packet from stub (Unmarshals) • Passes it to actual object on local JVM • Packages response and sends it back to client • Stubs can be on local machine or loaded across network similar to applet

  23. Marshalling Client Stub Skeleton Server Marshalled Parametersand Return Values MethodInvocation MethodInvocation

  24. UMBC The Server import java.rmi.*; import java.rmi.server.*; import java.net.*; public class HelloServer extends UnicastRemoteObject implements IHello { public HelloServer() throws RemoteException { hiMsg = "Hello, world!"; } public String sayHi() throws RemoteException { return hiMsg; } public static void main( String[ ] args ) { try { Naming.rebind( "hello", new HelloServer() ); } catch( RemoteException e ) { System.err.println( e ); } catch( MalformedURLException e ) { System.err.println( e ); } } private String hiMsg; }

  25. The Client import java.rmi.*; public class HelloClient { public static void main( String[ ] args ) { System.setSecurityManager( new RMISecurityManager() ); try { IHello iface = (IHello) Naming.lookup( "rmi://<host>/hello" ); System.out.println( "Client says " + iface.sayHi() ); } catch( Exception e ) { System.err.println( e ); } } }

  26. Connecting Client to Server javac HelloServer.java HelloClient.java rmic HelloServer Rmiregistry & java –Djava.security.policy=<policyfile> HelloServer & java –Djava.security.policy=<policyfile> HelloClient

  27. A Policy File grant { // Allow everything for now permission java.security.AllPermission; };

  28. Client • Defines task to be done by ComputeEngine

  29. Example

  30. Example

  31. Running the Example • Pi class downloaded to server at runtime • ComputeEngine stub downloaded to client at runtime • Make jar file with compute package (interfaces) • Distribute to developers • Put classes in network accessible directory

  32. Using RMI • RMI uses URL protocols to download code • Classpath should include location of jar filesand source files • Compile source (javac), generate stub (rmic) • Source for the example discussed so far can be found in the Java Tutorial on RMI

  33. Selected References • Advanced Techniques for Java Developers Chapter 7 • http://java.sun.com/docs/books/tutorial/rmi/index.html • Exploring Java, O’Reilly, Niemeyer & Peck • Java RMI Remote Method Invocation, Troy Downing, IDG Books • The RMI example comes from Core Web Programming, Marty Hall, Prentice Hall • http://engronline.ee.memphis.edu/AdvJava/lecture.htm