27
1 Lecture 21 – April 4, 2002 Dynamic Loading Communication in Bond Message delivery Internal and external message format KQML Synchronous and asynchrounous communication Events – monitoring Communication Engines Base 64 encoding Virtual Networks of Objects

Lecture 21 – April 4, 2002

  • Upload
    vui

  • View
    35

  • Download
    0

Embed Size (px)

DESCRIPTION

Lecture 21 – April 4, 2002. Dynamic Loading Communication in Bond Message delivery Internal and external message format KQML Synchronous and asynchrounous communication Events – monitoring Communication Engines Base 64 encoding Virtual Networks of Objects. - PowerPoint PPT Presentation

Citation preview

Page 1: Lecture 21 – April 4, 2002

1

Lecture 21 – April 4, 2002

Dynamic LoadingCommunication in BondMessage deliveryInternal and external message formatKQMLSynchronous and asynchrounous communicationEvents – monitoringCommunication EnginesBase 64 encodingVirtual Networks of Objects

Page 2: Lecture 21 – April 4, 2002

2

public class bondLoader extends bondObject { public Vector defaultpath = null; ClassLoader cloader = null; public bondLoader() { defaultpath = new Vector(); defaultpath.addElement("bond.core."); defaultpath.addElement("bond.services."); defaultpath.addElement("bond.agent."); defaultpath.addElement("bond.application.");

defaultpath.addElement("bond.application.TupleSpace.");

}

Page 3: Lecture 21 – April 4, 2002

3

/** Create object "name" with default constructor given "searchpath" */ public Object load(String name, Vector searchpaths) { Object o = null; Class cl; try { if ((cl = loadClass(name, searchpaths)) != null) { o = cl.newInstance(); } } catch(IllegalAccessException cnfe) { } catch(InstantiationException ie) { } return o; }

Page 4: Lecture 21 – April 4, 2002

4

/** Load a local class given its "name" */ public Class loadClass(String name, Vector

searchpaths) { String completename; for(int i=0; i!=searchpaths.size(); i++) { try { Class cl = Class.forName(makeName (name, (String)searchpaths.elementAt(i))); return cl; } catch(ClassNotFoundException cnfe) { } catch(Exception ex) { } }

Page 5: Lecture 21 – April 4, 2002

5

/** Load classes remotely */ if (cloader == null) {

String c_repository = System.getProperty ("bond.current.strategy.repository"); String repository = System.getProperty ("bond.strategy.repository"); if (c_repository != null && repository != null) { try { URL urlList[] = {new URL(c_repository), new URL(repository)}; cloader = new URLClassLoader(urlList); } catch (MalformedURLException e) { } } else if (repository != null) { try { URL urlList[] = {new URL (repository)}; cloader = new URLClassLoader(urlList); } catch (MalformedURLException e) { } } } for (int i = 0; i < searchpaths.size(); i++) { try { Class cl = Class.forName(makeName(name, (String)searchpaths.elementAt(i)), true,

cloader); return cl; } catch (ClassNotFoundException cnfe) { } catch(Exception ex) { } } return null; } }

Page 6: Lecture 21 – April 4, 2002

6

Communication

Multiple external message formats,

Multiple transport mechanism,

Dynamic collection of objects,

Make communication simple.

Page 7: Lecture 21 – April 4, 2002

7

SenderObject

ReceiverObject

Shadow

Communicator

Distributedawareness

Communicator

destination

content

subprotocol

source

piggyback

Distributedawareness

content

subprotocol

source

piggyback

Localdirectory

destination

Network

CommunicationEngine

Shadow

destination

message in KQMLor XML format

message in KQMLor XML format

CommunicationEngine

Page 8: Lecture 21 – April 4, 2002

8

Message delivery

CommunicationEngine

Resident

LocalDirectory

CommunicationEngine

Resident

LocalDirectoryObjectsObjects

Page 9: Lecture 21 – April 4, 2002

9

Internal message format

Internal format: unordered collection of name-value pairs implemented as dynamic properties of the bondMessage object.

The name is a string

The value can be any bondObject

Reserved names: Addressing variables (source, destination,…) Message identifiers Semantic identifiers (give the context of the message) Hidden variables (variables removed before delivery)

Page 10: Lecture 21 – April 4, 2002

10

External message representation

KQML

XML

Page 11: Lecture 21 – April 4, 2002

11

X Yask()

tell()

(a) (b)

X

MiddleAgent

Y

subscribe()

tell()

tell()

X

MiddleAgent

Y

recommend()

reply()

advertise()

(c)

X

MiddleAgent

Y

broker()

tell()

advertise()

(d)

ask() tell()

Page 12: Lecture 21 – April 4, 2002

12

Synchronous communication

ask() and waitReply()

ask() blocks the current thread, all other threads continue to run.

Page 13: Lecture 21 – April 4, 2002

13

bondMessage question = new bondMessage(``(ask-one : content get :value i :)'', ``PropertyAccess'');

bondMessage rep = bs.ask(question, this, 10000);

if (rep == null)

{

System.err.println(``Timeout of 10s exceeded'');

} else {

System.out.println(``Field i of remote object is''+

(String)rep.getParameter(``value''));

}

Page 14: Lecture 21 – April 4, 2002

14

