edu.memphis.ccrg.lida.framework.tasks
Class TaskSpawnerImpl

java.lang.Object
  extended by edu.memphis.ccrg.lida.framework.initialization.InitializableImpl
      extended by edu.memphis.ccrg.lida.framework.tasks.TaskSpawnerImpl
All Implemented Interfaces:
Initializable, TaskSpawner
Direct Known Subclasses:
RandomizingTaskSpawner

public class TaskSpawnerImpl
extends InitializableImpl
implements TaskSpawner

Maintains a queue of running tasks and their task status. Methods to add and cancel tasks. This implementation actually uses TaskManager to execute the tasks.

Author:
Javier Snaider, Ryan J. McCall

Constructor Summary
TaskSpawnerImpl()
          This default constructor is used by the AgentXmlFactory.
TaskSpawnerImpl(TaskManager tm)
          Convenience constructor that sets the TaskManager
 
Method Summary
 void addTask(FrameworkTask task)
          Adds and runs supplied FrameworkTask.
 void addTasks(java.util.Collection<? extends FrameworkTask> tasks)
          Adds and runs supplied FrameworkTasks.
 boolean cancelTask(FrameworkTask task)
          Cancels specified task if it exists in this TaskSpawner Task is removed from TaskSpawner and canceled in the TaskManager.
 boolean containsTask(FrameworkTask task)
          Returns whether this TaskSpawner manages this task.
 java.util.Collection<FrameworkTask> getRunningTasks()
          Deprecated. 
 java.util.Collection<FrameworkTask> getTasks()
          Returns the FrameworkTask objects controlled by this TaskSpawner.
protected  void processResults(FrameworkTask task)
          When a FrameworkTask has completed one execution and its status is TaskStatus.FINISHED_WITH_RESULTS this method is called to handle the results.
 void receiveFinishedTask(FrameworkTask task)
          This method receives a task that has finished.
 void setTaskManager(TaskManager tm)
          Set the TaskManager this TaskSpawner will use to actually run the tasks.
 
Methods inherited from class edu.memphis.ccrg.lida.framework.initialization.InitializableImpl
containsParameter, getParam, getParameters, init, init
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.memphis.ccrg.lida.framework.initialization.Initializable
containsParameter, getParam, getParameters, init, init
 

Constructor Detail

TaskSpawnerImpl

public TaskSpawnerImpl()
This default constructor is used by the AgentXmlFactory. TaskManager must be set using TaskSpawner.setTaskManager(TaskManager)


TaskSpawnerImpl

public TaskSpawnerImpl(TaskManager tm)
Convenience constructor that sets the TaskManager

Parameters:
tm - the TaskManager to set
Method Detail

setTaskManager

public void setTaskManager(TaskManager tm)
Description copied from interface: TaskSpawner
Set the TaskManager this TaskSpawner will use to actually run the tasks.

Specified by:
setTaskManager in interface TaskSpawner
Parameters:
tm - the TaskManager of the system.

addTasks

public void addTasks(java.util.Collection<? extends FrameworkTask> tasks)
Description copied from interface: TaskSpawner
Adds and runs supplied FrameworkTasks.

Specified by:
addTasks in interface TaskSpawner
Parameters:
tasks - a collection of tasks to be run.

addTask

public void addTask(FrameworkTask task)
Description copied from interface: TaskSpawner
Adds and runs supplied FrameworkTask.

Specified by:
addTask in interface TaskSpawner
Parameters:
task - the task to add.

receiveFinishedTask

public void receiveFinishedTask(FrameworkTask task)
Description copied from interface: TaskSpawner
This method receives a task that has finished. TaskSpawners can choose what to do with the FrameworkTask each time it finishes running. Generally the FrameworkTask's TaskStatus determines this action.

Specified by:
receiveFinishedTask in interface TaskSpawner
Parameters:
task - finished FrameworkTask

processResults

protected void processResults(FrameworkTask task)
When a FrameworkTask has completed one execution and its status is TaskStatus.FINISHED_WITH_RESULTS this method is called to handle the results.

Parameters:
task - the task to be processed

cancelTask

public boolean cancelTask(FrameworkTask task)
Description copied from interface: TaskSpawner
Cancels specified task if it exists in this TaskSpawner Task is removed from TaskSpawner and canceled in the TaskManager. This is only possible if the tick for which the task is scheduled has not been reached.

Specified by:
cancelTask in interface TaskSpawner
Parameters:
task - The task to cancel.
Returns:
true if the task was canceled, false otherwise
See Also:
TaskManager.cancelTask(FrameworkTask)

containsTask

public boolean containsTask(FrameworkTask task)
Description copied from interface: TaskSpawner
Returns whether this TaskSpawner manages this task.

Specified by:
containsTask in interface TaskSpawner
Parameters:
task - a FrameworkTask
Returns:
true if this TaskSpawner contains a task with task's id

getRunningTasks

@Deprecated
public java.util.Collection<FrameworkTask> getRunningTasks()
Deprecated. 

Description copied from interface: TaskSpawner
Returns a UnmodifiableCollection that contains the FrameworkTasks in this TaskSpawner. Tasks' TaskStatus may or may not be running. Use TaskSpawner.getTasks() instead.

Specified by:
getRunningTasks in interface TaskSpawner
Returns:
collection of running tasks.

getTasks

public java.util.Collection<FrameworkTask> getTasks()
Description copied from interface: TaskSpawner
Returns the FrameworkTask objects controlled by this TaskSpawner.

Specified by:
getTasks in interface TaskSpawner
Returns:
a Collection FrameworkTasks.