CS6601 DISTRIBUTED SYSTEMS

89
CS6601 DISTRIBUTED SYSTEMS UNIT II Dr.A.Kathirvel, Professor, Computer Science and Engg. M N M Jain Engineering College, Chennai

Transcript of CS6601 DISTRIBUTED SYSTEMS

Page 1: CS6601 DISTRIBUTED SYSTEMS

CS6601 DISTRIBUTED SYSTEMS

UNIT – II

Dr.A.Kathirvel, Professor, Computer Science and Engg.

M N M Jain Engineering College, Chennai

Page 2: CS6601 DISTRIBUTED SYSTEMS

Unit - II

COMMUNICATION IN DISTRIBUTED

SYSTEM System Model – Inter process Communication – the API for internet

protocols – External data representation and Multicast

communication. Network virtualization: Overlay networks. Case

study: MPI Remote Method Invocation And Objects: Remote

Invocation – Introduction – Request-reply protocols – Remote

procedure call – Remote method invocation. Case study: Java RMI –

Group communication – Publish-subscribe systems – Message

queues – Shared memory approaches – Distributed objects – Case

study: Enterprise Java Beans -from objects to components.

Coulouris, Dollimore, Kindberg and Blair

Distributed Systems:Concepts and Design Edition 5, Addison-Wesley 2012

Page 3: CS6601 DISTRIBUTED SYSTEMS

Fig4.1: Middleware layers

INTERPROCESS COMMUNICATION

3

Page 4: CS6601 DISTRIBUTED SYSTEMS

Fig4.2:Sockets and ports

message

agreed port any port

socket socket

Internet address = 138.37.88.249 Internet address = 138.37.94.248

other ports

client server

4

Page 5: CS6601 DISTRIBUTED SYSTEMS

UDP client sends a message to the

server and gets a reply import java.net.*;

import java.io.*;

public class UDPClient{

public static void main(String args[]){

// args give message contents and server hostname

DatagramSocket aSocket = null;

try {

aSocket = new DatagramSocket();

byte [] m = args[0].getBytes();

InetAddress aHost = InetAddress.getByName(args[1]);

int serverPort = 6789;

DatagramPacket request = new DatagramPacket(m, m.length(), aHost, serverPort);

aSocket.send(request);

byte[] buffer = new byte[1000];

DatagramPacket reply = new DatagramPacket(buffer, buffer.length);

aSocket.receive(reply);

System.out.println("Reply: " + new String(reply.getData()));

}catch (SocketException e){System.out.println("Socket: " + e.getMessage());

}catch (IOException e){System.out.println("IO: " + e.getMessage());}

}finally {if(aSocket != null) aSocket.close();}

} }

5

Page 6: CS6601 DISTRIBUTED SYSTEMS

UDP server repeatedly receives a

request and sends it back to the client import java.net.*;

import java.io.*;

public class UDPServer{

public static void main(String args[]){

DatagramSocket aSocket = null;

try{

aSocket = new DatagramSocket(6789);

byte[] buffer = new byte[1000];

while(true){

DatagramPacket request = new DatagramPacket(buffer, buffer.length);

aSocket.receive(request);

DatagramPacket reply = new DatagramPacket(request.getData(),

request.getLength(), request.getAddress(), request.getPort());

aSocket.send(reply);

}

}catch (SocketException e){System.out.println("Socket: " + e.getMessage());

}catch (IOException e) {System.out.println("IO: " + e.getMessage());}

}finally {if(aSocket != null) aSocket.close();}

}}

6

Page 7: CS6601 DISTRIBUTED SYSTEMS

TCP client makes connection to server,

sends request and receives reply import java.net.*;

import java.io.*;

