Class TaskManager


  • public abstract class TaskManager
    extends java.lang.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.

    • Constructor Summary

      Constructors 
      Constructor Description
      TaskManager()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void cancel()
      Cancel the current thread's task.
      java.util.Optional<ProgressPlugin.Task> getTask()
      Get the current task if there is one.
      static boolean isCanceled()
      Answer true if the current thread is associated with a Task and that task is canceled.
      static void shtutdown()
      Shutdown all tasks, cannot be recovered from
      static <T> T with​(ProgressPlugin.Task task, java.util.concurrent.Callable<T> callable)
      Execute a callable keeping the task active on the current thread.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TaskManager

        public TaskManager()
    • Method Detail

      • with

        public static <T> T with​(ProgressPlugin.Task task,
                                 java.util.concurrent.Callable<T> callable)
                          throws java.lang.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:
        java.lang.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 java.util.Optional<ProgressPlugin.Task> getTask()
        Get the current task if there is one.
        Returns:
        the current task or empty