Package com.powsybl.computation
Class CompletableFutureTask<R>
java.lang.Object
java.util.concurrent.CompletableFuture<R>
com.powsybl.computation.CompletableFutureTask<R>
- All Implemented Interfaces:
Runnable
,CompletionStage<R>
,Future<R>
A
CompletableFuture
which embeds an actual task, unlike the default implementation.
In particular, the behaviour of cancel(boolean)
is modified in order to actually
interrupt the thread executing the bound task.
Similarly to FutureTask
, this class implements Runnable
and
can therefore be submitted to an Executor
for execution.
- Author:
- Sylvain Leclerc <sylvain.leclerc at rte-france.com>
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTask
-
Constructor Summary
ConstructorDescriptionCompletableFutureTask
(Callable<R> task) Creates a completable future bound to the specified task. -
Method Summary
Modifier and TypeMethodDescriptionboolean
cancel
(boolean mayInterruptIfRunning) Cancels this completable future and, if requested and if the bound task is under execution, interrupts the thread executing the task.<U> CompletableFuture<U>
void
run()
Executes the wrapped callable.static <T> CompletableFutureTask<T>
Creates a completable future task and submits it to the specified executor.Submits this task to the specified executor.Methods inherited from class java.util.concurrent.CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, complete, completeAsync, completeAsync, completedFuture, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, obtrudeException, obtrudeValue, orTimeout, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, 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
-
Constructor Details
-
Method Details
-
run
public void run()Executes the wrapped callable. On execution end, this future will complete with the callable result, or complete exceptionally in case of exception. -
runAsync
Submits this task to the specified executor.- Parameters:
executor
- The executor which will execute this task.- Returns:
- This.
-
runAsync
Creates a completable future task and submits it to the specified executor.- Parameters:
task
- The task to be executed.executor
- The executor which will execute the task.- Returns:
- A
CompletableFutureTask
bound to the specified task.
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) Cancels this completable future and, if requested and if the bound task is under execution, interrupts the thread executing the task.- Specified by:
cancel
in interfaceFuture<R>
- Overrides:
cancel
in classCompletableFuture<R>
- Parameters:
mayInterruptIfRunning
- iftrue
, and if the bound task is under execution, the thread executing the task will be interrupted- Returns:
false
if the task could not be cancelled, typically because it has already completed;true
otherwise
-
newIncompleteFuture
- Overrides:
newIncompleteFuture
in classCompletableFuture<R>
-