Package aQute.bnd.service.progress
Class TaskManager
java.lang.Object
aQute.bnd.service.progress.TaskManager
A central task manager. Background threads should their code with the
with(Task, Callable)
call. This will associate a task with the
current thread. Anybody in that thread can call ProgressPlugin.Task.isCanceled()
or
cancel that current thread's task.
This creates a central point where long running tasks can register their activity so they can be centrally canceled and queried.
If no task is active, isCanceled()
returns false. It is therefore
save to call isCanceled()
at any time.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final AtomicBoolean
(package private) static final ThreadLocal<ProgressPlugin.Task>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
cancel()
Cancel the current thread's task.getTask()
Get the current task if there is one.static boolean
Answer true if the current thread is associated with a Task and that task is canceled.static void
Shutdown all tasks, cannot be recovered fromstatic <T> T
with
(ProgressPlugin.Task task, Callable<T> callable) Execute a callable keeping the task active on the current thread.
-
Field Details
-
tasks
-
shutdown
-
-
Constructor Details
-
TaskManager
public TaskManager()
-
-
Method Details
-
with
Execute a callable keeping the task active on the current thread.- Type Parameters:
T
- the type of the callable- Parameters:
task
- the task.callable
-- Returns:
- the result of the callable.
- Throws:
Exception
-
isCanceled
public static boolean isCanceled()Answer true if the current thread is associated with a Task and that task is canceled.- Returns:
- true if the current threads task is canceled, false if there is not task or if it is not canceled.
-
cancel
public static void cancel()Cancel the current thread's task. Noop if there is no current task -
shtutdown
public static void shtutdown()Shutdown all tasks, cannot be recovered from -
getTask
Get the current task if there is one.- Returns:
- the current task or empty
-