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 aCompletableFutureTaskthat will, upon running, execute the givenRunnable, and arrange thatgetwill return the given result on successful completion.CompletableFutureTask(java.util.concurrent.Callable<V> callable)Creates aCompletableFutureTaskthat 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)booleancancel(boolean mayInterruptIfRunning)protected voiddone()Use the methods provided by theCompletionStageinterface 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)Vget()Vget(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)booleanisCancelled()booleanisDone()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 voidset(V v)protected voidsetException(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.StringtoString()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 aCompletableFutureTaskthat 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 aCompletableFutureTaskthat will, upon running, execute the givenRunnable, and arrange thatgetwill 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 theCompletionStageinterface to perform actions after the completion of the task. This method is final and may not be overridden.- Overrides:
donein classjava.util.concurrent.FutureTask<V>
-
setException
protected void setException(java.lang.Throwable t)
- Overrides:
setExceptionin 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:
thenApplyin 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:
thenApplyAsyncin 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:
thenApplyAsyncin interfacejava.util.concurrent.CompletionStage<V>
-
thenAccept
public java.util.concurrent.CompletionStage<java.lang.Void> thenAccept(java.util.function.Consumer<? super V> action)
- Specified by:
thenAcceptin interfacejava.util.concurrent.CompletionStage<V>
-
thenAcceptAsync
public java.util.concurrent.CompletionStage<java.lang.Void> thenAcceptAsync(java.util.function.Consumer<? super V> action)
- Specified by:
thenAcceptAsyncin 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:
thenAcceptAsyncin interfacejava.util.concurrent.CompletionStage<V>
-
thenRun
public java.util.concurrent.CompletionStage<java.lang.Void> thenRun(java.lang.Runnable action)
- Specified by:
thenRunin interfacejava.util.concurrent.CompletionStage<V>
-
thenRunAsync
public java.util.concurrent.CompletionStage<java.lang.Void> thenRunAsync(java.lang.Runnable action)
- Specified by:
thenRunAsyncin 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:
thenRunAsyncin 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:
thenCombinein 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:
thenCombineAsyncin 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:
thenCombineAsyncin 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:
thenAcceptBothin 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:
thenAcceptBothAsyncin 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:
thenAcceptBothAsyncin 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:
runAfterBothin 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:
runAfterBothAsyncin 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:
runAfterBothAsyncin 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:
applyToEitherin 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:
applyToEitherAsyncin 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:
applyToEitherAsyncin 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:
acceptEitherin 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:
acceptEitherAsyncin 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:
acceptEitherAsyncin 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:
runAfterEitherin 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:
runAfterEitherAsyncin 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:
runAfterEitherAsyncin 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:
thenComposein 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:
thenComposeAsyncin 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:
thenComposeAsyncin 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:
exceptionallyin 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:
whenCompletein 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:
whenCompleteAsyncin 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:
whenCompleteAsyncin 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:
handlein 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:
handleAsyncin 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:
handleAsyncin interfacejava.util.concurrent.CompletionStage<V>
-
toCompletableFuture
public java.util.concurrent.CompletableFuture<V> toCompletableFuture()
- Specified by:
toCompletableFuturein 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:
toStringin classjava.util.concurrent.FutureTask<V>- Returns:
- a string identifying this CompletableFutureTask, as well as its state
-
-