Interface Task.Coordinator<T>
-
- Type Parameters:
T
- the type of the collected results
public static interface Task.Coordinator<T>
A publisher of collectedTask
results that additionally permits coordination of the submittedTask
.Results collected by the execution of a
Task
using one or moreExecutor
s are sent to registeredTask.Subscriber
s. Each registeredTask.Subscriber
receives the same results (via methodTask.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 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.Coordinator
s ensure thatTask.Subscriber
method invocations for each subscription are strictly ordered in happens-before order.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
cancel(boolean mayInterruptIfRunning)
Attempts to cancel execution of theTask
.Task.Properties
getProperties()
Obtain the properties of theTask
being coordinated.String
getTaskId()
Obtains the unique identity of theTask
being coordinated.boolean
isCancelled()
Returnstrue
if theTask
was cancelled before it completed normally.boolean
isDone()
Returnstrue
if theTask
completed.void
subscribe(Task.Subscriber<? super T> subscriber)
Subscribes the specifiedTask.Subscriber
to theTask.Coordinator
of aTask
to receive collected results.
-
-
-
Method Detail
-
subscribe
void subscribe(Task.Subscriber<? super T> subscriber)
Subscribes the specifiedTask.Subscriber
to theTask.Coordinator
of aTask
to 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
-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:
Future.cancel(boolean)
-
isCancelled
boolean isCancelled()
Returnstrue
if theTask
was cancelled before it completed normally.- Returns:
true
if this task was cancelled before it completed- See Also:
Future.isCancelled()
-
isDone
boolean isDone()
Returnstrue
if theTask
completed. Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will returntrue
.- Returns:
true
if this task completed- See Also:
Future.isDone()
-
getTaskId
String getTaskId()
Obtains the unique identity of theTask
being coordinated.- Returns:
- the task identity
-
getProperties
Task.Properties getProperties()
Obtain the properties of theTask
being coordinated.- Returns:
- the task properties
-
-