bondMessage question = new bondMessage(``(ask-one

:content get :value i :)'', ``PropertyAccess'');

question.needsReply();

bs.say(question, this);

...

code executed before the reply

...

rep = question.waitReply(10000);

Page 15: Lecture 21 – April 4, 2002

15

Asynchronous communication

The sender object uses the ask performative with reply-with field to send an asynchronous message. The communicator creates a message waiting slot for the sender object and deposits there a copy of the original message and the unique ID of the reply. Eventually the receiver object replays using the tell performative.When processing incoming messages, the communicator checks the waiting slot table for the unique ID of the message and if a waiting slot exists, the communicator delivers the message to it.If the incoming messages has the on_reply field set then it is delivered directly, else it is delivered by the say() method.

Page 16: Lecture 21 – April 4, 2002

16

Network

ResidentResident

SenderObject

ReceiverObject

Replywaiting

slot

say

on_reply

ask

tell

sayfallback

createwaiting slot

Page 17: Lecture 21 – April 4, 2002

17

Event handlingA

Java Virtual Machine

B

C

D

E1

E2

(a)

X

Y

Z

(b)

Event ServiceX

Y

Z

E1

E2

A

B

C

DCORBA program CORBA program

Bond Resident

X

Y

Z

(c)

Bond Resident

A

B

C

D

E2

E1

EventWaiting

Slots

Page 18: Lecture 21 – April 4, 2002

18

Events/monitoring

An event could be the change of a property of a Bond object.

The set() function executed by the object being monitored notifies the monitor when a property subject to monitoring changes.

Page 19: Lecture 21 – April 4, 2002

19

Network

ResidentResident

MonitorObject

MonitoredObject Y

say

on_event

Subscribe to property x of object Y

tell

say

fallback

create eventwaiting slot Unsubscribe

property x of object Y

event waiting slot for x

set (x, val)Event waiting slots

Properties of object Y

Page 20: Lecture 21 – April 4, 2002

20

The communicator – the sending side

for(every sent message) if (external format) transform message in internal format annotate with the sender address if (reply needed) { annotate with a unique reply-with field create a reply waiting slot } if (performative is subscribe) create an event waiting slot if (performative is unsubscribe) delete the event waiting slot

if (need to send info to destination) annotate with the piggyback field pass the message to communicator engine

Page 21: Lecture 21 – April 4, 2002

21

The communicator – the receiving sidefor(every incoming message) parse message remove the piggyback field if any if (has in-reply-to field) and (in-reply-to field maches a reply waiting

slot) then { deliver to object waiting on the reply waiting slot delete the reply waiting slot } else if (performative is tell) and (sender maches an event waiting slot) then deliver to object waiting on the event waiting slot else lookup the destination object if (destination is alias) select an object with the alias at random else look up the object in local dir if (no object) { send error message to sender wake up a thread in the threadpool deliver the message using the thread } }

Page 22: Lecture 21 – April 4, 2002

22

Communication Engines

Multiple communication engines:TCPUDP Infospheres – based upon RMI IP multicast

Each communication engine has a deamon to send and receive messages using the specific communication engine.

Page 23: Lecture 21 – April 4, 2002

23

public class bondUDPDaemon extends bondObject { public bondUDPDaemon(int port) throws SocketException { super(false); udpSocket = new DatagramSocket(port); localport = port; } public int getLocalPort(){return localport;} public void send(InetAddress targetIP, int targetPort, String

m) { bufOut = m.getBytes(); udpOutPacket = new DatagramPacket(bufOut, bufOut.length, targetIP, targetPort); try{udpSocket.send(udpOutPacket);} catch(IOException e){} }

Page 24: Lecture 21 – April 4, 2002

24

public String receive() { try{ udpInPacket = new DatagramPacket(bufIn, 65535); udpSocket.receive(udpInPacket); InetAddress fromAddress = udpInPacket.getAddress(); fromHostname = fromAddress.getHostName(); fromPort = udpInPacket.getPort(); String mes = new String(udpInPacket.getData(), 0, udpInPacket.getLength()); return mes;} catch(IOException e){ return null; } }

Page 25: Lecture 21 – April 4, 2002

25

Sending an object – realize()

public void sendObject(bondShadow bs, bondObject bo, String in_reply_to) { bondExternalMessage bm = new bondExternalMessage(); bm.in_reply_to = in_reply_to; bm.bo = bo; String m = Base64.Object2String(bm); try{ InetAddress targetIP = InetAddress.getByName (bs.remote_address.ipaddress); bondUDPDaemon.send(targetIP, bs.remote_address.port,

m);} catch(UnknownHostException e){e.printStackTrace();} }

Page 26: Lecture 21 – April 4, 2002

26

Base 64 encoding

Take a 24 bit sequence from the source. If fewer than 24 bits are available use the "=" character for padding. Separate the sequence into 4 six bit characters. View each character as the lower 6 bits of an 8 bit character by padding it to the left with 00. With six bits one could encode 64 characters. Use each 8 bit character constructed in the previous as an index into the Base64 alphabet: "ABCDEFGHIJKLMNOPQSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="

Page 27: Lecture 21 – April 4, 2002

27

Virtual Networks of Objects

Resident A

Resident B

Resident C

X

Y

Z

W

xy

w

z

V

Virtual network of objects

multicast

Sender

Network