public class TCPClient {

public static void main (String args[]) {

// arguments supply message and hostname of destination

Socket s = null;

try{

int serverPort = 7896;

s = new Socket(args[1], serverPort);

DataInputStream in = new DataInputStream( s.getInputStream());

DataOutputStream out =new DataOutputStream( s.getOutputStream());

out.writeUTF(args[0]); // UTF is a string encoding see Sn 4.3

String data = in.readUTF();

System.out.println("Received: "+ data) ;

}catch (UnknownHostException e){ System.out.println("Sock:"+e.getMessage());

}catch (EOFException e){System.out.println("EOF:"+e.getMessage());

}catch (IOException e){System.out.println("IO:"+e.getMessage());}

}finally {if(s!=null) try {s.close();}catch (IOException

e){System.out.println("close:"+e.getMessage());}}

}}

7

Page 8: CS6601 DISTRIBUTED SYSTEMS

TCP server makes a connection for each

client and then echoes the client’s request

import java.net.*;

import java.io.*;

public class TCPServer {

public static void main (String args[]) {

try{ int serverPort = 7896;

ServerSocket listenSocket = new ServerSocket(serverPort);

while(true) {

Socket clientSocket = listenSocket.accept();

Connection c = new Connection(clientSocket); }

} catch(IOException e) {System.out.println("Listen :"+e.getMessage());}

}

}

// this continues on the next slide

8

Page 9: CS6601 DISTRIBUTED SYSTEMS

class Connection extends Thread {

DataInputStream in;

DataOutputStream out;

Socket clientSocket;

public Connection (Socket aClientSocket) {

try {

clientSocket = aClientSocket;

in = new DataInputStream( clientSocket.getInputStream());

out =new DataOutputStream( clientSocket.getOutputStream());

this.start();

} catch(IOException e) {System.out.println("Connection:"+e.getMessage());}

}

public void run(){

try { // an echo server

String data = in.readUTF();

out.writeUTF(data);

} catch(EOFException e) {System.out.println("EOF:"+e.getMessage());

} catch(IOException e) {System.out.println("IO:"+e.getMessage());}

} finally{ try {clientSocket.close();}catch (IOException e){/*close failed*/}}

}

}

9

Page 10: CS6601 DISTRIBUTED SYSTEMS

CORBA CDR for constructed types

T y p e Re pr e s e n ta t i o n

s e q ue n ce l e n g th ( u n si g n ed l o n g ) fo ll ow ed b y el e m e nt s i n o r d e r

s t ri n g l e n g th ( u n si g n ed l o n g ) fo ll ow ed b y ch a ra c te rs i n o r d e r ( ca n al so

ca n h av e w i de ch a ra c te rs)

a r ra y a rr ay e le m e n t s i n o r de r ( n o l en g t h s p e ci f ie d b eca us e i t is f i x e d )

s t ru ct i n t he or de r o f de c la r at i o n o f t he co mp o n e n t s

e n u m e r a t e d u n s i g n e d l o n g ( t h e v a l ue s a re s pe c i f ie d b y t he o r de r d ec l ar e d )

u ni o n t y p e ta g f o l l o we d b y t h e s el e cte d m e mb er

10

Page 11: CS6601 DISTRIBUTED SYSTEMS

CORBA CDR message

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

0–3

4–7

8–11

12–15

16–19

20-23

24–27

5

"Smit"

"h___"

6

"Lond"

"on__"

1984

index in

sequence of bytes 4 bytes

notes

on representation

length of string

‘Smith’

length of string

‘London’

unsigned long

11

Page 12: CS6601 DISTRIBUTED SYSTEMS

Indication of Java serialized form

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

Serialized values

Person

3

1984

8-byte version number

int year

5 Smith

java.lang.String name:

6 London

h0

java.lang.String place:

h1

Explanation

class name, version number

number, type and name of instance variables

values of instance variables

12

Page 13: CS6601 DISTRIBUTED SYSTEMS

XML definition of the Person structure

<person id="123456789">

<name>Smith</name>

<place>London</place>

<year>1984</year>

<!-- a comment -->

</person >

use of namespace in the Person structure <person pers:id="123456789" xmlns:pers="http://www.cdk5.net/person">

<pers:name> Smith </pers:name>

<pers:place> London </pers:place >

<pers:year> 1984 </pers:year>

</person>

13

Page 14: CS6601 DISTRIBUTED SYSTEMS

