Chapter 5 Remote invocation Distributed Systems Concepts and

Chapter 5: Remote invocation Distributed Systems : Concepts and Design Dr. Ir. H. Sumijan, M. Sc Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 1 Middleware layers Applications This chapter (and Chapter 6) Remote invocation, indirect communication Underlying interprocess communication primitives: Middleware layers Sockets, message passing, multicast support, overlay networks UDP and TCP Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 2 Request-reply communication Client do. Operation Server Request message (wait) (continuation) Reply message get. Request select object execute method send. Reply Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012
![Figure 5. 3 Operations of the request-reply protocol public byte[] do. Operation (Remote. Ref Figure 5. 3 Operations of the request-reply protocol public byte[] do. Operation (Remote. Ref](http://slidetodoc.com/presentation_image/3a160184d8f88a6c07e127d9cf9c2678/image-4.jpg)
Figure 5. 3 Operations of the request-reply protocol public byte[] do. Operation (Remote. Ref s, int operation. Id, byte[] arguments) sends a request message to the remote server and returns the reply. The arguments specify the remote server, the operation to be invoked and the arguments of that operation. public byte[] get. Request (); acquires a client request via the server port. public void send. Reply (byte[] reply, Inet. Address client. Host, int client. Port); sends the reply message reply to the client at its Internet address and port. Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 4 Request-reply message structure message. Type int (0=Request, 1= Reply) request. Id int remote. Reference Remote. Ref operation. Id int or Operation arguments array of bytes Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 5 RPC exchange protocols Name Messages sent by Client Server R Request Reply RRA Request Reply Client Acknowledge reply Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 6 HTTP request message method URL or pathname GET //www. dcs. qmw. ac. uk/index. html HTTP version headers message body HTTP/ 1. 1 Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 7 HTTP Reply message HTTP version HTTP/1. 1 status code reason headers message body 200 OK resource data Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 8 CORBA IDL example // In file Person. idl struct Person { string name; string place; long year; }; interface Person. List { readonly attribute string listname; void add. Person(in Person p) ; void get. Person(in string name, out Person p); long number(); }; Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 9 Call semantics Fault tolerance measures Retransmit request message Duplicate filtering Call semantics Re-execute procedure or retransmit reply No Not applicable Maybe Yes No Re-execute procedure At-least-once Yes Retransmit reply At-most-once Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 10 Role of client and server stub procedures in RPC client process server process Request client program client stub procedure Communication module Reply server stub procedure Communication dispatcher module service procedure Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 11 Files interface in Sun XDR const MAX = 1000; typedef int File. Identifier; typedef int File. Pointer; typedef int Length; struct Data { int length; char buffer[MAX]; }; struct writeargs { File. Identifier f; File. Pointer position; Data data; }; struct readargs { File. Identifier f; File. Pointer position; Length length; }; program FILEREADWRITE { version VERSION { void WRITE(writeargs)=1; Data READ(readargs)=2; } = 9999; 1 2 Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 12 Remote and local method invocations local remote invocation A B C local E invocation local invocation D remote invocation F Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 13 A remote object and its remote interface remoteobject remote interface { Data m 1 m 2 m 3 implementation of methods m 4 m 5 m 6 Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 14 Instantiation of remote objects Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 15 The role of proxy and skeleton in remote method invocation Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 16 Java Remote interfaces Shape and Shape. List import java. rmi. *; import java. util. Vector; public interface Shape extends Remote { int get. Version() throws Remote. Exception; Graphical. Object get. All. State() throws Remote. Exception; 1 } public interface Shape. List extends Remote { Shape new. Shape(Graphical. Object g) throws Remote. Exception; 2 Vector all. Shapes() throws Remote. Exception; int get. Version() throws Remote. Exception; } Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 17 The Naming class of Java RMIregistry void rebind (String name, Remote obj) This method is used by a server to register the identifier of a remote object by name, as shown in Figure 15. 18, line 3. void bind (String name, Remote obj) This method can alternatively be used by a server to register a remote object by name, but if the name is already bound to a remote object reference an exception is thrown. void unbind (String name, Remote obj) This method removes a binding. Remote lookup(String name) This method is used by clients to look up a remote object by name, as shown in Figure 5. 20 line 1. A remote object reference is returned. String [] list() This method returns an array of Strings containing the names bound in the registry. Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 18 Java class Shape. List. Server with main method import java. rmi. *; public class Shape. List. Server{ public static void main(String args[]){ System. set. Security. Manager(new RMISecurity. Manager()); try{ Shape. List a. Shape. List = new Shape. List. Servant(); Naming. rebind("Shape List", a. Shape. List ); System. out. println("Shape. List server ready"); }catch(Exception e) { System. out. println("Shape. List server main " + e. get. Message()); } } } 1 2 Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 19 Java class Shape. List. Servant implements interface Shape. List import java. rmi. *; import java. rmi. server. Unicast. Remote. Object; import java. util. Vector; public class Shape. List. Servant extends Unicast. Remote. Object implements Shape. List { private Vector the. List; // contains the list of Shapes private int version; public Shape. List. Servant()throws Remote. Exception{. . . } public Shape new. Shape(Graphical. Object g) throws Remote. Exception { 1 version++; Shape s = new Shape. Servant( g, version); 2 the. List. add. Element(s); return s; } public Vector all. Shapes()throws Remote. Exception{. . . } public int get. Version() throws Remote. Exception {. . . } } Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 20 Java client of Shape. List import java. rmi. *; import java. rmi. server. *; import java. util. Vector; public class Shape. List. Client{ public static void main(String args[]){ System. set. Security. Manager(new RMISecurity. Manager()); Shape. List a. Shape. List = null; try{ a. Shape. List = (Shape. List) Naming. lookup("//bruno. Shape. List") ; Vector s. List = a. Shape. List. all. Shapes(); } catch(Remote. Exception e) {System. out. println(e. get. Message()); }catch(Exception e) {System. out. println("Client: " + e. get. Message()); } } } 1 2 Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012

Figure 5. 21 Classes supporting Java RMI Remote. Object Remote. Server Activatable Unicast. Remote. Object <servant class> Coulouris G. et al, 2012 : Distributed Systems: Concepts and Design (5 th Edition) 5 th Edition, Edition 5, © Addison-Wesley 2012
- Slides: 22