Class CompletableFutureTask<V>
- java.lang.Object
-
- java.util.concurrent.FutureTask<V>
-
- com.linkedin.alpini.base.concurrency.CompletableFutureTask<V>
-
- All Implemented Interfaces:
java.lang.Runnable
,java.util.concurrent.CompletionStage<V>
,java.util.concurrent.Future<V>
,java.util.concurrent.RunnableFuture<V>
public class CompletableFutureTask<V> extends java.util.concurrent.FutureTask<V> implements java.util.concurrent.CompletionStage<V>
Created by acurtis on 4/4/17.
-
-
Constructor Summary
Constructors Constructor Description CompletableFutureTask(java.lang.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(java.util.concurrent.Callable<V> callable)
Creates aCompletableFutureTask
that will, upon running, execute the givenCallable
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.CompletionStage<java.lang.Void>
acceptEither(java.util.concurrent.CompletionStage<? extends V> other, java.util.function.Consumer<? super V> action)
java.util.concurrent.CompletionStage<java.lang.Void>
acceptEitherAsync(java.util.concurrent.CompletionStage<? extends V> other, java.util.function.Consumer<? super V> action)
java.util.concurrent.CompletionStage<java.lang.Void>
acceptEitherAsync(java.util.concurrent.CompletionStage<? extends V> other, java.util.function.Consumer<? super V> action, java.util.concurrent.Executor executor)
<U> java.util.concurrent.CompletionStage<U>
applyToEither(java.util.concurrent.CompletionStage<? extends V> other, java.util.function.Function<? super V,U> fn)
<U> java.util.concurrent.CompletionStage<U>
applyToEitherAsync(java.util.concurrent.CompletionStage<? extends V> other, java.util.function.Function<? super V,U> fn)
<U> java.util.concurrent.CompletionStage<U>
applyToEitherAsync(java.util.concurrent.CompletionStage<? extends V> other, java.util.function.Function<? super V,U> fn, java.util.concurrent.Executor executor)
boolean
cancel(boolean mayInterruptIfRunning)
protected void
done()
Use the methods provided by theCompletionStage
interface to perform actions after the completion of the task.java.util.concurrent.CompletionStage<V>
exceptionally(java.util.function.Function<java.lang.Throwable,? extends V> fn)
V
get()
V
get(long timeout, java.util.concurrent.TimeUnit unit)
<U> java.util.concurrent.CompletionStage<U>
handle(java.util.function.BiFunction<? super V,java.lang.Throwable,? extends U> fn)
<U> java.util.concurrent.CompletionStage<U>
handleAsync(java.util.function.BiFunction<? super V,java.lang.Throwable,? extends U> fn)
<U> java.util.concurrent.CompletionStage<U>
handleAsync(java.util.function.BiFunction<? super V,java.lang.Throwable,? extends U> fn, java.util.concurrent.Executor executor)
boolean
isCancelled()
boolean
isDone()
java.util.concurrent.CompletionStage<java.lang.Void>
runAfterBoth(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action)
java.util.concurrent.CompletionStage<java.lang.Void>
runAfterBothAsync(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action)
java.util.concurrent.CompletionStage<java.lang.Void>
runAfterBothAsync(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action, java.util.concurrent.Executor executor)
java.util.concurrent.CompletionStage<java.lang.Void>
runAfterEither(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action)
java.util.concurrent.CompletionStage<java.lang.Void>
runAfterEitherAsync(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action)
java.util.concurrent.CompletionStage<java.lang.Void>
runAfterEitherAsync(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action, java.util.concurrent.Executor executor)
protected void
set(V v)
protected void
setException(java.lang.Throwable t)
java.util.concurrent.CompletionStage<java.lang.Void>
thenAccept(java.util.function.Consumer<? super V> action)
java.util.concurrent.CompletionStage<java.lang.Void>
thenAcceptAsync(java.util.function.Consumer<? super V> action)
java.util.concurrent.CompletionStage<java.lang.Void>
thenAcceptAsync(java.util.function.Consumer<? super V> action, java.util.concurrent.Executor executor)
<U> java.util.concurrent.CompletionStage<java.lang.Void>
thenAcceptBoth(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiConsumer<? super V,? super U> action)
<U> java.util.concurrent.CompletionStage<java.lang.Void>
thenAcceptBothAsync(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiConsumer<? super V,? super U> action)
<U> java.util.concurrent.CompletionStage<java.lang.Void>
thenAcceptBothAsync(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiConsumer<? super V,? super U> action, java.util.concurrent.Executor executor)
<U> java.util.concurrent.CompletionStage<U>
thenApply(java.util.function.Function<? super V,? extends U> fn)
<U> java.util.concurrent.CompletionStage<U>
thenApplyAsync(java.util.function.Function<? super V,? extends U> fn)
<U> java.util.concurrent.CompletionStage<U>
thenApplyAsync(java.util.function.Function<? super V,? extends U> fn, java.util.concurrent.Executor executor)
<U,W>
java.util.concurrent.CompletionStage<W>thenCombine(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiFunction<? super V,? super U,? extends W> fn)
<U,W>
java.util.concurrent.CompletionStage<W>thenCombineAsync(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiFunction<? super V,? super U,? extends W> fn)
<U,W>
java.util.concurrent.CompletionStage<W>thenCombineAsync(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiFunction<? super V,? super U,? extends W> fn, java.util.concurrent.Executor executor)
<U> java.util.concurrent.CompletionStage<U>
thenCompose(java.util.function.Function<? super V,? extends java.util.concurrent.CompletionStage<U>> fn)
<U> java.util.concurrent.CompletionStage<U>
thenComposeAsync(java.util.function.Function<? super V,? extends java.util.concurrent.CompletionStage<U>> fn)
<U> java.util.concurrent.CompletionStage<U>
thenComposeAsync(java.util.function.Function<? super V,? extends java.util.concurrent.CompletionStage<U>> fn, java.util.concurrent.Executor executor)
java.util.concurrent.CompletionStage<java.lang.Void>
thenRun(java.lang.Runnable action)
java.util.concurrent.CompletionStage<java.lang.Void>
thenRunAsync(java.lang.Runnable action)
java.util.concurrent.CompletionStage<java.lang.Void>
thenRunAsync(java.lang.Runnable action, java.util.concurrent.Executor executor)
java.util.concurrent.CompletableFuture<V>
toCompletableFuture()
java.lang.String
toString()
Returns a string identifying this CompletableFutureTask, as well as its completion state.java.util.concurrent.CompletionStage<V>
whenComplete(java.util.function.BiConsumer<? super V,? super java.lang.Throwable> action)
java.util.concurrent.CompletionStage<V>
whenCompleteAsync(java.util.function.BiConsumer<? super V,? super java.lang.Throwable> action)
java.util.concurrent.CompletionStage<V>
whenCompleteAsync(java.util.function.BiConsumer<? super V,? super java.lang.Throwable> action, java.util.concurrent.Executor executor)
-
-
-
Constructor Detail
-
CompletableFutureTask
public CompletableFutureTask(java.util.concurrent.Callable<V> callable)
Creates aCompletableFutureTask
that will, upon running, execute the givenCallable
.- Parameters:
callable
- the callable task- Throws:
java.lang.NullPointerException
- if the callable is null
-
CompletableFutureTask
public CompletableFutureTask(java.lang.Runnable runnable, V result)
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:
java.lang.NullPointerException
- if the runnable is null
-
-
Method Detail
-
isCancelled
public boolean isCancelled()
-
isDone
public boolean isDone()
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
get
public V get() throws java.lang.InterruptedException, java.util.concurrent.ExecutionException
-
get
public V get(long timeout, @Nonnull java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.ExecutionException, java.util.concurrent.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 classjava.util.concurrent.FutureTask<V>
-
setException
protected void setException(java.lang.Throwable t)
- Overrides:
setException
in classjava.util.concurrent.FutureTask<V>
-
thenApply
public <U> java.util.concurrent.CompletionStage<U> thenApply(java.util.function.Function<? super V,? extends U> fn)
- Specified by:
thenApply
in interfacejava.util.concurrent.CompletionStage<V>
-
thenApplyAsync
public <U> java.util.concurrent.CompletionStage<U> thenApplyAsync(java.util.function.Function<? super V,? extends U> fn)
- Specified by:
thenApplyAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
thenApplyAsync
public <U> java.util.concurrent.CompletionStage<U> thenApplyAsync(java.util.function.Function<? super V,? extends U> fn, java.util.concurrent.Executor executor)
- Specified by:
thenApplyAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
thenAccept
public java.util.concurrent.CompletionStage<java.lang.Void> thenAccept(java.util.function.Consumer<? super V> action)
- Specified by:
thenAccept
in interfacejava.util.concurrent.CompletionStage<V>
-
thenAcceptAsync
public java.util.concurrent.CompletionStage<java.lang.Void> thenAcceptAsync(java.util.function.Consumer<? super V> action)
- Specified by:
thenAcceptAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
thenAcceptAsync
public java.util.concurrent.CompletionStage<java.lang.Void> thenAcceptAsync(java.util.function.Consumer<? super V> action, java.util.concurrent.Executor executor)
- Specified by:
thenAcceptAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
thenRun
public java.util.concurrent.CompletionStage<java.lang.Void> thenRun(java.lang.Runnable action)
- Specified by:
thenRun
in interfacejava.util.concurrent.CompletionStage<V>
-
thenRunAsync
public java.util.concurrent.CompletionStage<java.lang.Void> thenRunAsync(java.lang.Runnable action)
- Specified by:
thenRunAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
thenRunAsync
public java.util.concurrent.CompletionStage<java.lang.Void> thenRunAsync(java.lang.Runnable action, java.util.concurrent.Executor executor)
- Specified by:
thenRunAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
thenCombine
public <U,W> java.util.concurrent.CompletionStage<W> thenCombine(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiFunction<? super V,? super U,? extends W> fn)
- Specified by:
thenCombine
in interfacejava.util.concurrent.CompletionStage<V>
-
thenCombineAsync
public <U,W> java.util.concurrent.CompletionStage<W> thenCombineAsync(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiFunction<? super V,? super U,? extends W> fn)
- Specified by:
thenCombineAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
thenCombineAsync
public <U,W> java.util.concurrent.CompletionStage<W> thenCombineAsync(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiFunction<? super V,? super U,? extends W> fn, java.util.concurrent.Executor executor)
- Specified by:
thenCombineAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
thenAcceptBoth
public <U> java.util.concurrent.CompletionStage<java.lang.Void> thenAcceptBoth(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiConsumer<? super V,? super U> action)
- Specified by:
thenAcceptBoth
in interfacejava.util.concurrent.CompletionStage<V>
-
thenAcceptBothAsync
public <U> java.util.concurrent.CompletionStage<java.lang.Void> thenAcceptBothAsync(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiConsumer<? super V,? super U> action)
- Specified by:
thenAcceptBothAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
thenAcceptBothAsync
public <U> java.util.concurrent.CompletionStage<java.lang.Void> thenAcceptBothAsync(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiConsumer<? super V,? super U> action, java.util.concurrent.Executor executor)
- Specified by:
thenAcceptBothAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
runAfterBoth
public java.util.concurrent.CompletionStage<java.lang.Void> runAfterBoth(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action)
- Specified by:
runAfterBoth
in interfacejava.util.concurrent.CompletionStage<V>
-
runAfterBothAsync
public java.util.concurrent.CompletionStage<java.lang.Void> runAfterBothAsync(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action)
- Specified by:
runAfterBothAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
runAfterBothAsync
public java.util.concurrent.CompletionStage<java.lang.Void> runAfterBothAsync(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action, java.util.concurrent.Executor executor)
- Specified by:
runAfterBothAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
applyToEither
public <U> java.util.concurrent.CompletionStage<U> applyToEither(java.util.concurrent.CompletionStage<? extends V> other, java.util.function.Function<? super V,U> fn)
- Specified by:
applyToEither
in interfacejava.util.concurrent.CompletionStage<V>
-
applyToEitherAsync
public <U> java.util.concurrent.CompletionStage<U> applyToEitherAsync(java.util.concurrent.CompletionStage<? extends V> other, java.util.function.Function<? super V,U> fn)
- Specified by:
applyToEitherAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
applyToEitherAsync
public <U> java.util.concurrent.CompletionStage<U> applyToEitherAsync(java.util.concurrent.CompletionStage<? extends V> other, java.util.function.Function<? super V,U> fn, java.util.concurrent.Executor executor)
- Specified by:
applyToEitherAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
acceptEither
public java.util.concurrent.CompletionStage<java.lang.Void> acceptEither(java.util.concurrent.CompletionStage<? extends V> other, java.util.function.Consumer<? super V> action)
- Specified by:
acceptEither
in interfacejava.util.concurrent.CompletionStage<V>
-
acceptEitherAsync
public java.util.concurrent.CompletionStage<java.lang.Void> acceptEitherAsync(java.util.concurrent.CompletionStage<? extends V> other, java.util.function.Consumer<? super V> action)
- Specified by:
acceptEitherAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
acceptEitherAsync
public java.util.concurrent.CompletionStage<java.lang.Void> acceptEitherAsync(java.util.concurrent.CompletionStage<? extends V> other, java.util.function.Consumer<? super V> action, java.util.concurrent.Executor executor)
- Specified by:
acceptEitherAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
runAfterEither
public java.util.concurrent.CompletionStage<java.lang.Void> runAfterEither(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action)
- Specified by:
runAfterEither
in interfacejava.util.concurrent.CompletionStage<V>
-
runAfterEitherAsync
public java.util.concurrent.CompletionStage<java.lang.Void> runAfterEitherAsync(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action)
- Specified by:
runAfterEitherAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
runAfterEitherAsync
public java.util.concurrent.CompletionStage<java.lang.Void> runAfterEitherAsync(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action, java.util.concurrent.Executor executor)
- Specified by:
runAfterEitherAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
thenCompose
public <U> java.util.concurrent.CompletionStage<U> thenCompose(java.util.function.Function<? super V,? extends java.util.concurrent.CompletionStage<U>> fn)
- Specified by:
thenCompose
in interfacejava.util.concurrent.CompletionStage<V>
-
thenComposeAsync
public <U> java.util.concurrent.CompletionStage<U> thenComposeAsync(java.util.function.Function<? super V,? extends java.util.concurrent.CompletionStage<U>> fn)
- Specified by:
thenComposeAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
thenComposeAsync
public <U> java.util.concurrent.CompletionStage<U> thenComposeAsync(java.util.function.Function<? super V,? extends java.util.concurrent.CompletionStage<U>> fn, java.util.concurrent.Executor executor)
- Specified by:
thenComposeAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
exceptionally
public java.util.concurrent.CompletionStage<V> exceptionally(java.util.function.Function<java.lang.Throwable,? extends V> fn)
- Specified by:
exceptionally
in interfacejava.util.concurrent.CompletionStage<V>
-
whenComplete
public java.util.concurrent.CompletionStage<V> whenComplete(java.util.function.BiConsumer<? super V,? super java.lang.Throwable> action)
- Specified by:
whenComplete
in interfacejava.util.concurrent.CompletionStage<V>
-
whenCompleteAsync
public java.util.concurrent.CompletionStage<V> whenCompleteAsync(java.util.function.BiConsumer<? super V,? super java.lang.Throwable> action)
- Specified by:
whenCompleteAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
whenCompleteAsync
public java.util.concurrent.CompletionStage<V> whenCompleteAsync(java.util.function.BiConsumer<? super V,? super java.lang.Throwable> action, java.util.concurrent.Executor executor)
- Specified by:
whenCompleteAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
handle
public <U> java.util.concurrent.CompletionStage<U> handle(java.util.function.BiFunction<? super V,java.lang.Throwable,? extends U> fn)
- Specified by:
handle
in interfacejava.util.concurrent.CompletionStage<V>
-
handleAsync
public <U> java.util.concurrent.CompletionStage<U> handleAsync(java.util.function.BiFunction<? super V,java.lang.Throwable,? extends U> fn)
- Specified by:
handleAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
handleAsync
public <U> java.util.concurrent.CompletionStage<U> handleAsync(java.util.function.BiFunction<? super V,java.lang.Throwable,? extends U> fn, java.util.concurrent.Executor executor)
- Specified by:
handleAsync
in interfacejava.util.concurrent.CompletionStage<V>
-
toCompletableFuture
public java.util.concurrent.CompletableFuture<V> toCompletableFuture()
- Specified by:
toCompletableFuture
in interfacejava.util.concurrent.CompletionStage<V>
-
toString
public java.lang.String 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 classjava.util.concurrent.FutureTask<V>
- Returns:
- a string identifying this CompletableFutureTask, as well as its state
-
-