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>
public class CompletableFutureTask<R> extends CompletableFuture<R> implements Runnable
ACompletableFuture
which embeds an actual task, unlike the default implementation. In particular, the behaviour ofcancel(boolean)
is modified in order to actually interrupt the thread executing the bound task.Similarly to
FutureTask
, this class implementsRunnable
and can therefore be submitted to anExecutor
for execution.- Author:
- Sylvain Leclerc
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTask
-
-
Constructor Summary
Constructors Constructor Description CompletableFutureTask(Callable<R> task)
Creates a completable future bound to the specified task.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.void
run()
Executes the wrapped callable.static <T> CompletableFutureTask<T>
runAsync(Callable<T> task, Executor executor)
Creates a completable future task and submits it to the specified executor.CompletableFutureTask<R>
runAsync(Executor 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, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, 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
-
-
-
-
Method Detail
-
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
public CompletableFutureTask<R> runAsync(Executor executor)
Submits this task to the specified executor.- Parameters:
executor
- The executor which will execute this task.- Returns:
- This.
-
runAsync
public static <T> CompletableFutureTask<T> runAsync(Callable<T> task, Executor executor)
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
-
-