edu.mssm.crover.ims.tasks
Class TaskManager

java.lang.Object
  |
  +--edu.mssm.crover.ims.tasks.TaskManager

public class TaskManager
extends java.lang.Object

Manages the scheduling and execution of tasks by workers. Workers contact a TaskManager to obtain tasks. The manager maintains the consistency of the todo list, such that one task is successfully processed only one, all tasks are eventually processed or reported as failed. This is the direct interface. If you need to use task management services on a platform which is not supported by the database backend, see the RMI interface.

See Also:
TaskManagerTMIServer

Field Summary
static long ONE_DAY
           
static long ONE_HOUR
           
static long ONE_MINUTE
           
static long ONE_WEEK
           
 
Method Summary
 void acceptTask(Task task)
          Must be called when task is accepted by a worker.
 void completeTask(Task task, TaskResult result)
          Must be called when task is completed by a worker.
 void db_checkpoint()
          Checkpoints the transaction.
 void db_start()
          Sets the pause length.
 void db_start(java.lang.String name)
           
 void db_stop(boolean success)
           
 void db_stop(boolean success, java.lang.String name)
           
 boolean existsTask(java.lang.String taskid)
           
 void failTask(Task task, java.lang.Exception e)
          Must be called when a worker fails to complete a task.
 Task findTask(java.lang.String taskid)
           
 org.odmg.Implementation getImplementation()
          Returns the ODMG implementation.
static TaskManager getInstance()
           
 TaskStatus getStatus(java.lang.String taskid)
           
 TaskResult getTaskResult(java.lang.String taskid)
          Returns the result of a task.
 void init()
          Check that the TaskManager is initialized.
 boolean isTaskCompleted(java.lang.String taskid)
          Test if a task status is completed.
 boolean isTaskFailed(java.lang.String taskid)
          Test if a task status is failed.
 boolean isTaskSubmitted(java.lang.String taskid)
          Test if a task status has been submitted.
 void printPriorTasks(Task task)
           
 Task requestTask(AbstractWorker worker)
          Request a task.
 Task requestTask(java.lang.String[] worker_types)
           
 void reschedule()
          Reschedules tasks.
 void setReadyToStart(Task task)
          Notify the task manager that this task is now ready to start.
 void startTask(Task task)
          Must be called when task is started by a worker.
 java.lang.String submit(java.lang.String taskEngineClassName, TaskData data, long timeout)
          Submits a new task.
 java.lang.String submit(Task newtask)
          Submits a new task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ONE_WEEK

public static final long ONE_WEEK
See Also:
Constant Field Values

ONE_DAY

public static final long ONE_DAY
See Also:
Constant Field Values

ONE_HOUR

public static final long ONE_HOUR
See Also:
Constant Field Values

ONE_MINUTE

public static final long ONE_MINUTE
See Also:
Constant Field Values
Method Detail

submit

public java.lang.String submit(java.lang.String taskEngineClassName,
                               TaskData data,
                               long timeout)
Submits a new task.

Parameters:
taskEngineClassName - Name of the class for the TaskEngine that will process this class.
data - Instance of TaskData that contains the data used to initialize this task.
Returns:
task-id Task identifier used to inquire about the task after submission.

getImplementation

public org.odmg.Implementation getImplementation()
Returns the ODMG implementation.


submit

public java.lang.String submit(Task newtask)
Submits a new task. A task cannot be submitted twice. A second call to submit with the same task result in the taskID of the task being returned.

Parameters:
newtask - Task to be submitted.
Returns:
task-id Task identifier used to inquire about the task after submission.

printPriorTasks

public void printPriorTasks(Task task)

requestTask

public Task requestTask(AbstractWorker worker)
Request a task. Obtains a task which can be executed by this worker.

Returns:
The task, or null if no suitable task has been scheduled for execution. The task returned is locked for exclusive execution by the requesting worker. When a task which has been locked for more than a worker-specified amount of time (lockTimeout), the lock is released and the task can be attributed to another worker.

requestTask

public Task requestTask(java.lang.String[] worker_types)

getTaskResult

public TaskResult getTaskResult(java.lang.String taskid)
                         throws TaskNotFoundException
Returns the result of a task. After a task has completed, this method returns the result computed by the task. If the task has not yet completed, or has failed, this method return null.

Parameters:
taskid - Identifier of the task.
TaskNotFoundException

existsTask

public boolean existsTask(java.lang.String taskid)

findTask

public Task findTask(java.lang.String taskid)

getStatus

public TaskStatus getStatus(java.lang.String taskid)

db_start

public void db_start(java.lang.String name)

db_stop

public void db_stop(boolean success,
                    java.lang.String name)

db_checkpoint

public void db_checkpoint()
Checkpoints the transaction.


db_start

public void db_start()
Sets the pause length. Pause length is the amount of time that the worker waits (when no task has been obtained from the task manager), before it tries to get a task again.


db_stop

public void db_stop(boolean success)

getInstance

public static TaskManager getInstance()
                               throws DatabaseNotAvailableException
DatabaseNotAvailableException

init

public void init()
          throws DatabaseNotAvailableException
Check that the TaskManager is initialized. This includes checking the db schema and roots for task management: If the schema or roots are incomplete, this method performs the initialization.

DatabaseNotAvailableException

reschedule

public void reschedule()
Reschedules tasks. This method should be called periodically to allow the TaskManager to discover tasks which were not completed within their allowed execution window. When such tasks are discovered, they are rescheduled as freshly submitted tasks.


failTask

public void failTask(Task task,
                     java.lang.Exception e)
Must be called when a worker fails to complete a task.


completeTask

public void completeTask(Task task,
                         TaskResult result)
Must be called when task is completed by a worker.


startTask

public void startTask(Task task)
Must be called when task is started by a worker. Listeners are currently not notified of this change to the task status.


setReadyToStart

public void setReadyToStart(Task task)
Notify the task manager that this task is now ready to start. The status cannot be changed back later as a task which is ready to start can be started at any time.


acceptTask

public void acceptTask(Task task)
Must be called when task is accepted by a worker. Listeners are currently not notified of this change to the task status.


isTaskSubmitted

public boolean isTaskSubmitted(java.lang.String taskid)
Test if a task status has been submitted.


isTaskCompleted

public boolean isTaskCompleted(java.lang.String taskid)
                        throws TaskNotFoundException
Test if a task status is completed.

TaskNotFoundException

isTaskFailed

public boolean isTaskFailed(java.lang.String taskid)
                     throws TaskNotFoundException
Test if a task status is failed.

TaskNotFoundException


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