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

java.lang.Object
  extended by edu.memphis.ccrg.lida.framework.tasks.TaskSpawnerImpl
All Implemented Interfaces:
Initializable, TaskSpawner

public class TaskSpawnerImpl
extends java.lang.Object
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

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> initialTasks)
          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.lang.Object getParam(java.lang.String name, java.lang.Object defaultValue)
          A convenience method to read parameters from the Map of properties set with the init() method.
 java.util.Collection<FrameworkTask> getRunningTasks()
          Returns a UnmodifiableCollection that contains the FrameworkTasks in this TaskSpawner.
 void init()
          This is a convenience method to initialize this Object.
 void init(java.util.Map<java.lang.String,?> params)
          This method initializes the module with parameters specified in agent.xml
protected  void processResults(FrameworkTask task)
          When a finished Task is received and its status is 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 taskManager)
          Set the TaskManager this TaskSpawner will use to actually run the tasks.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 taskManager)
Description copied from interface: TaskSpawner
Set the TaskManager this TaskSpawner will use to actually run the tasks.

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

addTasks

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

Specified by:
addTasks in interface TaskSpawner
Parameters:
initialTasks - 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 finished Task is received and its status is FINISHED_WITH_RESULTS This method is called to handle the results.

Parameters:
task - the finished Task to process

getRunningTasks

public java.util.Collection<FrameworkTask> getRunningTasks()
Description copied from interface: TaskSpawner
Returns a UnmodifiableCollection that contains the FrameworkTasks in this TaskSpawner.

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

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 t's id

init

public void init(java.util.Map<java.lang.String,?> params)
Description copied from interface: Initializable
This method initializes the module with parameters specified in agent.xml

Specified by:
init in interface Initializable
Parameters:
params - Map of parameters indexed by String names

init

public void init()
Description copied from interface: Initializable
This is a convenience method to initialize this Object. It is called from init(Map parameters). Subclasses can overwrite this method in order to initialize this Object. But make sure to call super.init(); at the beginning of the implementation of this method.

Specified by:
init in interface Initializable

getParam

public java.lang.Object getParam(java.lang.String name,
                                 java.lang.Object defaultValue)
Description copied from interface: Initializable
A convenience method to read parameters from the Map of properties set with the init() method.

Specified by:
getParam in interface Initializable
Parameters:
name - the parameter name
defaultValue - the default value to be returned if the parameter doesn't exist.
Returns:
the value of the parameter or the default value.