Presentation is loading. Please wait.

Presentation is loading. Please wait.

Remote Object Invocation Tran, Van Hoai Department of Systems & Networking Faculty of Computer Science & Engineering HCMC University of Technology.

Similar presentations

Presentation on theme: "Remote Object Invocation Tran, Van Hoai Department of Systems & Networking Faculty of Computer Science & Engineering HCMC University of Technology."— 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 22009-2010

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

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 OS Client ServerOS Server Client invokes a method Skeleton invokes same method at object Client machineServer machine Proxy Network Proxy same interface as object Marshalled invocation passed across network Skeleton interface object state method

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 Distr_object *obj_ref; obj_ref =...; obj_ref->do_something(); Explicit Distr_object *obj_ref; Local_object *obj_ptr; obj_ref =...; obj_ptr = bind( obj_ref ); obj_ptr->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) local object O1remote object O2 copy of O1 copy of R1 to O2 server code (method implementation) remote reference R1 new local reference remote invocation with L1 and R1 as parameters client code with RMI to server at C local reference L1 machine Amachine B machine C

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

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) server machine Remote Object C Remote Object A Remote Object B Naming “X” “Y” “Z”

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

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 /* */ 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 ( 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 ( exc) { System.out.println("Malformed URL: " + exc.toString()); } catch (java.rmi.NotBoundException exc) { System.out.println("NotBound: " + exc.toString()); }

Download ppt "Remote Object Invocation Tran, Van Hoai Department of Systems & Networking Faculty of Computer Science & Engineering HCMC University of Technology."

Similar presentations

Ads by Google