An XML schema for the Person structure

<xsd:schema xmlns:xsd = URL of XML schema definitions >

<xsd:element name= "person" type ="personType" />

<xsd:complexType name="personType">

<xsd:sequence>

<xsd:element name = "name" type="xs:string"/>

<xsd:element name = "place" type="xs:string"/>

<xsd:element name = "year" type="xs:positiveInteger"/>

</xsd:sequence>

<xsd:attribute name= "id" type = "xs:positiveInteger"/>

</xsd:complexType>

</xsd:schema>

Representation of a remote object reference

Internet address port number time object number interface of remote object

32 bits 32 bits 32 bits 32 bits

14

Page 15: CS6601 DISTRIBUTED SYSTEMS

Multicast peer joins a group and sends

and receives datagrams import java.net.*;

import java.io.*;

public class MulticastPeer{

public static void main(String args[]){

// args give message contents & destination multicast group (e.g. "228.5.6.7")

MulticastSocket s =null;

try {

InetAddress group = InetAddress.getByName(args[1]);

s = new MulticastSocket(6789);

s.joinGroup(group);

byte [] m = args[0].getBytes();

DatagramPacket messageOut =

new DatagramPacket(m, m.length, group, 6789);

s.send(messageOut);

// this figure continued on the next slide

15

Page 16: CS6601 DISTRIBUTED SYSTEMS

// get messages from others in group

byte[] buffer = new byte[1000];

for(int i=0; i< 3; i++) {

DatagramPacket messageIn =

new DatagramPacket(buffer, buffer.length);

s.receive(messageIn);

System.out.println("Received:" + new String(messageIn.getData()));

}

s.leaveGroup(group);

}catch (SocketException e){System.out.println("Socket: " + e.getMessage());

}catch (IOException e){System.out.println("IO: " + e.getMessage());}

}finally {if(s != null) s.close();}

}

}

16

Page 17: CS6601 DISTRIBUTED SYSTEMS

Types of overlay

table continues on the next slide

17

Page 18: CS6601 DISTRIBUTED SYSTEMS
Page 19: CS6601 DISTRIBUTED SYSTEMS

Skype overlay architecture

19

Page 20: CS6601 DISTRIBUTED SYSTEMS

Fig:4.17 An overview of point-to-point

communication in MPI

20

Page 21: CS6601 DISTRIBUTED SYSTEMS

Selected send operations in MPI

Page 22: CS6601 DISTRIBUTED SYSTEMS

Fig 5.1: Middleware layers

Applications

Middleware layers Underlying interprocess communication primitives:

Sockets, message passing, multicast support, overlay networks

UDP and TCP

Remote invocation, indirect communication This chapter

(and Chapter 6)

Remote invocation

22

Page 23: CS6601 DISTRIBUTED SYSTEMS

Fig 5.2:Request-reply communication

Request

Server Client

doOperation

(wait)

(continuation)

Reply

message

getRequest

execute

method

message

select object

sendReply

23

Page 24: CS6601 DISTRIBUTED SYSTEMS

Operations of the request-reply protocol

public byte[] doOperation(RemoteRef s,int operationId,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[] 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.

24

Page 25: CS6601 DISTRIBUTED SYSTEMS

Fig 5.4:Request-reply message structure

messageType

requestId

remoteReference

operationId

arguments

int (0=Request, 1= Reply)

int

RemoteRef

int or Operation

array of bytes

25

Page 26: CS6601 DISTRIBUTED SYSTEMS

Fig5.5:RPC exchange protocols

R Request

R R Reply

R R A Acknowledge reply

Request

Request Reply

Client Server Client

Name Messages sent by

Fig 5.6:HTTP request message

GET //www.dcs.qmw.ac.uk/index.html HTTP/ 1.1

URL or pathname method HTTP version headers message body

Fig 5.7:HTTP Reply message

HTTP/1.1 200 OK resource data

HTTP version status code reason headers message body

26

Page 27: CS6601 DISTRIBUTED SYSTEMS

Fig5.8: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();}; Fig5.9:Call semantics

