Interface Task

All Superinterfaces:
org.openide.util.Cancellable
All Known Subinterfaces:
Task.WithResult<T>
All Known Implementing Classes:
AbstractTask, AbstractTask.WithResult, SerialTasks

public interface Task extends org.openide.util.Cancellable
A task to be executed. The task may complete within a call to execute() or initiate asynchronous operation, such as making calls into the PraxisCORE hub. If the caller needs to know when an asynchronous task is completed, it may add a property change listener.

A task may only be executed once.

All methods should be called on, and all listeners are fired on, the Swing event thread.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    The possible states of a Task.
    static interface 
    An extension of Task that produces a result when it completes successfully.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Name of property used when firing state change events.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add a property change listener.
    default Optional<String>
    Optional description of this task to be presented to the user.
    Initiate execution of the task.
    Query the current task state.
    default List<String>
    log()
    Optional log of information generated by execution of this task, suitable for presentation to the user.
    void
    Remove a property change listener.
    run(Task task)
    Execute the task wrapped in a completion stage.

    Methods inherited from interface org.openide.util.Cancellable

    cancel
  • Field Details

  • Method Details

    • execute

      Task.State execute()
      Initiate execution of the task. This method returns Task.State.RUNNING when the task is running asynchronous operations. The caller may add a property listener if it needs to know when and how those operations complete.

      A task can only be executed once. This method will throw an IllegalStateException if the task state is not Task.State.NEW.

      Returns:
      task state
      Throws:
      IllegalStateException - if the task state is not NEW.
    • getState

      Task.State getState()
      Query the current task state.
      Returns:
      task state
    • addPropertyChangeListener

      void addPropertyChangeListener(PropertyChangeListener listener)
      Add a property change listener.
      Parameters:
      listener - property change listener
    • removePropertyChangeListener

      void removePropertyChangeListener(PropertyChangeListener listener)
      Remove a property change listener.
      Parameters:
      listener - property change listener
    • description

      default Optional<String> description()
      Optional description of this task to be presented to the user.
      Returns:
      optional description
    • log

      default List<String> log()
      Optional log of information generated by execution of this task, suitable for presentation to the user.
      Returns:
      task log
    • run

      static CompletionStage<Void> run(Task task)
      Execute the task wrapped in a completion stage.
      Parameters:
      task - task to execute
      Returns:
      task completion stage