Class ListenableTask<V>
java.lang.Object
java.util.concurrent.CompletableFuture<V>
eu.cloudnetservice.utils.base.concurrent.ListenableTask<V>
- Type Parameters:
V- the generic type of the task.
- All Implemented Interfaces:
CompletionStage<V>, Future<V>
The listenable task is a task that is allowed to be executed over and over again. The task wraps a callable and calls
it on each run of the task. Once the result of the task is completed using
task.run(true) the task cannot run
anymore, and it switches into the done state.- Since:
- 4.0
-
Nested Class Summary
Nested classes/interfaces inherited from class CompletableFuture
CompletableFuture.AsynchronousCompletionTaskNested classes/interfaces inherited from interface Future
Future.State -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicIntegerprotected static final intprotected static final intprotected static final int -
Constructor Summary
ConstructorsConstructorDescriptionListenableTask(@NonNull Callable<V> callable) Constructs a new listenable task with the given callable -
Method Summary
Modifier and TypeMethodDescriptionvoidrun(boolean setResult) Runs the callable provided to this listenable task.Methods inherited from class CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, cancel, complete, completeAsync, completeAsync, completedFuture, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, exceptionNow, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, resultNow, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, state, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
-
Field Details
-
STATE_NEW
protected static final int STATE_NEW- See Also:
-
STATE_RUN
protected static final int STATE_RUN- See Also:
-
STATE_DONE
protected static final int STATE_DONE- See Also:
-
callable
-
state
-
-
Constructor Details
-
ListenableTask
Constructs a new listenable task with the given callable- Parameters:
callable- the callable to call on each run.- Throws:
NullPointerException- if the given callable is null.
-
-
Method Details
-
run
public void run(boolean setResult) Runs the callable provided to this listenable task. This task supports running it over and over again until the result it set and the task completed with that result.- Parameters:
setResult- whether the result of the callable should be set as result of this task.
-