Interface Task

  • All Superinterfaces:
    Cancelable, Named
    All Known Implementing Classes:
    DefaultTask

    public interface Task
    extends Cancelable, Named
    A self-aware job which reports its status and progress as it runs. There are two ways to use a Task object: - A job can be run asynchronously by using run(Runnable), and can report its progression from within the Runnable. - A Task object can simply be used to report in a synchronous manner the progression of a piece of code. In the case of synchronous reporting, the job is considered started when start() is called and finished when finish() is called. A finished job can be finished either because it is done or because it has been cancelled. A cancel callback can be set with setCancelCallBack(Runnable). The runnable argument will be executed in the case of an external event requesting a cancellation of the task - typically, if a user clicks a cancel button on the GUI, task.cancel("User cancellation requested") will be called. As a result, the task implementors should run the callback. This callback can be used to make the task aware that a cancellation has been requested, and should proceed to stop its execution. See also TaskService, DefaultTask
    Author:
    Curtis Rueden, Nicolas Chiaruttini
    • Method Detail

      • start

        default void start()
        reports that the task is started - synchronous job
      • finish

        default void finish()
        reports that the task is finished - synchronous job
      • isDone

        boolean isDone()
        Checks whether the task has completed.
      • getStatusMessage

        String getStatusMessage()
        Gets a status message describing what the task is currently doing.
      • getProgressMaximum

        long getProgressMaximum()
        Gets the number of steps the task performs in total.
        Returns:
        Total number of steps the task will perform, or 0 if unknown.
        See Also:
        getProgressValue()
      • setStatusMessage

        void setStatusMessage​(String status)
        Sets the status message. Called by task implementors.
        Parameters:
        status - The message to set.
        See Also:
        getStatusMessage()
      • setProgressValue

        void setProgressValue​(long step)
        Sets the current step. Called by task implementors.
        Parameters:
        step - The step vaule to set.
        See Also:
        getProgressValue()
      • setProgressMaximum

        void setProgressMaximum​(long max)
        Sets the total number of steps. Called by task implementors.
        Parameters:
        max - The step count to set.
        See Also:
        getProgressMaximum()
      • setCancelCallBack

        default void setCancelCallBack​(Runnable runnable)
        If the task is cancelled (external call to Cancelable.cancel(String)), the input runnable argument should be executed by task implementors.
        Parameters:
        runnable - : should be executed if this task is cancelled through Cancelable.cancel(String)
      • getCancelCallBack

        default Runnable getCancelCallBack()
        Returns the current cancel callback runnable, This can be used to concatenate callbacks in order, for instance, to ask for a user confirmation before cancelling the task