public abstract class AbstractTaskExecutor extends Object implements TaskExecutor
TaskExecutor implementations.
AbstractTaskExecutor defines default implementations for all
the execute methods which all rely on the protected
submitTask
method. Only this submitTask method is needed to be implemented by
subclasses to actually schedule a task. Note that all the execute
methods rely directly the submitTask method and
overriding any of them has no effect on the others (i.e.: they don't call
each other). For further details on how to implement the submitTask
method: see its documentation.
| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractTaskExecutor.SubmittedTask<V>
Defines the submitted task to be executed by subclasses of
AbstractTaskExecutor. |
| Constructor and Description |
|---|
AbstractTaskExecutor() |
| Modifier and Type | Method and Description |
|---|---|
<V> CompletionStage<V> |
executeFunction(CancellationToken cancelToken,
CancelableFunction<? extends V> function)
Executes the function at some time in the future.
|
protected abstract void |
submitTask(CancellationToken cancelToken,
AbstractTaskExecutor.SubmittedTask<?> submittedTask)
Implementations must override this method to actually execute submitted
tasks.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexecute, execute, executeStagedprotected abstract void submitTask(CancellationToken cancelToken, AbstractTaskExecutor.SubmittedTask<?> submittedTask)
Assuming no cancellation requests, implementations must call
submittedTask.execute.
Cancellation requests can be detected using the provided
CancellationToken and if an implementation chooses not to even
try to execute task, it must only call
submittedTask.cancel.
Implementations must always complete the passed task in some way. Either
by calling its execute or its completeExceptionally (or cancel)
method.
cancelToken - the CancellationToken which can be checked by
implementations if the currently submitted task has been canceled.
Also this is the CancellationToken implementations should pass
to task. This argument cannot be null.submittedTask - the task to be executed. Implementations must execute this task at most
once by calling its execute method.
If the execute method is not called, an exceptional return state must be set via
the completeExceptionally
method. This argument cannot be null.public <V> CompletionStage<V> executeFunction(CancellationToken cancelToken, CancelableFunction<? extends V> function)
executeFunction in interface TaskExecutorV - 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.Cancellation.createCancellationSource(),
Cancellation.UNCANCELABLE_TOKEN