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

distributed systems lecture 6 programming models
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

DS-E02 Lec6 1

Distributed Systems Lecture 6 Programming models

Josva Kleist Unit for Distributed Systems and Semantics Aalborg University

slide-2
SLIDE 2

DS-E02 Lec6 2

Distributed programming

  • Directly using the available network protocols.
  • Generalization of existing language primitives to

support distributed programming.

  • Event driven programming.
  • Distributed shared memory.
slide-3
SLIDE 3

DS-E02 Lec6 3

Middleware layers

Applications Middleware layers Request reply protocol External data representation Operating System RMI, RPC and events

slide-4
SLIDE 4

DS-E02 Lec6 4

Basic communication issues

  • External data representation and marshalling.
  • The client-server communication model.
slide-5
SLIDE 5

DS-E02 Lec6 5

Heterogeneity

Hardware

  • Interpretation of a byte (big or little endian).
  • Representation of integers, floating point values,

characters, etc. Software

  • Internal representation of datastructures.
slide-6
SLIDE 6

DS-E02 Lec6 6

Coping with heterogeneity

  • Values are converted to an agreed external format

before transmission, and converted to the local format

  • n receipt.
  • Values are transmitted in the sender’s format together

with an indication of the format used.

slide-7
SLIDE 7

DS-E02 Lec6 7

External data representation and marshalling

  • CORBA common data representation (CDR).
  • Java’s object serialization.
slide-8
SLIDE 8

DS-E02 Lec6 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
slide-9
SLIDE 9

DS-E02 Lec6 9

CORBA CDR for constructed types

Type Representation length (unsigned long) followed by element in order sequence length (unsigned long) followed by characters in

  • rder (can also have wide characters)

string array elements in order (no length specified because it is fixed) array in the order of declaration of the components) struct unsigned long (the values are specified by the order declared) enumerated union type tag followed by the selected member

slide-10
SLIDE 10

DS-E02 Lec6 10

CORBA CDR message

notes

  • n representation

0–3 4–7 8–11 12–15 16–19 20-23 24–27 5 "Smit" "h___" 6 "Lond" "on__" 1934 index in sequence of bytes 4 bytes length of string ‘Smith’ length of string ‘London’ unsigned long

The flattened form represents a Person struct with value: {‘Smith’, ‘London’, 1934}

slide-11
SLIDE 11

DS-E02 Lec6 11

Marshalling in CORBA

struct Person{ string name; string place; long year; }

slide-12
SLIDE 12

DS-E02 Lec6 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 }

slide-13
SLIDE 13

DS-E02 Lec6 13

Indication of Java serialized form

Explanation

Person 3 1934 8-byte version number int year 5 Smith java.lang.String name: 6 London h0 java.lang.String place: h1

Serialized values

class name, version number number, type and name of instance variables values of instance variables

The true serialized form contains additional type markers; h0 and h1 are handles

slide-14
SLIDE 14

DS-E02 Lec6 14

Request-reply communication

Request doOperation (wait) (continuation) Reply message getRequest execute method message select object sendReply Client Server

slide-15
SLIDE 15

DS-E02 Lec6 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.

slide-16
SLIDE 16

DS-E02 Lec6 16

Request-reply message structure

messageType requestId

  • bjectReference

methodId arguments int (0=Request, 1= Reply) int RemoteObjectRef int or Method array of bytes

slide-17
SLIDE 17

DS-E02 Lec6 17

Failure model for request-reply protocols

  • Omission failures
  • No ordering guaranteed (UDP does not guarantee
  • rdering).
slide-18
SLIDE 18

DS-E02 Lec6 18

Coping with failure

  • Timeouts
  • Discarding duplicated request messages
  • Lost reply messages
  • History
slide-19
SLIDE 19

DS-E02 Lec6 19

Request-reply exchange protocols

Name Message sent by Client Server Client R Request RR Reply Request RRA Reply Acknowledge reply Request

slide-20
SLIDE 20

DS-E02 Lec6 20

Design of distributed objects

  • Object references.
  • Remote interfaces vs. local interfaces.
  • Actions.
  • Semantics of method invocation.
  • Implementation.
  • Exception handling.
  • Garbage collection.