Fault tolerance measures Call semantics

Retransmit request message

Duplicate filtering

Re-execute procedure or retransmit reply

No

Yes

Yes

Not applicable

No

Yes

Not applicable

Re-execute procedure

Retransmit reply At-most-once

At-least-once

Maybe

Page 28: CS6601 DISTRIBUTED SYSTEMS

Fig5.10: Role of client and server stub

procedures in RPC

client

Request

Reply

Communication Communication

module module dispatcher

service

client stub

server stub procedure procedure

client process server process

procedure program

28

Page 29: CS6601 DISTRIBUTED SYSTEMS

Fig5.11: Files interface in Sun XDR

const MAX = 1000;

typedef int FileIdentifier;

typedef int FilePointer;

typedef int Length;

struct Data {

int length;

char buffer[MAX];

};

struct writeargs {

FileIdentifier f;

FilePointer position;

Data data;

};

struct readargs {

FileIdentifier f;

FilePointer position;

Length length;

};

program FILEREADWRITE {

version VERSION {

void WRITE(writeargs)=1; 1

Data READ(readargs)=2; 2

}=2;

} = 9999;

29

Page 30: CS6601 DISTRIBUTED SYSTEMS

Fig5.12: Remote and local method

invocations

invocation invocation

remote

invocation

remote

local

local

local

invocation

invocation

A B

C

D

E

F

30

Page 31: CS6601 DISTRIBUTED SYSTEMS

Fig5.13:A remote object and its remote

interface

interface

remote

m1

m2

m3

m4 m5

m6

Data

implementation

remote object

{ of methods

31

Page 32: CS6601 DISTRIBUTED SYSTEMS

Fig5.14: Instantiation of remote objects

32

Page 33: CS6601 DISTRIBUTED SYSTEMS

Fig5.15: The role of proxy and skeleton

in remote method invocation

33

Page 34: CS6601 DISTRIBUTED SYSTEMS

Fig5.16: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; 1

}

public interface ShapeList extends Remote {

Shape newShape(GraphicalObject g) throws RemoteException; 2

Vector allShapes() throws RemoteException;

int getVersion() throws RemoteException;

}

34

Page 35: CS6601 DISTRIBUTED SYSTEMS

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.

35

Page 36: CS6601 DISTRIBUTED SYSTEMS

Fig5.18: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(); 1

Naming.rebind("Shape List", aShapeList ); 2

System.out.println("ShapeList server ready");

}catch(Exception e) {

System.out.println("ShapeList server main " + e.getMessage());}

}

}

36

Page 37: CS6601 DISTRIBUTED SYSTEMS

Fig5.19: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 { 1

version++;

Shape s = new ShapeServant( g, version); 2

theList.addElement(s);

return s;

}

public Vector allShapes()throws RemoteException{...}

public int getVersion() throws RemoteException { ... }

}

37

Page 38: CS6601 DISTRIBUTED SYSTEMS

Fig5.20: 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") ;

1

Vector sList = aShapeList.allShapes();

2

} catch(RemoteException e) {System.out.println(e.getMessage());

}catch(Exception e) {System.out.println("Client: " + e.getMessage());}

}

}

38

Page 39: CS6601 DISTRIBUTED SYSTEMS

Fig5.21: Classes supporting Java RMI

RemoteServer

UnicastRemoteObject

<servant class>

Activatable

RemoteObject

Indirect Communication

39

Page 40: CS6601 DISTRIBUTED SYSTEMS

Fig 6.1:Space and time coupling in ds

40

Page 41: CS6601 DISTRIBUTED SYSTEMS

Fig6.2:Open and closed groups

Closed group Open group

41

Page 42: CS6601 DISTRIBUTED SYSTEMS

Fig6.3: The role of group membership

management

Join

Group

address

expansion

Multicast

communication

Group

send

Fail Group membership

management

Leave

Process group

42

Page 43: CS6601 DISTRIBUTED SYSTEMS

Fig 6.4:The architecture of JGroups

43

Page 44: CS6601 DISTRIBUTED SYSTEMS

