Class DefaultLongRunningTaskManager
- java.lang.Object
-
- com.atlassian.confluence.util.longrunning.DefaultLongRunningTaskManager
-
- All Implemented Interfaces:
LongRunningTaskManagerInternal
,LongRunningTaskManager
,org.springframework.beans.factory.DisposableBean
,org.springframework.beans.factory.InitializingBean
@FieldsAreNonnullByDefault @ParametersAreNonnullByDefault @ReturnValuesAreNonnullByDefault public class DefaultLongRunningTaskManager extends Object implements LongRunningTaskManagerInternal, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
-
-
Constructor Summary
Constructors Constructor Description DefaultLongRunningTaskManager(PermissionManager permissionManager, ActivityMonitor activityMonitor, LongRunningTaskMonitor longRunningTaskMonitor, com.atlassian.event.api.EventListenerRegistrar eventListenerRegistrar)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
void
destroy()
PageResponse<LongTaskStatus>
getAllTasks(@Nullable ConfluenceUser asUser, LimitedRequest request)
Get all currently-tracked tasks that the specified user can see.@Nullable com.atlassian.core.task.longrunning.LongRunningTask
getLongRunningTask(@Nullable com.atlassian.user.User user, LongRunningTaskId taskId)
gets a long running task with the given Id that was registered either by this user or the anonymous user.int
getTaskCount()
Return a count of the current queued and running tasks.void
onApplicationStopped(com.atlassian.config.lifecycle.events.ApplicationStoppedEvent e)
LongRunningTaskId
queueLongRunningTask(com.atlassian.core.task.longrunning.LongRunningTask task)
Start tracking a long running task that should be started in a new thread whenLongRunningTaskManagerInternal.startIfQueued(com.atlassian.confluence.util.longrunning.LongRunningTaskId)
is called.List<LongTaskStatus>
removeComplete()
Remove completed tasks from the tracker.void
resume()
Resume accepting long-running tasks afterLongRunningTaskManager.stop(long, java.util.concurrent.TimeUnit)
has been called.void
runToCompletion(@Nullable com.atlassian.user.User user, com.atlassian.core.task.longrunning.LongRunningTask task)
Starts aLongRunningTask
and waits for it to complete.void
startIfQueued(LongRunningTaskId taskId)
Starts the task in a new thread if it has previously been queued.LongRunningTaskId
startLongRunningTask(@Nullable com.atlassian.user.User user, com.atlassian.core.task.longrunning.LongRunningTask task)
Start some task in a new threadvoid
stop(long timeout, TimeUnit unit)
Stop accepting new long running tasks.void
stopTrackingLongRunningTask(LongRunningTaskId taskId)
Clean up an old task.protected void
taskFinished(LongRunningTaskId taskId)
-
-
-
Constructor Detail
-
DefaultLongRunningTaskManager
public DefaultLongRunningTaskManager(PermissionManager permissionManager, ActivityMonitor activityMonitor, LongRunningTaskMonitor longRunningTaskMonitor, com.atlassian.event.api.EventListenerRegistrar eventListenerRegistrar)
- Since:
- 5.7
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet() throws Exception
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
-
onApplicationStopped
@EventListener public void onApplicationStopped(com.atlassian.config.lifecycle.events.ApplicationStoppedEvent e)
-
queueLongRunningTask
public LongRunningTaskId queueLongRunningTask(com.atlassian.core.task.longrunning.LongRunningTask task)
Description copied from interface:LongRunningTaskManagerInternal
Start tracking a long running task that should be started in a new thread whenLongRunningTaskManagerInternal.startIfQueued(com.atlassian.confluence.util.longrunning.LongRunningTaskId)
is called.- Specified by:
queueLongRunningTask
in interfaceLongRunningTaskManagerInternal
- Parameters:
task
- the task to perform- Returns:
- an ID that can be used to look up the task
-
startIfQueued
public void startIfQueued(LongRunningTaskId taskId)
Description copied from interface:LongRunningTaskManagerInternal
Starts the task in a new thread if it has previously been queued.- Specified by:
startIfQueued
in interfaceLongRunningTaskManagerInternal
- Parameters:
taskId
- the ID of the task
-
startLongRunningTask
public LongRunningTaskId startLongRunningTask(@Nullable com.atlassian.user.User user, com.atlassian.core.task.longrunning.LongRunningTask task)
Description copied from interface:LongRunningTaskManager
Start some task in a new thread- Specified by:
startLongRunningTask
in interfaceLongRunningTaskManager
- Parameters:
user
- the user responsible for the tasktask
- the task to perform- Returns:
- an ID that can be used to look up the task
-
runToCompletion
public void runToCompletion(@Nullable com.atlassian.user.User user, com.atlassian.core.task.longrunning.LongRunningTask task)
Description copied from interface:LongRunningTaskManagerInternal
Starts aLongRunningTask
and waits for it to complete.- Specified by:
runToCompletion
in interfaceLongRunningTaskManagerInternal
- Parameters:
user
- the user responsible for the tasktask
- the task to perform
-
getLongRunningTask
public @Nullable com.atlassian.core.task.longrunning.LongRunningTask getLongRunningTask(@Nullable com.atlassian.user.User user, LongRunningTaskId taskId)
gets a long running task with the given Id that was registered either by this user or the anonymous user.- Specified by:
getLongRunningTask
in interfaceLongRunningTaskManager
- Parameters:
user
- the user responsible for the tasktaskId
- the ID of the task- Returns:
- the task, or null if no task is registered with that ID and user
-
getAllTasks
public PageResponse<LongTaskStatus> getAllTasks(@Nullable ConfluenceUser asUser, LimitedRequest request)
Description copied from interface:LongRunningTaskManagerInternal
Get all currently-tracked tasks that the specified user can see.- Specified by:
getAllTasks
in interfaceLongRunningTaskManagerInternal
-
removeComplete
public List<LongTaskStatus> removeComplete()
Description copied from interface:LongRunningTaskManager
Remove completed tasks from the tracker.- Specified by:
removeComplete
in interfaceLongRunningTaskManager
- Returns:
- details of the removed tasks
-
getTaskCount
public int getTaskCount()
Description copied from interface:LongRunningTaskManagerInternal
Return a count of the current queued and running tasks. The count may include tasks that the current user is not allowed to see.- Specified by:
getTaskCount
in interfaceLongRunningTaskManagerInternal
-
stopTrackingLongRunningTask
public void stopTrackingLongRunningTask(LongRunningTaskId taskId)
Description copied from interface:LongRunningTaskManager
Clean up an old task. The manager hangs on to tasks that have been completed so their status can be queried. Calling this method will remove the task from the manager entirely.This method does not stop a task from being executed. If the task is already running it will continue to completion, you just won't be able to query its status any more.
- Specified by:
stopTrackingLongRunningTask
in interfaceLongRunningTaskManager
- Parameters:
taskId
- the ID of the task to remove.
-
destroy
public void destroy()
- Specified by:
destroy
in interfaceorg.springframework.beans.factory.DisposableBean
-
stop
public void stop(long timeout, TimeUnit unit) throws TimeoutException
Description copied from interface:LongRunningTaskManager
Stop accepting new long running tasks. All tasks that have previously been submitted will be run to completion. If this takes longer than the timeout, the method will throw an exception and the task manager will resume normal operation accepting new tasks.- Specified by:
stop
in interfaceLongRunningTaskManager
- Parameters:
timeout
- the time to wait for running tasks to completeunit
- the unit of measurement for the timeout parameter- Throws:
TimeoutException
- if the timeout is exceeded
-
resume
public void resume()
Description copied from interface:LongRunningTaskManager
Resume accepting long-running tasks afterLongRunningTaskManager.stop(long, java.util.concurrent.TimeUnit)
has been called. If the long-running task manager is not stopped, this method will whistle quietly to itself and do nothing.- Specified by:
resume
in interfaceLongRunningTaskManager
-
taskFinished
protected void taskFinished(LongRunningTaskId taskId)
-
-