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
-
SeqPlanItinerary(Aglet)
- Constructs a SeqPlanItinerary object with the specified owner aglet.
-
addPlan(String, Message)
- Adds the new plan item specified by a pair of a address and a message.
-
addPlan(String, String)
- Adds the new plan item specified by a pair of a address and a message.
-
clearPlan()
- Clears the whole plan.
-
getAddressAt(int)
- Returns the address at the specified index.
-
getMessageAt(int)
- Returns the message at the specified index.
-
goToNext()
- Go to the next address and perform the next message at the
destination address.
-
handleMessage(Message)
- Handles the message.
-
insertPlanAt(String, Message, int)
- Inserts the new plan item specified by a pair of a address and
a message at the specified index.
-
insertPlanAt(String, String, int)
- Inserts the new plan item specified by a pair of a address and
a message at the specified index.
-
isRepeat()
- Checks if the itinerary is repeatition plan.
-
onArrival(MobilityEvent)
- This is not normally used by aglets programmers.
-
removePlanAt(int)
- Removes the plan specified by the index.
-
setRepeat(boolean)
- Conditionally enables a repetition.
-
size()
- Returns the size of this plan
-
startTrip()
- Starts the trip defined in this itineray
SeqPlanItinerary
public SeqPlanItinerary(Aglet aglet)
- Constructs a SeqPlanItinerary object with the specified owner aglet.
- Parameters:
- aglet - the owner aglet
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.
isRepeat
public boolean isRepeat()
- Checks if the itinerary is repeatition plan.
size
public int size()
- Returns the size of this plan
getAddressAt
public String getAddressAt(int index)
- Returns the address at the specified index.
getMessageAt
public Message getMessageAt(int index)
- Returns the message at the specified index.
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
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
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
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
removePlanAt
public synchronized void removePlanAt(int index)
- Removes the plan specified by the index.
- Parameters:
- index - the index to remove.
clearPlan
public synchronized void clearPlan()
- Clears the whole plan.
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.
goToNext
public boolean goToNext()
- Go to the next address and perform the next message at the
destination address.
startTrip
public void startTrip() throws IOException, AgletException
- Starts the trip defined in this itineray
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