Fig6.5:Java class FireAlarmJG

import org.jgroups.JChannel;

public class FireAlarmJG {

public void raise() {

try {

JChannel channel = new JChannel();

channel.connect("AlarmChannel");

Message msg = new Message(null, null, "Fire!");

channel.send(msg);

}

catch(Exception e) {

}}

44

Page 45: CS6601 DISTRIBUTED SYSTEMS

Fig 6.6:Java class FireAlarmConsumerJG

import org.jgroups.JChannel;

public class FireAlarmConsumerJG {

public String await() {

try {

JChannel channel = new JChannel();

channel.connect("AlarmChannel");

Message msg = (Message) channel.receive(0);

return (String) msg.GetObject();

} catch(Exception e) {

return null;

}

}}

45

Page 46: CS6601 DISTRIBUTED SYSTEMS

Fig 6.7:Dealing room system Dealer’s computer

Information

provider

Dealer

External

source

External

source

Information

provider

Dealer

Dealer

Dealer

Notification

Notification

Notification

Notification

Notification Notification

Notification

Notification

Dealer’s computer

Dealer’s computer Dealer’s computer

Notification Notification

46

Page 47: CS6601 DISTRIBUTED SYSTEMS

Fig6.8:The publish-subscribe paradigm

47

Page 48: CS6601 DISTRIBUTED SYSTEMS

Fig 6.9:A network of brokers

48

Page 49: CS6601 DISTRIBUTED SYSTEMS

Fig6.10:The architecture of publish-

subscribe systems

49

Page 50: CS6601 DISTRIBUTED SYSTEMS

Fig6.11:Filtering-based routing

upon receive publish(event e) from node x 1

matchlist := match(e, subscriptions) 2

send notify(e) to matchlist; 3

fwdlist := match(e, routing); 4

send publish(e) to fwdlist - x; 5

upon receive subscribe(subscription s) from node x 6

if x is client then 7

add x to subscriptions; 8

else add(x, s) to routing; 9

send subscribe(s) to neighbours - x; 10

50

Page 51: CS6601 DISTRIBUTED SYSTEMS

Fig6.12:Rendezvous-based routing

upon receive publish(event e) from node x at node i

rvlist := EN(e);

if i in rvlist then begin

matchlist :=match(e, subscriptions);

send notify(e) to matchlist;

end

send publish(e) to rvlist - i;

upon receive subscribe(subscription s) from node x at node i

rvlist := SN(s);

if i in rvlist then

add s to subscriptions;

else

send subscribe(s) to rvlist - i;

51

Page 52: CS6601 DISTRIBUTED SYSTEMS

Fig6.13:Example publish-subscribe system

52

Page 53: CS6601 DISTRIBUTED SYSTEMS

Fig6.14:The message queue paradigm

53

Page 54: CS6601 DISTRIBUTED SYSTEMS

Fig6.15:A simple networked topology

in WebSphere MQ

54

Page 55: CS6601 DISTRIBUTED SYSTEMS

Fig6.16:The programming model

offered by JMS

55

Page 56: CS6601 DISTRIBUTED SYSTEMS

Fig6.17:Java class FireAlarmJMS import javax.jms.*;

import javax.naming.*;

public class FireAlarmJMS {

public void raise() {

try { 1

Context ctx = new InitialContext(); 2

TopicConnectionFactory topicFactory = 3

(TopicConnectionFactory)ctx.lookup ("TopicConnectionFactory"); 4

Topic topic = (Topic)ctx.lookup("Alarms"); 5

TopicConnection topicConn = 6

topicConnectionFactory.createTopicConnection(); 7

TopicSession topicSess = topicConn.createTopicSession(false, 8

Session.AUTO_ACKNOWLEDGE); 9

TopicPublisher topicPub = topicSess.createPublisher(topic); 10;

TextMessage msg = topicSess.createTextMessage(); 11

msg.setText("Fire!"); 12

topicPub.publish(message); 13

} catch (Exception e) { 14

} 15

}

56

Page 57: CS6601 DISTRIBUTED SYSTEMS

Fig6.18:Java class FireAlarmConsumerJMS

import javax.jms.*; import javax.naming.*;

public class FireAlarmConsumerJMS

public String await() {

try { 1

Context ctx = new InitialContext(); 2

TopicConnectionFactory topicFactory = 3

(TopicConnectionFactory)ctx.lookup("TopicConnectionFactory"); 4

Topic topic = (Topic)ctx.lookup("Alarms"); 5

TopicConnection topicConn = 6

topicConnectionFactory.createTopicConnection(); 7

TopicSession topicSess = topicConn.createTopicSession(false, 8

Session.AUTO_ACKNOWLEDGE); 9

TopicSubscriber topicSub = topicSess.createSubscriber(topic); 10

topicSub.start(); 11

TextMessage msg = (TextMessage) topicSub.receive(); 12

return msg.getText(); 13

} catch (Exception e) { 14

return null; 15

}16 }

57

Page 58: CS6601 DISTRIBUTED SYSTEMS

Fig6.19:The distributed shared memory

abstraction

58

Page 59: CS6601 DISTRIBUTED SYSTEMS

Fig6.20:The tuple space abstraction

59

Page 60: CS6601 DISTRIBUTED SYSTEMS

Replication and the tuple space

operations

write

1. The requesting site multicasts the write request to all members of the view;

2. On receiving this request, members insert the tuple into their replica and

acknowledge this action;

3. Step 1 is repeated until all acknowledgements are received.

read

1. The requesting site multicasts the read request to all members of the view;

2. On receiving this request, a member returns a matching tuple to the requestor;

3. The requestor returns the first matching tuple received as the result of the operation

(ignoring others);

4. Step 1 is repeated until at least one response is received.

continued on next slide

60

Page 61: CS6601 DISTRIBUTED SYSTEMS

take Phase 1: Selecting the tuple to be removed

Phase 2: Removing the selected tuple

1. The requesting site multicasts the take request to all members of the view;

2. On receiving this request, each replica acquires a lock on the associated tuple set and, if the

lock cannot

be acquired, the take request is rejected;

3. All accepting members reply with the set of all matching tuples;

4. Step 1 is repeated until all sites have accepted the request and responded with their set of

tuples and the

intersection is non-null;

5. A particular tuple is selected as the result of the operation (selected randomly from the

intersection of all

the replies);

6. If only a minority accept the request, this minority are asked to release their locks and

phase 1 repeats.

1. The requesting site multicasts a remove request to all members of the view citing the

tuple to be

removed;

2. On receiving this request, members remove the tuple from their replica, send an

acknowledgement

and release the lock;

3. Step 1 is repeated until all acknowledgements are received.

61

Page 62: CS6601 DISTRIBUTED SYSTEMS

Fig6.22:Partitioning in the York Linda

Kernel

62

Page 63: CS6601 DISTRIBUTED SYSTEMS

Fig6.23:The JavaSpaces API

63

Page 64: CS6601 DISTRIBUTED SYSTEMS

Fig6.24:Java class AlarmTupleJS

import net.jini.core.entry.*;

public class AlarmTupleJS implements Entry {

public String alarmType;

public AlarmTupleJS() { }

}

public AlarmTupleJS(String alarmType) {

this.alarmType = alarmType;}

}}