slide-21
SLIDE 21

DS-E02 Lec6 21

Representation of a remote object reference

32 bits 32 bits 32 bits 32 bits Internet address port number time

  • bject number

interface of remote object

slide-22
SLIDE 22

DS-E02 Lec6 22

Remote and local method invocations

invocation invocation remote invocation remote local local local invocation invocation A B C D E F

slide-23
SLIDE 23

DS-E02 Lec6 23

A remote object and its remote interface

interface remote m1 m2 m3 m4 m5 m6 Data implementation remote

  • bject

{

  • f methods
slide-24
SLIDE 24

DS-E02 Lec6 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(); };

slide-25
SLIDE 25

DS-E02 Lec6 25

Invocation semantics

  • Exactly once.
  • Maybe.
  • At least once.
  • At most once.
slide-26
SLIDE 26

DS-E02 Lec6 26

Invocation semantics – part 2

Invocation Fault tolerance measures semantics Retransmit request Duplicate Re-execute procedure message filtering

  • r retransmit reply

No Not applicable Not applicable Maybe Yes No Re-execute procedure At-least-once Yes Yes Retransmit reply At-most-once

slide-27
SLIDE 27

DS-E02 Lec6 27

Implementing RMI

  • bject A
  • bject B

skeleton Request proxy for B Reply Communication Remote Remote reference Communication module module reference module module for B’s class & dispatcher remote client server

slide-28
SLIDE 28

DS-E02 Lec6 28

Exceptions

  • Where are exceptions generated on the server side

directed?

  • What about new exception types introduced by the

RMI subsystem?

slide-29
SLIDE 29

DS-E02 Lec6 29

Garbage collection

  • The garbage collection system in an existing run time

system must continue to function.

  • How are remote references handled?
slide-30
SLIDE 30

DS-E02 Lec6 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.
slide-31
SLIDE 31

DS-E02 Lec6 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.

slide-32
SLIDE 32

DS-E02 Lec6 32

Java Remote interfaces Shape and ShapeList

import java.rmi.*; import java.util.Vector; public interface Shape extends Remote { int getVersion( ) throws RemoteException; GraphicalObject getAllState() throws RemoteException; } public interface ShapeList extends Remote { Shape newShape(GraphicalObject g) throws RemoteException; Vector allShapes( ) throws RemoteException; int getVersion( ) throws RemoteException; } 1 2

slide-33
SLIDE 33

DS-E02 Lec6 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

  • bject 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

  • bject 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.

slide-34
SLIDE 34

DS-E02 Lec6 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 ); System.out.println("ShapeList server ready"); }catch(Exception e) { System.out.println("ShapeList server main " + e.getMessage());} } } 1 2

slide-35
SLIDE 35

DS-E02 Lec6 35

Java class ShapeListServant implements interface ShapeList

import java.rmi.*; import java.rmi.server.UnicastRemoteObject; import java.util.Vector; public class ShapeListServant extends UnicastRemoteObject implements ShapeList { private Vector theList; // contains the list of Shapes private int version; public ShapeListServant()throws RemoteException{...} public Shape newShape(GraphicalObject g) throws RemoteException { version++; Shape s = new ShapeServant( g, version); theList.addElement(s); return s; } public Vector allShapes()throws RemoteException{...} public int getVersion() throws RemoteException { ... } } 1 2 3

slide-36
SLIDE 36

DS-E02 Lec6 36

Java client of ShapeList

import java.rmi.*; import java.rmi.server.*; import java.util.Vector; public class ShapeListClient{ public static void main(String args[]){ System.setSecurityManager(new RMISecurityManager()); ShapeList aShapeList = null; try{ aShapeList = (ShapeList) Naming.lookup("//bruno.ShapeList") ; Vector sList = aShapeList.allShapes(); } catch(RemoteException e) {System.out.println(e.getMessage()); }catch(Exception e) {System.out.println("Client: " + e.getMessage());} } } 1 2

slide-37
SLIDE 37

DS-E02 Lec6 37

Classes supporting Java RMI

RemoteServer UnicastRemoteObject <servant class> Activatable RemoteObject