Interface Task.Coordinator<T>
- Type Parameters:
T- the type of the collected results
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 Summary
Modifier and TypeMethodDescriptionbooleancancel(boolean mayInterruptIfRunning) Attempts to cancel execution of theTask.Obtain the properties of theTaskbeing coordinated.Obtains the unique identity of theTaskbeing coordinated.booleanReturnstrueif theTaskwas cancelled before it completed normally.booleanisDone()Returnstrueif theTaskcompleted.voidsubscribe(Task.Subscriber<? super T> subscriber) Subscribes the specifiedTask.Subscriberto theTask.Coordinatorof aTaskto receive collected results.
-
Method Details
-
subscribe
Subscribes the specifiedTask.Subscriberto theTask.Coordinatorof aTaskto receive collected results.If already subscribed, or the attempt to subscribe fails, the
Task.Subscriber.onError(Throwable)method is invoked with anIllegalStateException.- Parameters:
subscriber- theTask.Subscriber
-
cancel
boolean cancel(boolean mayInterruptIfRunning) Attempts to cancel execution of theTask. 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-trueif the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete- Returns:
falseif the task could not be cancelled, typically because it has already completed normally;trueotherwise- See Also:
-
isCancelled
boolean isCancelled()Returnstrueif theTaskwas cancelled before it completed normally.- Returns:
trueif this task was cancelled before it completed- See Also:
-
isDone
boolean isDone()Returnstrueif theTaskcompleted. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will returntrue.- Returns:
trueif this task completed- See Also:
-
getTaskId
String getTaskId()Obtains the unique identity of theTaskbeing coordinated.- Returns:
- the task identity
-
getProperties
Task.Properties getProperties()Obtain the properties of theTaskbeing coordinated.- Returns:
- the task properties
-