com.atlassian.jira.task
Interface TaskManager

All Known Implementing Classes:
TaskManagerImpl

public interface TaskManager

The TaskManager contains a collection of tasks that are long running. It schedules them to run at its discretion, but it does try to run them as soon as possible, assuming there is sufficient resources available.

Tasks are described operationally by TaskDescriptor.

NOTE: All task descriptors returned are a snapshot of the task state when the method returns. So while the task may finish, the TaskDescriptor will not be updated to relect that. You must always re-ask the TaskManager for a new TaskDecriptor to find out if a task has finished or not.

Since:
v3.13

Method Summary
 TaskDescriptor findFirstTask(TaskMatcher matcher)
          Find the first task that "matches" according to the passed matcher.
 Collection findTasks(TaskMatcher matcher)
          Find all the tasks that "match" according to the passed matcher.
 Collection getAllTasks()
          Return a collection of TaskDescriptors currently within the manager.
 TaskDescriptor getLiveTask(TaskContext taskContext)
          Return the live task associated with the passed context, if one exists.
 Collection getLiveTasks()
          Return a collection of sumitted or running TaskDescriptors in the manager.
 TaskDescriptor getTask(Long taskId)
          Returns the TaskDescriptor of the task that is identified by the passed id.
 boolean hasLiveTaskWithContext(TaskContext taskContext)
          Returns true if the there are live tasks (running or submitted) that have a task context that is EQUAL to the passed in taskContext.
 boolean hasTaskWithContext(TaskContext taskContext)
          Returns true if the there are any tasks (submitted, running or finished) that have a task context that is EQUAL to the passed in taskContext.
 boolean removeTask(Long taskId)
          Remove a task from the manager.
 boolean shutdownAndWait(long waitSeconds)
          Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
 void shutdownNow()
          Attempts to aggressively stop all actively executing tasks, halts the processing of waiting tasks.
 TaskDescriptor submitTask(edu.emory.mathcs.backport.java.util.concurrent.Callable callable, String taskDescription, TaskContext taskContext)
          This submits a Callable task to the manager which can then be started at the managers discretion, but hopefully very soon.
 

Method Detail

getAllTasks

Collection getAllTasks()
Return a collection of TaskDescriptors currently within the manager. This will include tasks that are yet to start, tasks that are running and completed tasks.

The returned collection is sorted by task id, which should be in addition order.

Returns:
a collection of TaskDescriptors. The descriptors returned are a snapshot of each task state when the method returns will not reflect any future changes. An empty collection is returned when there are no current tasks.

getLiveTasks

Collection getLiveTasks()
Return a collection of sumitted or running TaskDescriptors in the manager.

The returned collection is sorted by task id, which should be in addition order.

Returns:
a collection of running TaskDescriptors. The descriptors returned are a snapshot of each task state when the method returns and will not reflect any future changes. An empty collection is returned when there are no descriptors to return.

getLiveTask

TaskDescriptor getLiveTask(TaskContext taskContext)
Return the live task associated with the passed context, if one exists.

Parameters:
taskContext - the context to search for.
Returns:
currently live task associated with the passed context. The descriptor returned is a snapshot of the task state when the method returns will not reflect any future changes. null will be returned when no matching task can be found.

getTask

TaskDescriptor getTask(Long taskId)
Returns the TaskDescriptor of the task that is identified by the passed id.

Parameters:
taskId - the id of the task to retrieve
Returns:
a TaskDescriptor or null if the manager has not such task. The descriptor returned is a snapshot of the task state when the method returns will not reflect any future changes. null will be returned when no matching task can be found.

submitTask

TaskDescriptor submitTask(edu.emory.mathcs.backport.java.util.concurrent.Callable callable,
                          String taskDescription,
                          TaskContext taskContext)
                          throws edu.emory.mathcs.backport.java.util.concurrent.RejectedExecutionException,
                                 AlreadyExecutingException
This submits a Callable task to the manager which can then be started at the managers discretion, but hopefully very soon. The TaskDescriptor returned is a snapshot of the task's state when the method returns and will not change to reflect the task's future state changes. The task's ID can be found in the returned TaskDescriptor.

Parameters:
callable - the long running task
taskDescription - the description of the task
taskContext - some stateful context that the task knows about
Returns:
a TaskDescriptor for the new long running task. The returned descriptor is a snapshot of the task state when the method returns and will not reflect any future changes.
Throws:
edu.emory.mathcs.backport.java.util.concurrent.RejectedExecutionException - if the task manager is being shutdown and cannot accept new tasks.
AlreadyExecutingException - if a task with an equal TaskContext is already running in the task manager.

removeTask

boolean removeTask(Long taskId)
Remove a task from the manager. The task will still continue to execute if it has not already completed.

Parameters:
taskId - the task identifier.
Returns:
true if the task was removed or false otherwise.

shutdownAndWait

boolean shutdownAndWait(long waitSeconds)
Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted. It will wait for at most waitSeconds and then return true if the underlying execution threads are terminated completely.

Parameters:
waitSeconds - the numder of seconds to wait for graceful shutdown.
Returns:
true if the underlying execution threads have terminated completely.

shutdownNow

void shutdownNow()
Attempts to aggressively stop all actively executing tasks, halts the processing of waiting tasks.


hasTaskWithContext

boolean hasTaskWithContext(TaskContext taskContext)
Returns true if the there are any tasks (submitted, running or finished) that have a task context that is EQUAL to the passed in taskContext.

Parameters:
taskContext - the specific task context (which implements equals() propertly)
Returns:
true if there are any tasks with an equal task context

hasLiveTaskWithContext

boolean hasLiveTaskWithContext(TaskContext taskContext)
Returns true if the there are live tasks (running or submitted) that have a task context that is EQUAL to the passed in taskContext.

Parameters:
taskContext - the specific task context (which implements equals() propertly)
Returns:
true if there are any tasks with an equal task context

findFirstTask

TaskDescriptor findFirstTask(TaskMatcher matcher)
Find the first task that "matches" according to the passed matcher.

Parameters:
matcher - the condition used to find the task.
Returns:
the first task that "matches" according to the passed matcher. The descriptor returned is a snapshot of the task state when the method returns will not reflect any future changes. null will be returned when no matching task can be found.

findTasks

Collection findTasks(TaskMatcher matcher)
Find all the tasks that "match" according to the passed matcher.

Parameters:
matcher - the condition used to find the task.
Returns:
the tasks that "match" according to the passed matcher. The descriptors returned are a snapshot of the task state when the method returns will not reflect any future changes. An empty collection is returned when no tasks are matched.


Copyright © 2002-2008 Atlassian. All Rights Reserved.