Interface Task.Coordinator<T>
-
- Type Parameters:
T- the type of the collected results
public static interface Task.Coordinator<T>A publisher of collectedTaskresults that additionally permits coordination of the submittedTask.Results collected by the execution of a
Taskusing one or moreExecutors are sent to registeredTask.Subscribers. Each registeredTask.Subscriberreceives the same results (via methodTask.Subscriber.onNext(Object)) in the same order, unless drops or errors are encountered.If a
Task.Coordinatorencounters an error that does not allow results to be issued to aTask.Subscriber, theTask.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, theTask.Subscriber.onComplete()is called.Task.Coordinators ensure thatTask.Subscribermethod invocations for each subscription are strictly ordered in happens-before order.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleancancel(boolean mayInterruptIfRunning)Attempts to cancel execution of theTask.Task.PropertiesgetProperties()Obtain the properties of theTaskbeing coordinated.StringgetTaskId()Obtains the unique identity of theTaskbeing coordinated.booleanisCancelled()Returnstrueif 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 Detail
-
subscribe
void subscribe(Task.Subscriber<? super T> subscriber)
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:
Future.cancel(boolean)
-
isCancelled
boolean isCancelled()
Returnstrueif theTaskwas cancelled before it completed normally.- Returns:
trueif this task was cancelled before it completed- See Also:
Future.isCancelled()
-
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:
Future.isDone()
-
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
-
-