Interface Task.Coordinator<T>

Type Parameters:
T - the type of the collected results
Enclosing interface:
Task<T>

public static interface Task.Coordinator<T>
A publisher of collected Task results that additionally permits coordination of the submitted Task.

Results collected by the execution of a Task using one or more Executors are sent to registered Task.Subscribers. Each registered Task.Subscriber receives the same results (via method Task.Subscriber.onNext(Object)) in the same order, unless drops or errors are encountered.

If a Task.Coordinator encounters an error that does not allow results to be issued to a Task.Subscriber, the Task.Subscriber.onError(Throwable) is called, and then receives no further results. Otherwise, when it is known that no further results will be issued to it, the Task.Subscriber.onComplete() is called.

Task.Coordinators ensure that Task.Subscriber method invocations for each subscription are strictly ordered in happens-before order.

  • Method Details

    • subscribe

      void subscribe(Task.Subscriber<? super T> subscriber)
      Subscribes the specified Task.Subscriber to the Task.Coordinator of a Task to receive collected results.

      If already subscribed, or the attempt to subscribe fails, the Task.Subscriber.onError(Throwable) method is invoked with an IllegalStateException.

      Parameters:
      subscriber - the Task.Subscriber
    • cancel

      boolean cancel(boolean mayInterruptIfRunning)
      Attempts to cancel execution of the Task. This attempt will fail if the task has already completed, has already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.

      After this method returns, subsequent calls to isDone() will always return true. Subsequent calls to isDone() will always return true if this method returned true.

      Parameters:
      mayInterruptIfRunning - true if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete
      Returns:
      false if the task could not be cancelled, typically because it has already completed normally; true otherwise
      See Also:
    • isCancelled

      boolean isCancelled()
      Returns true if the Task was cancelled before it completed normally.
      Returns:
      true if this task was cancelled before it completed
      See Also:
    • isDone

      boolean isDone()
      Returns true if the Task completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true.
      Returns:
      true if this task completed
      See Also:
    • getTaskId

      String getTaskId()
      Obtains the unique identity of the Task being coordinated.
      Returns:
      the task identity
    • getProperties

      Task.Properties getProperties()
      Obtain the properties of the Task being coordinated.
      Returns:
      the task properties