Class TaskManager

java.lang.Object
aQute.bnd.service.progress.TaskManager

public abstract class TaskManager extends Object
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 Details

  • Constructor Details

    • TaskManager

      public TaskManager()
  • Method Details

    • with

      public static <T> T with(ProgressPlugin.Task task, Callable<T> callable) throws Exception
      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

      public Optional<ProgressPlugin.Task> getTask()
      Get the current task if there is one.
      Returns:
      the current task or empty