public interface TaskExecutor extends Executor
java.util.concurrent.Executor.
That is, this interface defines a simpler way for canceling tasks and allows
to continue after the completion of the submitted task via a CompletionStage.
It is possible to continue execution regardless how the submitted task completed
(success, failure or canceled).
For more control over the life of a TaskExecutor, see the extending
TaskExecutorService interface.
CompletionStage, etc.| Modifier and Type | Method and Description |
|---|---|
default CompletionStage<Void> |
execute(CancellationToken cancelToken,
CancelableTask task)
Executes the task at some time in the future.
|
default void |
execute(Runnable command)
Note that although the task itself is not cancelable explicitly, the executor might cancel
it by not executing the submitted task.
|
<V> CompletionStage<V> |
executeFunction(CancellationToken cancelToken,
CancelableFunction<? extends V> function)
Executes the function at some time in the future.
|
default CompletionStage<Void> |
executeStaged(Runnable task)
Executes an non-cancelable task at some time in the future.
|
<V> CompletionStage<V> executeFunction(CancellationToken cancelToken, CancelableFunction<? extends V> function)
V - the type of the result of the submitted functioncancelToken - the CancellationToken which is to be checked
if the submitted task is to be canceled. If this
CancellationToken signals a cancellation request, this
TaskExecutor may choose to not even attempt to execute the
submitted task. This argument may not be null. When the task cannot be
canceled, use the static Cancellation.UNCANCELABLE_TOKEN
for this argument (even in this case, the TaskExecutor may be able to
cancel the task, if it was not submitted for execution).function - the function to be executed by this TaskExecutor. This
argument cannot be null.CompletionStage which can be used to execute tasks
after the completion of the submitted function and process the result of
the submitted function. This method never returns null.NullPointerException - thrown if the CancellationToken
or the task is nullCancellation.createCancellationSource(),
Cancellation.UNCANCELABLE_TOKENdefault CompletionStage<Void> execute(CancellationToken cancelToken, CancelableTask task)
cancelToken - the CancellationToken which is to be checked
if the submitted task is to be canceled. If this
CancellationToken signals a cancellation request, this
TaskExecutor may choose to not even attempt to execute the
submitted task. This argument may not be null. When the task cannot be
canceled, use the static Cancellation.UNCANCELABLE_TOKEN
for this argument (even in this case, the TaskExecutor may be able to
cancel the task, if it was not submitted for execution).task - the task to be executed by this TaskExecutor. This
argument cannot be null.CompletionStage which can be used to execute tasks
after the completion of the submitted task. This method never returns null.NullPointerException - thrown if the CancellationToken
or the task is nullCancellation.createCancellationSource(),
Cancellation.UNCANCELABLE_TOKENdefault CompletionStage<Void> executeStaged(Runnable task)
Note that although the task itself is not cancelable explicitly, the executor might cancel
it by not executing the submitted task. For example, due to a call to the
shutdownAndCancel method of
TaskExecutorService.
The default implementation delegates the call to
execute(CancellationToken, CancelableTask).
task - the task to be executed by this TaskExecutor. This
argument cannot be null.CompletionStage which can be used to execute tasks
after the completion of the submitted task. This method never returns null.NullPointerException - thrown if the task is nullCancellation.createCancellationSource(),
Cancellation.UNCANCELABLE_TOKENdefault void execute(Runnable command)
Note that although the task itself is not cancelable explicitly, the executor might cancel
it by not executing the submitted task. For example, due to a call to the
shutdownAndCancel method of
TaskExecutorService.
The default implementation delegates the call to executeStaged and
logs uncaught errors thrown by the submitted task.