64

Page 65: CS6601 DISTRIBUTED SYSTEMS

Fig6.25:Java class FireAlarmJS

import net.jini.space.JavaSpace;

public class FireAlarmJS {

public void raise() {

try {

JavaSpace space =

SpaceAccessor.findSpace("AlarmSpace");

AlarmTupleJS tuple = new AlarmTupleJS("Fire!");

space.write(tuple, null, 60*60*1000);

catch (Exception e) {

} } }

65

Page 66: CS6601 DISTRIBUTED SYSTEMS

Fig16.26:Java class FireAlarmReceiverJS

import net.jini.space.JavaSpace;

public class FireAlarmConsumerJS {

public String await() {

try {

JavaSpace space = SpaceAccessor.findSpace();

AlarmTupleJS template = new AlarmTupleJS("Fire!");

AlarmTupleJS recvd = (AlarmTupleJS)

space.read(template, null,

Long.MAX_VALUE);

return recvd.alarmType;

}

catch (Exception e) {

return null;

} }}

66

Page 67: CS6601 DISTRIBUTED SYSTEMS

Fig6.27:Summary of indirect

communication styles

67

Page 68: CS6601 DISTRIBUTED SYSTEMS

Fig8.1:Distributed

objects

Distributed Objects and Components

68

Page 69: CS6601 DISTRIBUTED SYSTEMS

Fig8.2:IDL interfaces Shape and ShapeList

struct Rectangle{ 1

long width;

long height;

long x;

long y;

} ;

struct GraphicalObject { 2

string type;

Rectangle enclosing;

boolean isFilled;

};

interface Shape { 3

long getVersion() ;

GraphicalObject getAllState() ; // returns state of the GraphicalObject

};

typedef sequence <Shape, 100> All; 4

interface ShapeList { 5

exception FullException{ }; 6

Shape newShape(in GraphicalObject g) raises (FullException); 7

All allShapes(); // returns sequence of remote object references 8

long getVersion() ;

};

69

Page 70: CS6601 DISTRIBUTED SYSTEMS

Fig8.3:IDL module Whiteboard

module Whiteboard {

struct Rectangle{

...} ;

struct GraphicalObject {

...};

interface Shape {

...};

typedef sequence <Shape, 100> All;

interface ShapeList {

...};

};

70

Page 71: CS6601 DISTRIBUTED SYSTEMS

Fig8.4:IDL constructed types – 1

Type Examples Use

sequence typedef sequence <Shape, 100> All; typedef sequence <Shape> All bounded and unbounded sequences o f Shapes

Defines a type for a variable-length sequence of elements of a specified IDL type. An upper bound on the length may be specified.

string String name; typedef string<8> SmallString;

unbounded and bounded sequences of characters

Defines a sequences of characters, terminated by the null character. An upper bound on the length may be specified.

array typedef octet uniqueId[12];

typedef GraphicalObject GO[10][8]

Defines a type for a multi-dimensional fixed-length sequence of elements of a specified IDL type.

this figure continues on the next slide

71

Page 72: CS6601 DISTRIBUTED SYSTEMS

Fig8.4: IDL constructed types – 2

Type Examples Use

record struct GraphicalObject {

string type; Rectangle enclosing; boolean isFilled;

};

Defines a type for a record containing a group of related entities. Structs are passed by value in arguments and results.

enumerated enum Rand (Exp, Number, Name);

The enumerated type in IDL maps a type name onto a small set of integer values.

union union Exp switch (Rand) { case Exp: string vote; case Number: long n; case Name: string s;

The IDL discriminated union allows one of a given set of types to be passed as an argument. The header is parameterized by an enum , which specifies which member is in use. };

72

Page 73: CS6601 DISTRIBUTED SYSTEMS

Fig8.5:The main components of the

CORBA architecture

client server

proxy

or dynamic invocation

implementation

repository object adapter

ORB ORB

skeleton

or dynamic skeleton

client program

interface

repository

Request

Reply core core for A

Servant

A

73

Page 74: CS6601 DISTRIBUTED SYSTEMS

Fig8.6: CORBA Services (1)

this figure continues on the next slide

74

Page 75: CS6601 DISTRIBUTED SYSTEMS

Fig8.6:CORBA Services (2)

75

Page 76: CS6601 DISTRIBUTED SYSTEMS

Fig8.7:Java interfaces generated by idlj

from CORBA interface ShapeList

public interface ShapeListOperations {

Shape newShape(GraphicalObject g)

throws ShapeListPackage.FullException;

Shape[] allShapes();

int getVersion();

}

public interface ShapeList extends ShapeListOperations,

org.omg.CORBA.Object,

org.omg.CORBA.portable.IDLEntity { }

76

Page 77: CS6601 DISTRIBUTED SYSTEMS

Fig8.8: ShapeListServant class of the Java

server program for CORBA interface ShapeList

import org.omg.CORBA.*;

import org.omg.PortableServer.POA;

class ShapeListServant extends ShapeListPOA {

private POA theRootpoa;

private Shape theList[];

private int version;

private static int n=0;

public ShapeListServant(POA rootpoa){

theRootpoa = rootpoa;

// initialize the other instance variables

}

// continued on the next slide

77

Page 78: CS6601 DISTRIBUTED SYSTEMS

public Shape newShape(GraphicalObject g)

throws ShapeListPackage.FullException { 1

version++;

Shape s = null;

ShapeServant shapeRef = new ShapeServant( g, version);

try {

org.omg.CORBA.Object ref =

theRoopoa.servant_to_reference(shapeRef); 2

s = ShapeHelper.narrow(ref);

} catch (Exception e) {}

if(n >=100) throw new ShapeListPackage.FullException();

theList[n++] = s;

return s;

}

public Shape[] allShapes(){ ... }

public int getVersion() { ... }

} 78

Page 79: CS6601 DISTRIBUTED SYSTEMS

Fig8.9:Java class ShapeListServer

import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*;

import org.omg.CORBA.*; import org.omg.PortableServer.*;

public class ShapeListServer {

public static void main(String args[]) {

try{

ORB orb = ORB.init(args,null); 1

POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));2

rootpoa.the_POAManager().activate(); 3

ShapeListServant SLSRef = new ShapeListServant(rootpoa); 4

org.omg.CORBA.Object ref = rootpoa.servant_to_reference(SLSRef); 5

ShapeList SLRef = ShapeListHelper.narrow(ref);

org.omg.CORBA.Object objRef =orb.resolve_initial_references("NameService");

NamingContext ncRef = NamingContextHelper.narrow(objRef); 6

NameComponent nc = new NameComponent("ShapeList", ""); 7

NameComponent path[] = {nc}; 8

ncRef.rebind(path, SLRef); 9

orb.run(); 10

} catch (Exception e) { ... }

}}

