Class CompletableFutureTask<V>
java.lang.Object
java.util.concurrent.FutureTask<V>
com.linkedin.alpini.base.concurrency.CompletableFutureTask<V>
- All Implemented Interfaces:
Runnable
,CompletionStage<V>
,Future<V>
,RunnableFuture<V>
Created by acurtis on 4/4/17.
-
Constructor Summary
ConstructorDescriptionCompletableFutureTask
(Runnable runnable, V result) Creates aCompletableFutureTask
that will, upon running, execute the givenRunnable
, and arrange thatget
will return the given result on successful completion.CompletableFutureTask
(Callable<V> callable) Creates aCompletableFutureTask
that will, upon running, execute the givenCallable
. -
Method Summary
Modifier and TypeMethodDescriptionacceptEither
(CompletionStage<? extends V> other, Consumer<? super V> action) acceptEitherAsync
(CompletionStage<? extends V> other, Consumer<? super V> action) acceptEitherAsync
(CompletionStage<? extends V> other, Consumer<? super V> action, Executor executor) <U> CompletionStage<U>
applyToEither
(CompletionStage<? extends V> other, Function<? super V, U> fn) <U> CompletionStage<U>
applyToEitherAsync
(CompletionStage<? extends V> other, Function<? super V, U> fn) <U> CompletionStage<U>
applyToEitherAsync
(CompletionStage<? extends V> other, Function<? super V, U> fn, Executor executor) boolean
cancel
(boolean mayInterruptIfRunning) protected final void
done()
Use the methods provided by theCompletionStage
interface to perform actions after the completion of the task.exceptionally
(Function<Throwable, ? extends V> fn) get()
<U> CompletionStage<U>
handle
(BiFunction<? super V, Throwable, ? extends U> fn) <U> CompletionStage<U>
handleAsync
(BiFunction<? super V, Throwable, ? extends U> fn) <U> CompletionStage<U>
handleAsync
(BiFunction<? super V, Throwable, ? extends U> fn, Executor executor) boolean
boolean
isDone()
runAfterBoth
(CompletionStage<?> other, Runnable action) runAfterBothAsync
(CompletionStage<?> other, Runnable action) runAfterBothAsync
(CompletionStage<?> other, Runnable action, Executor executor) runAfterEither
(CompletionStage<?> other, Runnable action) runAfterEitherAsync
(CompletionStage<?> other, Runnable action) runAfterEitherAsync
(CompletionStage<?> other, Runnable action, Executor executor) protected void
protected void
thenAccept
(Consumer<? super V> action) thenAcceptAsync
(Consumer<? super V> action) thenAcceptAsync
(Consumer<? super V> action, Executor executor) <U> CompletionStage<Void>
thenAcceptBoth
(CompletionStage<? extends U> other, BiConsumer<? super V, ? super U> action) <U> CompletionStage<Void>
thenAcceptBothAsync
(CompletionStage<? extends U> other, BiConsumer<? super V, ? super U> action) <U> CompletionStage<Void>
thenAcceptBothAsync
(CompletionStage<? extends U> other, BiConsumer<? super V, ? super U> action, Executor executor) <U> CompletionStage<U>
<U> CompletionStage<U>
thenApplyAsync
(Function<? super V, ? extends U> fn) <U> CompletionStage<U>
thenApplyAsync
(Function<? super V, ? extends U> fn, Executor executor) <U,
W> CompletionStage<W> thenCombine
(CompletionStage<? extends U> other, BiFunction<? super V, ? super U, ? extends W> fn) <U,
W> CompletionStage<W> thenCombineAsync
(CompletionStage<? extends U> other, BiFunction<? super V, ? super U, ? extends W> fn) <U,
W> CompletionStage<W> thenCombineAsync
(CompletionStage<? extends U> other, BiFunction<? super V, ? super U, ? extends W> fn, Executor executor) <U> CompletionStage<U>
thenCompose
(Function<? super V, ? extends CompletionStage<U>> fn) <U> CompletionStage<U>
thenComposeAsync
(Function<? super V, ? extends CompletionStage<U>> fn) <U> CompletionStage<U>
thenComposeAsync
(Function<? super V, ? extends CompletionStage<U>> fn, Executor executor) thenRunAsync
(Runnable action) thenRunAsync
(Runnable action, Executor executor) toString()
Returns a string identifying this CompletableFutureTask, as well as its completion state.whenComplete
(BiConsumer<? super V, ? super Throwable> action) whenCompleteAsync
(BiConsumer<? super V, ? super Throwable> action) whenCompleteAsync
(BiConsumer<? super V, ? super Throwable> action, Executor executor) Methods inherited from class java.util.concurrent.FutureTask
run, runAndReset
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.concurrent.CompletionStage
exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync
-
Constructor Details
-
CompletableFutureTask
Creates aCompletableFutureTask
that will, upon running, execute the givenCallable
.- Parameters:
callable
- the callable task- Throws:
NullPointerException
- if the callable is null
-
CompletableFutureTask
Creates aCompletableFutureTask
that will, upon running, execute the givenRunnable
, and arrange thatget
will return the given result on successful completion.- Parameters:
runnable
- the runnable taskresult
- the result to return on successful completion. If you don't need a particular result, consider using constructions of the form:CompletionStage<?> f = new CompletableFutureTask<Void>(runnable, null)
- Throws:
NullPointerException
- if the runnable is null
-
-
Method Details
-
isCancelled
public boolean isCancelled()- Specified by:
isCancelled
in interfaceFuture<V>
- Overrides:
isCancelled
in classFutureTask<V>
-
isDone
public boolean isDone() -
cancel
public boolean cancel(boolean mayInterruptIfRunning) -
get
- Specified by:
get
in interfaceFuture<V>
- Overrides:
get
in classFutureTask<V>
- Throws:
InterruptedException
ExecutionException
-
get
public V get(long timeout, @Nonnull TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
get
in interfaceFuture<V>
- Overrides:
get
in classFutureTask<V>
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
done
protected final void done()Use the methods provided by theCompletionStage
interface to perform actions after the completion of the task. This method is final and may not be overridden.- Overrides:
done
in classFutureTask<V>
-
set
- Overrides:
set
in classFutureTask<V>
-
setException
- Overrides:
setException
in classFutureTask<V>
-
thenApply
- Specified by:
thenApply
in interfaceCompletionStage<V>
-
thenApplyAsync
- Specified by:
thenApplyAsync
in interfaceCompletionStage<V>
-
thenApplyAsync
- Specified by:
thenApplyAsync
in interfaceCompletionStage<V>
-
thenAccept
- Specified by:
thenAccept
in interfaceCompletionStage<V>
-
thenAcceptAsync
- Specified by:
thenAcceptAsync
in interfaceCompletionStage<V>
-
thenAcceptAsync
- Specified by:
thenAcceptAsync
in interfaceCompletionStage<V>
-
thenRun
- Specified by:
thenRun
in interfaceCompletionStage<V>
-
thenRunAsync
- Specified by:
thenRunAsync
in interfaceCompletionStage<V>
-
thenRunAsync
- Specified by:
thenRunAsync
in interfaceCompletionStage<V>
-
thenCombine
public <U,W> CompletionStage<W> thenCombine(CompletionStage<? extends U> other, BiFunction<? super V, ? super U, ? extends W> fn) - Specified by:
thenCombine
in interfaceCompletionStage<V>
-
thenCombineAsync
public <U,W> CompletionStage<W> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V, ? super U, ? extends W> fn) - Specified by:
thenCombineAsync
in interfaceCompletionStage<V>
-
thenCombineAsync
public <U,W> CompletionStage<W> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V, ? super U, ? extends W> fn, Executor executor) - Specified by:
thenCombineAsync
in interfaceCompletionStage<V>
-
thenAcceptBoth
public <U> CompletionStage<Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super V, ? super U> action) - Specified by:
thenAcceptBoth
in interfaceCompletionStage<V>
-
thenAcceptBothAsync
public <U> CompletionStage<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super V, ? super U> action) - Specified by:
thenAcceptBothAsync
in interfaceCompletionStage<V>
-
thenAcceptBothAsync
public <U> CompletionStage<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super V, ? super U> action, Executor executor) - Specified by:
thenAcceptBothAsync
in interfaceCompletionStage<V>
-
runAfterBoth
- Specified by:
runAfterBoth
in interfaceCompletionStage<V>
-
runAfterBothAsync
- Specified by:
runAfterBothAsync
in interfaceCompletionStage<V>
-
runAfterBothAsync
public CompletionStage<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor) - Specified by:
runAfterBothAsync
in interfaceCompletionStage<V>
-
applyToEither
public <U> CompletionStage<U> applyToEither(CompletionStage<? extends V> other, Function<? super V, U> fn) - Specified by:
applyToEither
in interfaceCompletionStage<V>
-
applyToEitherAsync
public <U> CompletionStage<U> applyToEitherAsync(CompletionStage<? extends V> other, Function<? super V, U> fn) - Specified by:
applyToEitherAsync
in interfaceCompletionStage<V>
-
applyToEitherAsync
public <U> CompletionStage<U> applyToEitherAsync(CompletionStage<? extends V> other, Function<? super V, U> fn, Executor executor) - Specified by:
applyToEitherAsync
in interfaceCompletionStage<V>
-
acceptEither
public CompletionStage<Void> acceptEither(CompletionStage<? extends V> other, Consumer<? super V> action) - Specified by:
acceptEither
in interfaceCompletionStage<V>
-
acceptEitherAsync
public CompletionStage<Void> acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action) - Specified by:
acceptEitherAsync
in interfaceCompletionStage<V>
-
acceptEitherAsync
public CompletionStage<Void> acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action, Executor executor) - Specified by:
acceptEitherAsync
in interfaceCompletionStage<V>
-
runAfterEither
- Specified by:
runAfterEither
in interfaceCompletionStage<V>
-
runAfterEitherAsync
- Specified by:
runAfterEitherAsync
in interfaceCompletionStage<V>
-
runAfterEitherAsync
public CompletionStage<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor) - Specified by:
runAfterEitherAsync
in interfaceCompletionStage<V>
-
thenCompose
- Specified by:
thenCompose
in interfaceCompletionStage<V>
-
thenComposeAsync
- Specified by:
thenComposeAsync
in interfaceCompletionStage<V>
-
thenComposeAsync
public <U> CompletionStage<U> thenComposeAsync(Function<? super V, ? extends CompletionStage<U>> fn, Executor executor) - Specified by:
thenComposeAsync
in interfaceCompletionStage<V>
-
exceptionally
- Specified by:
exceptionally
in interfaceCompletionStage<V>
-
whenComplete
- Specified by:
whenComplete
in interfaceCompletionStage<V>
-
whenCompleteAsync
- Specified by:
whenCompleteAsync
in interfaceCompletionStage<V>
-
whenCompleteAsync
public CompletionStage<V> whenCompleteAsync(BiConsumer<? super V, ? super Throwable> action, Executor executor) - Specified by:
whenCompleteAsync
in interfaceCompletionStage<V>
-
handle
- Specified by:
handle
in interfaceCompletionStage<V>
-
handleAsync
- Specified by:
handleAsync
in interfaceCompletionStage<V>
-
handleAsync
public <U> CompletionStage<U> handleAsync(BiFunction<? super V, Throwable, ? extends U> fn, Executor executor) - Specified by:
handleAsync
in interfaceCompletionStage<V>
-
toCompletableFuture
- Specified by:
toCompletableFuture
in interfaceCompletionStage<V>
-
toString
Returns a string identifying this CompletableFutureTask, as well as its completion state. The state, in brackets, contains the String"Completed Normally"
or the String"Completed Exceptionally"
, or the String"Not completed"
followed by the number of CompletableFutures dependent upon its completion, if any.- Overrides:
toString
in classFutureTask<V>
- Returns:
- a string identifying this CompletableFutureTask, as well as its state
-