1 / 22

Remote Object Invocation

Remote Object Invocation. Tran, Van Hoai Department of Systems & Networking Faculty of Computer Science & Engineering HCMC University of Technology. Outline. Distributed objects Binding client to object Static vs Dynamic Parameter passing Examples Java RMI. Why object-oriented ?.

woody
Download Presentation

Remote Object Invocation

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 Object Invocation Tran, Van Hoai Department of Systems & Networking Faculty of Computer Science & Engineering HCMC University of Technology

  2. Outline • Distributed objects • Binding client to object • Static vs Dynamic • Parameter passing • Examples • Java RMI 2009-2010

  3. Why object-oriented ? • OO has strong features • information hiding • data abstraction • encapsulation • modularity • polymorphism • and inheritance • OOP software engineering • Modelling • Design • Language • Database • Scripting • … 2009-2010

  4. Enhancement of RPC • RPC • simple • effective • standard for communication in distributed system development Object Oriented + Remote Procedure Call = Remote Object Invocation

  5. Distributed object model (1) Client machine Server machine object Client Server state Proxy same interface as object Client invokes a method method Skeleton invokes same method at object interface Proxy Skeleton Client OS ServerOS Marshalled invocation passed across network Network

  6. Distributed object model (2) • When a client binds to a distributed object, load the interface (“proxy”) into client address space • Proxy analogous to stubs • Server stub is referred to as a skeleton

  7. Characteristics for distributed objects (1) • Compile time vs runtime objects • compile time objects: related to language-level objects • Object = instance of a class • Interfaces compiled into client, server’s stubs • Drawback: depend strongly on particular programming language • runtime objects: how object implemented left open • need an adapter to bind dynamically invocation to implementation

  8. Characteristics for distributed objects (2) • Persistent vs transient objects • persistent objects: not depend on server process • object can be stored in secondary storage if server exits • and restored when new server started • transient objects: exists as long as server managing it

  9. Binding client to object • Distributed object model provides systemwide reference • can be passed as parameters • Binding needed before invoking methods • In practice, binding temporarily creates proxy • 2 approaches • Implicit binding • Explicit binding

  10. Implicit vs Explicit bindings Implicit Explicit Distr_object *obj_ref; Local_object *obj_ptr; obj_ref = ...; obj_ptr = bind( obj_ref ); obj_ptr->do_something(); Distr_object *obj_ref; obj_ref = ...; obj_ref->do_something(); Explicit bind and get a pointer to proxy Invoke a method on local proxy

  11. Object reference implementation issuses (1) • Goal: to allow client binding to an object • Simple approach • reference = (network address, server ID, object ID) • server ID = port (in practice) • Drawbacks • what happens if server machine crashes, and the server has a new server ID ? • Client can contact with a service to provide mapping between server ID and server • The server must register with the service

  12. Object reference implementation issuses (2) • Drawbacks • what happens if the server moved to other machine ? • a server to provide a mapping, called location server • reference = (location server address, systemwide server ID)

  13. Remote Method Invocation • Similar to RPC, but has an advantages of systemwide object reference • static invocation: • predefined interface definition • interface known when client being developed fobject.append(int) • dynamic invocation: • select at runtime which method to be invoked at remote object invoke( fobject, id(append), int)

  14. Passing object references(local & remote) machine A machine B remote reference R1 local object O1 remote object O2 local reference L1 client code with RMI to server at C new local reference machine C copy of O1 copy of R1 to O2 remote invocation with L1 and R1 as parameters server code(method implementation)

  15. DCE Distributed object model server machine server machine Dynamic (private) object named (shared) object Dynamic (private) object Dynamic (private) object remote reference • object not for a single client • client looks up named object at directory service • object created for individual client • a function “create()” to new an object client #1 client #2 client #3 Distributed dynamic objects Distributed named objects

  16. Java RMI • Java RMI allows programmer to execute remote function class using the same semantics as local functions calls Local Machine (Client) SampleServer remoteObject; int s; … s = remoteObject.sum(1,2); System.out.println(s); Remote Machine (Server) public int sum(int a,int b) { return a + b; } 1,2 3

  17. Java RMI architecture • The server must first bind its name to the registry • The client lookup the server name in the registry to establish remote references. • The Stub serializing the parameters to skeleton, the skeleton invoking the remote method and serializing the result back to the stub.

  18. Naming service (1) • Directory that associates names to remote objects (bind) Remote Object A Naming “X” Remote Object C “Y” Remote Object B “Z” server machine

  19. Naming service (2) • Client use Naming Service to find a particular Server object (lookup) Naming Object Client Remote Object Server “X” lookup(“Y”) “Y” Remote reference to Server “Z” client machine server machine

  20. Steps for Developing an RMI System 1. Define the remote interface 2. Develop the remote object by implementing the remote interface. 3. Develop the client program. 4. Compile the Java source files. 5. Generate the client stubs and server skeletons. 6. Start the RMI registry. 7. Start the remote server objects. 8. Run the client

  21. Server /* SampleServerImpl.java */ public static void main(String args[]) { try { System.setSecurityManager(new RMISecurityManager()); //set the security manager //create a local instance of the object SampleServerImpl Server = new SampleServerImpl(); //put the local instance in the registry Naming.rebind("SAMPLE-SERVER" , Server); System.out.println("Server waiting....."); } catch (java.net.MalformedURLException me) { System.out.println("Malformed URL: " + me.toString()); } catch (RemoteException re) { System.out.println("Remote exception: " + re.toString()); } }

  22. Client import java.rmi.*; import java.rmi.server.*; public class SampleClient { public static void main(String[] args) { // set the security manager for the client System.setSecurityManager(new RMISecurityManager()); //get the remote object from the registry try { System.out.println("Security Manager loaded"); String url = "//localhost/SAMPLE-SERVER"; SampleServer remoteObject = (SampleServer)Naming.lookup(url); System.out.println("Got remote object"); System.out.println(" 1 + 2 = " + remoteObject.sum(1,2) ); } catch (RemoteException exc) { System.out.println("Error in lookup: " + exc.toString()); } catch (java.net.MalformedURLException exc) { System.out.println("Malformed URL: " + exc.toString()); } catch (java.rmi.NotBoundException exc) { System.out.println("NotBound: " + exc.toString()); } } }

More Related