79

Page 80: CS6601 DISTRIBUTED SYSTEMS

Fig8.10:Java client program for CORBA

interfaces Shape and ShapeList import org.omg.CosNaming.*;

import org.omg.CosNaming.NamingContextPackage.*;

import org.omg.CORBA.*;

public class ShapeListClient{

public static void main(String args[]) {

try{

ORB orb = ORB.init(args, null); 1

org.omg.CORBA.Object objRef =

orb.resolve_initial_references("NameService");

NamingContext ncRef = NamingContextHelper.narrow(objRef);

NameComponent nc = new NameComponent("ShapeList", "");

NameComponent path [] = { nc };

ShapeList shapeListRef =

ShapeListHelper.narrow(ncRef.resolve(path)); 2

Shape[] sList = shapeListRef.allShapes(); 3

GraphicalObject g = sList[0].getAllState(); 4

} catch(org.omg.CORBA.SystemException e) {...}

}

80

Page 81: CS6601 DISTRIBUTED SYSTEMS

Fig8.11:An example software architecture

81

Page 82: CS6601 DISTRIBUTED SYSTEMS

Fig8.12:The structure of a container

82

Page 83: CS6601 DISTRIBUTED SYSTEMS

Fig8.13:Application servers

83

Page 84: CS6601 DISTRIBUTED SYSTEMS

Fig8.14: Transaction attributes in EJB.

84

Page 85: CS6601 DISTRIBUTED SYSTEMS

Fig8.15:Invocation contexts in EJB

85

Page 86: CS6601 DISTRIBUTED SYSTEMS

Fig8.16 :An example component

configuration in Fractal

86

Page 87: CS6601 DISTRIBUTED SYSTEMS

Fig8.17:The structure of a Fractal

component

87

Page 88: CS6601 DISTRIBUTED SYSTEMS

Fig8.18:Component and Content

Controller Interfaces in Fractal

88

Page 89: CS6601 DISTRIBUTED SYSTEMS

Questions?