Class aglet.util.SeqPlanItinerary
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class aglet.util.SeqPlanItinerary

java.lang.Object
   |
   +----aglet.event.MobilityAdapter
           |
           +----aglet.util.SeqPlanItinerary

public class SeqPlanItinerary
extends MobilityAdapter
implements Serializable
SeqPlanItinerary defines the trip plan which has a sequence of place-message pair. For example, the plan defined like:
  itinerary.addPlan("atp://first", "job1");
  itinerary.addPlan("atp://second", "job2");
first dispatches an aglet to the "atp://first" and sends new Message("job1") message to the aglet. After that message handling is completed, the itinerary dispatches the aglet to the next address, "atp://second" , and send the corresponding message new Message("job2", init) to the aglet again. The order of plan is defined in the order addPlan method is called, or you can insert a new plan item at the specified index by calling insertPlanAt . To automatically dispatches an aglet to the next address when the job is completed, the aglet have to have the following block
   boolean handleMessage(Message msg) {
       if (itinerary.handleMessage(msg)) {
           return true;
       }
       ...
   }
in the handleMessage() method. Here is a full example which make use of the SeqPlanItinerary class.
  SeqPlanItinerary itinerary;
  public void onCreation(Object init) {
  	itinerary = new SeqPlanItinerary(this);
     itinerary.addPlan("atp://first",  "job1");
     itinerary.addPlan("atp://second", new Message("job2", init));
     itinerary.addPlan("atp://thrid",  "job1");
     itinerary.addPlan("atp://fourth", "end");
     itinerary.startTrip();
  }
  public boolean handleMessage(Message msg) {
      if (itinerary.handleMessage(msg)) {
	     return true; // itinerary has handled the message
      } else if (msg.sameKind("job1")) {
          // do job1.
          // This will be called at "atp://first" and "atp://thrid".
      } else if (msg.sameKind("job2")) {
          // do job2. This will be called at "atp://second".
          Object obj = msg.getArg(); // returns init value given in the
                                     // onCreation method.
      } else if (msg.sameKind("end")) {
          printResult();
          dispose();
      } else return false;
      return true;
  }
See Also:
handleMessage

Constructor Index

 o SeqPlanItinerary(Aglet)
Constructs a SeqPlanItinerary object with the specified owner aglet.

Method Index

 o addPlan(String, Message)
Adds the new plan item specified by a pair of a address and a message.
 o addPlan(String, String)
Adds the new plan item specified by a pair of a address and a message.
 o clearPlan()
Clears the whole plan.
 o getAddressAt(int)
Returns the address at the specified index.
 o getMessageAt(int)
Returns the message at the specified index.
 o goToNext()
Go to the next address and perform the next message at the destination address.
 o handleMessage(Message)
Handles the message.
 o insertPlanAt(String, Message, int)
Inserts the new plan item specified by a pair of a address and a message at the specified index.
 o insertPlanAt(String, String, int)
Inserts the new plan item specified by a pair of a address and a message at the specified index.
 o isRepeat()
Checks if the itinerary is repeatition plan.
 o onArrival(MobilityEvent)
This is not normally used by aglets programmers.
 o removePlanAt(int)
Removes the plan specified by the index.
 o setRepeat(boolean)
Conditionally enables a repetition.
 o size()
Returns the size of this plan
 o startTrip()
Starts the trip defined in this itineray

Constructors

 o SeqPlanItinerary
  public SeqPlanItinerary(Aglet aglet)
Constructs a SeqPlanItinerary object with the specified owner aglet.
Parameters:
aglet - the owner aglet

Methods

 o setRepeat
  public void setRepeat(boolean b)
Conditionally enables a repetition. If true, the index of plan is set to 0 when it reaches to the end of plan.
Parameters:
b - if true, repeats the plan; doesn't otherwise.
 o isRepeat
  public boolean isRepeat()
Checks if the itinerary is repeatition plan.
 o size
  public int size()
Returns the size of this plan
 o getAddressAt
  public String getAddressAt(int index)
Returns the address at the specified index.
 o getMessageAt
  public Message getMessageAt(int index)
Returns the message at the specified index.
 o addPlan
  public synchronized void addPlan(String address,
                                   Message msg)
Adds the new plan item specified by a pair of a address and a message. This is added at the end of plan.
Parameters:
address - the address to go
msg - the message to be sent to the owner aglet
 o addPlan
  public void addPlan(String address,
                      String msg)
Adds the new plan item specified by a pair of a address and a message. This is added at the end of plan.
Parameters:
address - the address to go
msg - the message to be sent to the owner aglet
 o insertPlanAt
  public synchronized void insertPlanAt(String address,
                                        Message msg,
                                        int index)
Inserts the new plan item specified by a pair of a address and a message at the specified index.
Parameters:
address - the address to go
msg - the message to be sent to the owner aglet
index - the index
 o insertPlanAt
  public void insertPlanAt(String address,
                           String msg,
                           int index)
Inserts the new plan item specified by a pair of a address and a message at the specified index.
Parameters:
address - the address to go
msg - the message to be sent to the owner aglet
index - the index
 o removePlanAt
  public synchronized void removePlanAt(int index)
Removes the plan specified by the index.
Parameters:
index - the index to remove.
 o clearPlan
  public synchronized void clearPlan()
Clears the whole plan.
 o handleMessage
  public boolean handleMessage(Message msg)
Handles the message. SeqPlanItinerary object only handles "goToNext" message.
Returns:
dispatches the aglet if the message is "goToNext", return false otherwise.
 o goToNext
  public boolean goToNext()
Go to the next address and perform the next message at the destination address.
 o startTrip
  public void startTrip() throws IOException, AgletException
Starts the trip defined in this itineray
 o onArrival
  public void onArrival(MobilityEvent ev)
This is not normally used by aglets programmers.
Overrides:
onArrival in class MobilityAdapter

All Packages  Class Hierarchy  This Package  Previous  Next  Index