Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.ibm.agletx.util
Class MessengerItinerary

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

All Implemented Interfaces:
  java.util.EventListener, MobilityListener, java.io.Serializable

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.

Version:
  1.20 $Date: 2001/07/28 06:33:36 $
Author:
  Yariv Aridor
See Also:
  Serialized Form

Fields inherited from class com.ibm.agletx.util.SeqItinerary
`aglet, currentTarget`

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, getCurrentTask, getOrigin, getOwnerAglet, getTaskAt, goToNext, handleException, handleTripException, indexOf, indexOf, isRepeat, onArrival, onTermination, removeTaskAt, setRepeat, size, startTrip`

Methods inherited from class com.ibm.aglet.event.MobilityAdapter
`onDispatching, onReverting`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### 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

### 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

### MessengerItinerary

    public MessengerItinerary(Aglet aglet,
                              java.lang.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

Method Detail

### addAglet

    public void addAglet(java.lang.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.

### getAgletAt

    public java.net.URL getAgletAt(int index)
                            throws java.io.IOException

  Return the URI of the aglet at the specified index. The URI is represented as

### getAglets

    public java.util.Enumeration getAglets()

  Return the enumeration of all the aglets to receive the broadcast message

### removeAglet

    public void removeAglet(int index)

  Remove an aglet from the plan at a specific index.
  Parameters:
    `index` - the index to remove.

### setMessage

    public void setMessage(Message msg)

  Set the message to be broadcast
  Parameters:
    `msg` - the message

### setMessage

    public void setMessage(java.lang.String msg)

  Set the message to be broadcast
  Parameters:
    `msg` - the message

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD