All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.ibm.agletx.util.SlaveItinerary

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

public class SlaveItinerary
extends SeqItinerary
An Itinerary class to repeatedly perform a specific task in multiple destinations.
Here is a typical usage of this class.
  private boolean lastTask = false;
  private SlaveItinerary itinerary  = null;
  class TaskA extends Task {
	public void execute(SeqItinerary itin) throws Exception {
	   // do some work
	}
  }
  class TaskB extends Task {
	public void execute(SeqItinerary itin) throws Exception {
	    // do some work
	}
  }
  public void onCreation(Object ini) {	
	    itinerary = new SlaveItinerary(this,"atp://yariv.trl.ibm.com",new TaskA());
            itinerary.addPlace("atp://tai.trl.ibm.com");
	    itinerary.startTrip();
   }
  public void run () {
	if (itinerary.atLastDestination()==true) {
	    if (lastTask==true) { 
		//  completed all tasks.
	    }
	    else {
		lastTask=true;
		itinerary.setTask(new TaskB());
		itinerary.startTrip();
	    }
	}
  }
 
The above code defines an aglet which performs 2-phase computation: in the first phase, the aglet travels among multiple destinations to perform a task defined by TaskA. Then, the second phase is started, in which the aglet visits again all these destinations to perform a task of TaskB.

In the above code, the invocation of itinerary.startTrip() causes the owner aglet to be dispatched sequentially among the destinations. In every destination, the execute() of the corresponding Task object (assigned to the SlaveItinerary object via setTask()) is automatically invoked.


Constructor Index

 o SlaveItinerary(Aglet, String, Task)
Constructor.
 o SlaveItinerary(Aglet, Vector, Task)
Constructor.

Method Index

 o addPlan(String)
Add a new address to the itinerary of the owner aglet
 o getTask()
Return the current task to be preformed by the owner aglet
 o setTask(Task)
Set the task to be preformed by the owner aglet

Constructors

 o SlaveItinerary
 public SlaveItinerary(Aglet aglet,
                       String address,
                       Task task)
Constructor.

Parameters:
aglet - the owner aglet
task - the task to preform
address - an address where the task should be preformed
 o SlaveItinerary
 public SlaveItinerary(Aglet aglet,
                       Vector addresses,
                       Task task)
Constructor.

Parameters:
aglet - the owner aglet
task - the task to preform
addresses - a vector of address where the task should be performed.

Methods

 o addPlan
 public void addPlan(String address)
Add a new address to the itinerary of the owner aglet

 o getTask
 public Task getTask()
Return the current task to be preformed by the owner aglet

 o setTask
 public void setTask(Task task)
Set the task to be preformed by the owner aglet


All Packages  Class Hierarchy  This Package  Previous  Next  Index