|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--com.ibm.aglet.event.MobilityAdapter
|
+--com.ibm.agletx.util.SeqItinerary
|
+--com.ibm.agletx.util.MessengerItinerary
An Itinerary class to broadcast a message to remote aglets. The message
is carried by a messenger aglet which visits the hosts
of the receiver aglets to send them the message, locally.
The following code segment shows a typical usage of this class.
public MessengerAglet extends Aglet {
MessengerItinerary itinerary;
Message message = new Message("test",null); // the message to broadcast
String receivers[] = .... // URIs of receiver aglets.
class MessengerItineraryx extends MessengerItinerary {
AgletProxy sender = null;
public MessengerItineraryx (Aglet aglet, Message msg, AgletProxy sender) {
super(aglet,msg);
this.sender=sender;
}
public void handleException (Throwable th) {
try {
sender.sendMessage(new Message("ack",th));
} catch (Exception ex) {
ex.printStackTrace();
}
th.printStackTrace();
}
}
public void onCreation(Object ini) {
AgletProxy sender = (AgletProxy)ini;
itinerary=new MessengerItineraryx(this,message,sender);
for (<every receiver in receivers[]>) {
itinerary.addAglet(<location of a receiver>,<ID of a receiver>);
}
itinerary.startTrip();
}
}
The above code defines the messenger aglet. Unlike one-way messaging, the
messenger aglet notifies its owner aglet (i.e. the creator aglet) in case
any of the receiver aglets can not be located.
In the code, the message to broadcast and the receiver aglets are saved
in the message and receivers instance variables,
respectivally. The MessangerItineraryx subclass overrides the
handleException() to notifies the creator aglet (via the message
Message("ack",ex)) of any exceptions encountered by the messenger
aglet. The invocation of itinerary.startTrip() causes the
messenger aglet to start its trip among the hosts of the receiver aglets.
| Constructor Summary | |
MessengerItinerary(Aglet aglet)
Construct a MessengerItinerary object with a specified owner aglet The message should be explicitly set by the setMessage() |
|
MessengerItinerary(Aglet aglet,
Message msg)
Construct a MessengerItinerary object with the specified owner aglet and a message to broadcast. |
|
MessengerItinerary(Aglet aglet,
java.lang.String msg)
Construct a MessengerItinerary object with the specified owner aglet and a message to broadcast. |
|
| Method Summary | |
void |
addAglet(java.lang.String address,
AgletID id)
Add a new item [address, aglet id] to the itinerary. |
java.net.URL |
getAgletAt(int index)
Return the URI of the aglet at the specified index. |
java.util.Enumeration |
getAglets()
Return the enumeration of all the aglets to receive the broadcast message |
void |
removeAglet(int index)
Remove an aglet from the plan at a specific index. |
void |
setMessage(Message msg)
Set the message to be broadcast |
void |
setMessage(java.lang.String msg)
Set the message to be broadcast |
| Methods inherited from class com.ibm.agletx.util.SeqItinerary |
addAddress,
addresses,
addTask,
atLastDestination,
clear,
getAddressAt,
getCurrentAddress,
getOrigin,
getOwnerAglet,
getTaskAt,
goToNext,
handleException,
handleTripException,
indexOf,
indexOf,
isRepeat,
onArrival,
removeTaskAt,
setRepeat,
size,
startTrip |
| Methods inherited from class com.ibm.aglet.event.MobilityAdapter |
onDispatching,
onReverting |
| Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Constructor Detail |
public MessengerItinerary(Aglet aglet,
Message msg)
aglet - the owner agletmsg - the message to be broadcastedpublic MessengerItinerary(Aglet aglet)
aglet - the owner aglet
public MessengerItinerary(Aglet aglet,
java.lang.String msg)
aglet - the owner agletmsg - the message to br broadcasted| Method Detail |
public java.net.URL getAgletAt(int index)
throws java.io.IOException
index - the specified index.
public void addAglet(java.lang.String address,
AgletID id)
address - the address of the aglet.id - the id of the aglet.public java.util.Enumeration getAglets()
public void removeAglet(int index)
index - the index to remove.public void setMessage(Message msg)
msg - the messagepublic void setMessage(java.lang.String msg)
msg - the message
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||