com.atlassian.jira.task
Class TaskManagerImpl

java.lang.Object
  extended by com.atlassian.jira.task.TaskManagerImpl
All Implemented Interfaces:
TaskManager

public class TaskManagerImpl
extends Object
implements TaskManager

An implementation of a TaskManager. This manager uses an ExecutorService to run submitted tasks.

Since:
3.13

Constructor Summary
TaskManagerImpl(JiraAuthenticationContext authenticationContext)
           
TaskManagerImpl(JiraAuthenticationContext authenticationContext, ExecutorService executorService)
           
 
Method Summary
 boolean awaitUntilActiveTasksComplete(long seconds)
          Waits on the TaskManager until all current active tasks are completed.
 TaskDescriptor<?> findFirstTask(TaskMatcher matcher)
          Find the first task that "matches" according to the passed matcher.
 Collection<TaskDescriptor<?>> findTasks(TaskMatcher matcher)
          Find all the tasks that "match" according to the passed matcher.
 Collection<TaskDescriptor<?>> getAllTasks()
          Return a collection of TaskDescriptors currently within the manager.
<V> TaskDescriptor<V>
getLiveTask(TaskContext taskContext)
          Return the live task associated with the passed context, if one exists.
 Collection<TaskDescriptor<?>> getLiveTasks()
          Return a collection of sumitted or running TaskDescriptors in the manager.
<V> TaskDescriptor<V>
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.
<V> TaskDescriptor<V>
submitTask(Callable<V> 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskManagerImpl

public TaskManagerImpl(JiraAuthenticationContext authenticationContext)

TaskManagerImpl

public TaskManagerImpl(JiraAuthenticationContext authenticationContext,
                       ExecutorService executorService)
Method Detail

submitTask

public <V> TaskDescriptor<V> submitTask(@NotNull
                                        Callable<V> callable,
                                        @NotNull
                                        String taskDescription,
                                        @NotNull
                                        TaskContext taskContext)
                             throws RejectedExecutionException,
                                    AlreadyExecutingException
Description copied from interface: TaskManager
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.

Specified by:
submitTask in interface TaskManager
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:
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

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

Specified by:
removeTask in interface TaskManager
Parameters:
taskId - the task identifier.
Returns:
true if the task was removed or false otherwise.

shutdownAndWait

public boolean shutdownAndWait(long waitSeconds)
Description copied from interface: TaskManager
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.

Specified by:
shutdownAndWait in interface TaskManager
Parameters:
waitSeconds - the numder of seconds to wait for graceful shutdown.
Returns:
true if the underlying execution threads have terminated completely.

shutdownNow

public void shutdownNow()
Description copied from interface: TaskManager
Attempts to aggressively stop all actively executing tasks, halts the processing of waiting tasks.

Specified by:
shutdownNow in interface TaskManager

awaitUntilActiveTasksComplete

public boolean awaitUntilActiveTasksComplete(long seconds)
Description copied from interface: TaskManager
Waits on the TaskManager until all current active tasks are completed. Calling this method does not stop tasks being added.

Specified by:
awaitUntilActiveTasksComplete in interface TaskManager
Parameters:
seconds - the number of seconds to wait.
Returns:
true if all the active tasks are completed before the timeout, false otherwise.

getLiveTask

public <V> TaskDescriptor<V> getLiveTask(@NotNull
                                         TaskContext taskContext)
Description copied from interface: TaskManager
Return the live task associated with the passed context, if one exists.

Specified by:
getLiveTask in interface TaskManager
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

public <V> TaskDescriptor<V> getTask(Long taskId)
Description copied from interface: TaskManager
Returns the TaskDescriptor of the task that is identified by the passed id.

Specified by:
getTask in interface TaskManager
Parameters:
taskId - the id of the task to retrieve, if null then null will be returned
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.

hasLiveTaskWithContext

public boolean hasLiveTaskWithContext(@NotNull
                                      TaskContext taskContext)
Description copied from interface: TaskManager
Returns true if the there are live tasks (running or submitted) that have a task context that is EQUAL to the passed in taskContext.

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

hasTaskWithContext

public boolean hasTaskWithContext(@NotNull
                                  TaskContext taskContext)
Description copied from interface: TaskManager
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.

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

findFirstTask

public TaskDescriptor<?> findFirstTask(@NotNull
                                       TaskMatcher matcher)
Description copied from interface: TaskManager
Find the first task that "matches" according to the passed matcher.

Specified by:
findFirstTask in interface TaskManager
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

public Collection<TaskDescriptor<?>> findTasks(TaskMatcher matcher)
Description copied from interface: TaskManager
Find all the tasks that "match" according to the passed matcher.

Specified by:
findTasks in interface TaskManager
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.

getAllTasks

public Collection<TaskDescriptor<?>> getAllTasks()
Description copied from interface: TaskManager
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.

Specified by:
getAllTasks in interface TaskManager
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

public Collection<TaskDescriptor<?>> getLiveTasks()
Description copied from interface: TaskManager
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.

Specified by:
getLiveTasks in interface TaskManager
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.


Copyright © 2002-2012 Atlassian. All Rights Reserved.