All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.ibm.agletx.util.MessengerItinerary

java.lang.Object
   |
   +----com.ibm.aglet.event.MobilityAdapter
           |
           +----com.ibm.agletx.util.SeqItinerary
                   |
                   +----com.ibm.agletx.util.MessengerItinerary

public class MessengerItinerary
extends SeqItinerary
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 Index

 o MessengerItinerary(Aglet)
Construct a MessengerItinerary object with a specified owner aglet The message should be explicitly set by the setMessage()
 o MessengerItinerary(Aglet, Message)
Construct a MessengerItinerary object with the specified owner aglet and a message to broadcast.
 o MessengerItinerary(Aglet, String)
Construct a MessengerItinerary object with the specified owner aglet and a message to broadcast.

Method Index

 o addAglet(String, AgletID)
Add a new item [address, aglet id] to the itinerary.
 o getAgletAt(int)
Return the URI of the aglet at the specified index.
 o getAglets()
Return the enumeration of all the aglets to receive the broadcast message
 o removeAglet(int)
Remove an aglet from the plan at a specific index.
 o setMessage(Message)
Set the message to be broadcast
 o setMessage(String)
Set the message to be broadcast

Constructors

 o MessengerItinerary
 public MessengerItinerary(Aglet aglet,
                           Message msg)
Construct a MessengerItinerary object with the specified owner aglet and a message to broadcast.

Parameters:
aglet - the owner aglet
msg - the message to be broadcasted
 o MessengerItinerary
 public MessengerItinerary(Aglet aglet)
Construct a MessengerItinerary object with a specified owner aglet The message should be explicitly set by the setMessage()

Parameters:
aglet - the owner aglet
 o MessengerItinerary
 public MessengerItinerary(Aglet aglet,
                           String msg)
Construct a MessengerItinerary object with the specified owner aglet and a message to broadcast.

Parameters:
aglet - the owner aglet
msg - the message to br broadcasted

Methods

 o getAgletAt
 public synchronized URL getAgletAt(int index) throws IOException
Return the URI of the aglet at the specified index. The URI is represented as
+ '#' + .

Parameters:
index - the specified index.
 o addAglet
 public synchronized void addAglet(String address,
                                   AgletID id)
Add a new item [address, aglet id] to the itinerary.

Parameters:
address - the address of the aglet.
id - the id of the aglet.
 o getAglets
 public Enumeration getAglets()
Return the enumeration of all the aglets to receive the broadcast message

 o removeAglet
 public synchronized void removeAglet(int index)
Remove an aglet from the plan at a specific index.

Parameters:
index - the index to remove.
 o setMessage
 public void setMessage(Message msg)
Set the message to be broadcast

Parameters:
msg - the message
 o setMessage
 public void setMessage(String msg)
Set the message to be broadcast

Parameters:
msg - the message

All Packages  Class Hierarchy  This Package  Previous  Next  Index