distributed systems lecture 6 programming models
play

Distributed Systems Lecture 6 Programming models Josva Kleist - PowerPoint PPT Presentation

Distributed Systems Lecture 6 Programming models Josva Kleist Unit for Distributed Systems and Semantics Aalborg University DS-E02 Lec6 1 Distributed programming Directly using the available network protocols. Generalization of


  1. Distributed Systems Lecture 6 Programming models Josva Kleist Unit for Distributed Systems and Semantics Aalborg University DS-E02 Lec6 1

  2. Distributed programming • Directly using the available network protocols. • Generalization of existing language primitives to support distributed programming. • Event driven programming. • Distributed shared memory. DS-E02 Lec6 2

  3. Middleware layers Applications RMI, RPC and events Middleware Request reply protocol layers External data representation Operating System DS-E02 Lec6 3

  4. Basic communication issues • External data representation and marshalling. • The client-server communication model. DS-E02 Lec6 4

  5. Heterogeneity Hardware • Interpretation of a byte (big or little endian). • Representation of integers, floating point values, characters, etc. Software • Internal representation of datastructures. DS-E02 Lec6 5

  6. Coping with heterogeneity • Values are converted to an agreed external format before transmission, and converted to the local format on receipt. • Values are transmitted in the sender’s format together with an indication of the format used. DS-E02 Lec6 6

  7. External data representation and marshalling • CORBA common data representation (CDR). • Java’s object serialization. DS-E02 Lec6 7

  8. CORBA CDR for primitive types • Short integers (16 bit) • Long integers (32 bit) • Unsigned short, unsigned long • Float (32 bit) • Double (32 bit) • Char • Boolean ( true, false ) • Octet (8-bit) • Any DS-E02 Lec6 8

  9. CORBA CDR for constructed types Type Representation sequence length (unsigned long) followed by element in order string length (unsigned long) followed by characters in order (can also have wide characters) array array elements in order (no length specified because it is fixed) struct in the order of declaration of the components) enumerated unsigned long (the values are specified by the order declared) union type tag followed by the selected member DS-E02 Lec6 9

  10. CORBA CDR message notes index in on representation sequence of bytes 4 bytes length of string 5 0–3 "Smit" 4–7 ‘Smith’ "h___" 8–11 12–15 6 length of string "Lond" 16–19 ‘London’ "on__" 20-23 1934 24–27 unsigned long The flattened form represents a Person struct with value: {‘Smith’, ‘London’, 1934} DS-E02 Lec6 10

  11. Marshalling in CORBA struct Person{ string name; string place; long year; } DS-E02 Lec6 11

  12. Java Object Serialization public class Person implements Serializable{ private String name; private String place; private int year; public Person(String aName, String aPlace, in aYear){ name=aName; place=aPlace; year=aYear; } // followed by methods for accessing the instance vars } DS-E02 Lec6 12

  13. Indication of Java serialized form Explanation Serialized values Person 8-byte version number h0 class name, version number java.lang.String java.lang.String number, type and name of int year 3 name: place: instance variables 1934 5 Smith 6 London h1 values of instance variables The true serialized form contains additional type markers; h0 and h1 are handles DS-E02 Lec6 13

  14. Request-reply communication Client Server Request doOperation getRequest message select object execute (wait) method Reply sendReply message (continuation) DS-E02 Lec6 14

  15. Operations of the request-reply protocol public byte[] doOperation (RemoteObjectRef o, int methodId, byte[] arguments) sends a request message to the remote object and returns the reply. The arguments specify the remote object, the method to be invoked and the arguments of that method. public byte[] getRequest (); acquires a client request via the server port. public void sendReply (byte[] reply, InetAddress clientHost, int clientPort); sends the reply message reply to the client at its Internet address and port. DS-E02 Lec6 15

  16. Request-reply message structure messageType int (0=Request, 1= Reply) requestId int objectReference RemoteObjectRef methodId int or Method arguments array of bytes DS-E02 Lec6 16

  17. Failure model for request-reply protocols • Omission failures • No ordering guaranteed (UDP does not guarantee ordering). DS-E02 Lec6 17

  18. Coping with failure • Timeouts • Discarding duplicated request messages • Lost reply messages • History DS-E02 Lec6 18

  19. Request-reply exchange protocols Name Message sent by Client Server Client R Request RR Reply Request RRA Reply Acknowledge reply Request DS-E02 Lec6 19

  20. Design of distributed objects • Object references. • Remote interfaces vs. local interfaces. • Actions. • Semantics of method invocation. • Implementation. • Exception handling. • Garbage collection. DS-E02 Lec6 20

  21. Representation of a remote object reference 32 bits 32 bits 32 bits 32 bits interface of Internet address port number time object number remote object DS-E02 Lec6 21

  22. Remote and local method invocations local C remote E local invocation invocation remote invocation invocation F B A local invocation D DS-E02 Lec6 22

  23. A remote object and its remote interface remote object Data remote interface m4 m1 { implementation m5 m2 m6 of methods m3 DS-E02 Lec6 23

  24. CORBA IDL example // In file Person.idl struct Person { string name; string place; long year; } ; interface PersonList { readonly attribute string listname; void addPerson(in Person p) ; void getPerson(in string name, out Person p); long number(); }; DS-E02 Lec6 24

  25. Invocation semantics • Exactly once. • Maybe. • At least once. • At most once. DS-E02 Lec6 25

  26. Invocation semantics – part 2 Invocation Fault tolerance measures semantics Retransmit request Duplicate Re-execute procedure message filtering or retransmit reply No Not applicable Not applicable Maybe Yes No Re-execute procedure At-least-once Yes Yes Retransmit reply At-most-once DS-E02 Lec6 26

  27. Implementing RMI server client remote skeleton object A proxy for B object B & dispatcher Request for B’s class Reply Remote reference Communication Communication Remote module reference module module module DS-E02 Lec6 27

  28. Exceptions • Where are exceptions generated on the server side directed? • What about new exception types introduced by the RMI subsystem? DS-E02 Lec6 28

  29. Garbage collection • The garbage collection system in an existing run time system must continue to function. • How are remote references handled? DS-E02 Lec6 29

  30. Case study: Java RMI • Extends the Java object model providing support for distributed objects. • Same syntax as for local method invocation. • Remote interfaces defined by extending the Remote interface. • Parameter passing: – Remote objects passed by remote object reference. – Non-remote objects passed by value (must be serializable). • Classes can be downloaded from one VM to another. DS-E02 Lec6 30

  31. Garbage collection in Java RMI • Each server holds a list of client processes that has a proxy to a remote object located at the server. • When a client process creates a proxy, a request is send to the server, asking that the process is added to the list. • When a proxy in a client process is garbage collected, a request is send to the server, asking the the process is removed from the list. • When the list is empty, the remote object can be garbage collected. DS-E02 Lec6 31

  32. Java Remote interfaces Shape and ShapeList import java.rmi.*; import java.util.Vector; public interface Shape extends Remote { int getVersion( ) throws RemoteException; 1 GraphicalObject getAllState() throws RemoteException; } public interface ShapeList extends Remote { 2 Shape newShape(GraphicalObject g) throws RemoteException; Vector allShapes( ) throws RemoteException; int getVersion( ) throws RemoteException; } DS-E02 Lec6 32

  33. 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.13, 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 15.15 line 1. A remote object reference is returned. String [] list() This method returns an array of Strings containing the names bound in the registry. DS-E02 Lec6 33

  34. Java class ShapeListServer with main method import java.rmi.*; public class ShapeListServer{ public static void main(String args[]){ System.setSecurityManager(new RMISecurityManager()); try{ ShapeList aShapeList = new ShapeListServant(); Naming.rebind("Shape List", aShapeList ); 1 System.out.println("ShapeList server ready"); 2 }catch(Exception e) { System.out.println("ShapeList server main " + e.getMessage());} } } DS-E02 Lec6 34

Recommend


More recommend