edu.mssm.crover.ims.tasks
Class Task

java.lang.Object
  |
  +--edu.mssm.crover.ims.tasks.Task
All Implemented Interfaces:
TaskControl, TaskListener
Direct Known Subclasses:
GroupOfTasks

public class Task
extends java.lang.Object
implements TaskControl, TaskListener

Abstract Task. Encapsulates the interaction with the TaskManager. Subclasses are expected to specialize the processing for specific tasks.


Field Summary
protected  TaskData data
          Data required for this task to be processed.
protected  org.odmg.DSet priorTasks
          This task cannot start before the prior task have succeeded or failed.
protected  TaskStatus status
           
protected  java.lang.String taskID
          Unique identifier for this class.
protected  java.lang.String taskType
          Type of this task.
protected  TaskManager tm
           
 
Constructor Summary
Task(TaskManager tm, long timeout)
          Creates a new task.
 
Method Summary
 void abnormalTermination(java.lang.Exception e)
          The task abnormally terminated.
 void addListener(TaskListener listener)
           
 void addPriorTask(Task priortask)
           
 TaskData getData()
           
 java.util.Collection getPriorTasks()
           
 TaskStatus getStatus()
           
 java.lang.String getTaskID()
           
 java.lang.String getTaskType()
           
 long getTimeout()
           
protected  void installEngine()
          Installs the TaskEngine.
 boolean isReadyToStart()
          Returns whether the task is ready to start.
 void normalTermination(TaskResult tr)
          The task normally terminated.
 void notifyListeners()
           
 boolean priorTasksDone()
          Returns true when priorTasks are done (either failed or complete).
 void process()
          Delegates the processing to the taskEngine.
 void removeListener(TaskListener listener)
           
 void removePriorTask(Task priortask)
           
 void setData(TaskData data)
          Sets the data that this task will use when processed.
protected  void setTaskID(java.lang.String taskid)
           
 void setTaskType(java.lang.String tasktype)
           
 void start()
          Starts execution of the task.
 void statusChanged(java.lang.String taskid, TaskStatus newstatus)
          The status of a task has just changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

taskID

protected java.lang.String taskID
Unique identifier for this class.


taskType

protected java.lang.String taskType
Type of this task. This is the classname of the TaskEngine which know how to execute this task.


priorTasks

protected org.odmg.DSet priorTasks
This task cannot start before the prior task have succeeded or failed. To achieve this constraint, this task listens on the status of previous tasks. The task's canStart property is false when priorTasks contains at least one task.


status

protected TaskStatus status

tm

protected transient TaskManager tm

data

protected TaskData data
Data required for this task to be processed. All data instances should be serializable.

Constructor Detail

Task

public Task(TaskManager tm,
            long timeout)
Creates a new task. The task will fail after timeout minutes have ellapsed between the time the task has been started and the task has completed.

Method Detail

setTaskID

protected void setTaskID(java.lang.String taskid)

getStatus

public TaskStatus getStatus()

getTimeout

public long getTimeout()

getTaskType

public java.lang.String getTaskType()

getPriorTasks

public java.util.Collection getPriorTasks()

addPriorTask

public void addPriorTask(Task priortask)

removePriorTask

public void removePriorTask(Task priortask)

getData

public TaskData getData()

isReadyToStart

public boolean isReadyToStart()
Returns whether the task is ready to start. A task manager will not provide workers with tasks unless they are ready to start. A task should return false if its execution should start only after some other task has been completed. When a task determines that it is now ready to start, it should invoke setReadyToStart(this) on the task manager. The task manager will NOT call this method to check after submission time. This means that the task needs to rely upon some mechanism to be notified when the conditions which determine if it can start are met.


statusChanged

public void statusChanged(java.lang.String taskid,
                          TaskStatus newstatus)
The status of a task has just changed. We are notified of the new status and the identity of the task that experienced the change. This default implementation records the status changes of priorTasks.

Specified by:
statusChanged in interface TaskListener

setData

public void setData(TaskData data)
Sets the data that this task will use when processed.

See Also:
TaskData

normalTermination

public void normalTermination(TaskResult tr)
Description copied from interface: TaskControl
The task normally terminated. This method should be called by a worker when a task has terminated properly.

Specified by:
normalTermination in interface TaskControl
See Also:
TaskControl.normalTermination(TaskResult tr)

installEngine

protected void installEngine()
                      throws java.lang.ClassNotFoundException,
                             java.lang.InstantiationException,
                             java.lang.IllegalAccessException
Installs the TaskEngine. (Instantiate it.)

java.lang.ClassNotFoundException
java.lang.InstantiationException
java.lang.IllegalAccessException

addListener

public void addListener(TaskListener listener)

removeListener

public void removeListener(TaskListener listener)

abnormalTermination

public void abnormalTermination(java.lang.Exception e)
Description copied from interface: TaskControl
The task abnormally terminated. This method should be called by a worker when a task has not terminated properly.

Specified by:
abnormalTermination in interface TaskControl
See Also:
TaskControl.abnormalTermination(Exception e)

start

public void start()
Starts execution of the task.


process

public void process()
Delegates the processing to the taskEngine.

See Also:
TaskEngine

notifyListeners

public void notifyListeners()

priorTasksDone

public boolean priorTasksDone()
Returns true when priorTasks are done (either failed or complete). False otherwise.


getTaskID

public java.lang.String getTaskID()

setTaskType

public void setTaskType(java.lang.String tasktype)


Copyright @ 2003 Mount Sinai School of Medicine. All Rights Reserved.