Package org.redisson.misc
Class CompletableFutureWrapper<V>
- java.lang.Object
-
- org.redisson.misc.CompletableFutureWrapper<V>
-
- Type Parameters:
V- value type
- All Implemented Interfaces:
CompletionStage<V>,Future<V>,RFuture<V>
- Direct Known Subclasses:
RedissonExecutorBatchFuture,RedissonExecutorFuture,RedissonScheduledFuture
public class CompletableFutureWrapper<V> extends Object implements RFuture<V>
- Author:
- Nikita Koksharov
-
-
Constructor Summary
Constructors Constructor Description CompletableFutureWrapper(CompletableFuture<V> future)CompletableFutureWrapper(CompletionStage<V> stage)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletionStage<Void>acceptEither(CompletionStage<? extends V> other, Consumer<? super V> action)CompletionStage<Void>acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action)CompletionStage<Void>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)RFuture<V>await()Use snippet below instead.booleanawait(long timeoutMillis)Use snippet below instead.booleanawait(long timeout, TimeUnit unit)Use snippet below instead.RFuture<V>awaitUninterruptibly()Use snippet below instead.booleanawaitUninterruptibly(long timeoutMillis)Use snippet below instead.booleanawaitUninterruptibly(long timeout, TimeUnit unit)Use snippet below instead.booleancancel(boolean mayInterruptIfRunning)Throwablecause()Returns the cause of the failed I/O operation if the I/O operation has failed.booleancomplete(V value)CompletionStage<V>exceptionally(Function<Throwable,? extends V> fn)Vget()Vget(long timeout, TimeUnit unit)VgetNow()Return the result without blocking.VgetNow(V valueIfAbsent)<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)booleanisCancelled()booleanisDone()booleanisSuccess()Returnstrueif and only if the I/O operation was completed successfully.Vjoin()Use toCompletableFuture().join() method insteadvoidonComplete(BiConsumer<? super V,? super Throwable> action)Use whenComplete() method insteadCompletionStage<Void>runAfterBoth(CompletionStage<?> other, Runnable action)CompletionStage<Void>runAfterBothAsync(CompletionStage<?> other, Runnable action)CompletionStage<Void>runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)CompletionStage<Void>runAfterEither(CompletionStage<?> other, Runnable action)CompletionStage<Void>runAfterEitherAsync(CompletionStage<?> other, Runnable action)CompletionStage<Void>runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)RFuture<V>sync()Use toCompletableFuture().get() method insteadRFuture<V>syncUninterruptibly()Use toCompletableFuture().join() method insteadCompletionStage<Void>thenAccept(Consumer<? super V> action)CompletionStage<Void>thenAcceptAsync(Consumer<? super V> action)CompletionStage<Void>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>thenApply(Function<? super V,? extends U> fn)<U> CompletionStage<U>thenApplyAsync(Function<? super V,? extends U> fn)<U> CompletionStage<U>thenApplyAsync(Function<? super V,? extends U> fn, Executor executor)<U,V1>
CompletionStage<V1>thenCombine(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)<U,V1>
CompletionStage<V1>thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)<U,V1>
CompletionStage<V1>thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> 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)CompletionStage<Void>thenRun(Runnable action)CompletionStage<Void>thenRunAsync(Runnable action)CompletionStage<Void>thenRunAsync(Runnable action, Executor executor)CompletableFuture<V>toCompletableFuture()CompletionStage<V>whenComplete(BiConsumer<? super V,? super Throwable> action)CompletionStage<V>whenCompleteAsync(BiConsumer<? super V,? super Throwable> action)CompletionStage<V>whenCompleteAsync(BiConsumer<? super V,? super Throwable> action, Executor executor)
-
-
-
Constructor Detail
-
CompletableFutureWrapper
public CompletableFutureWrapper(CompletionStage<V> stage)
-
CompletableFutureWrapper
public CompletableFutureWrapper(CompletableFuture<V> future)
-
-
Method Detail
-
thenApply
public <U> CompletionStage<U> thenApply(Function<? super V,? extends U> fn)
- Specified by:
thenApplyin interfaceCompletionStage<V>
-
thenApplyAsync
public <U> CompletionStage<U> thenApplyAsync(Function<? super V,? extends U> fn)
- Specified by:
thenApplyAsyncin interfaceCompletionStage<V>
-
thenApplyAsync
public <U> CompletionStage<U> thenApplyAsync(Function<? super V,? extends U> fn, Executor executor)
- Specified by:
thenApplyAsyncin interfaceCompletionStage<V>
-
thenAccept
public CompletionStage<Void> thenAccept(Consumer<? super V> action)
- Specified by:
thenAcceptin interfaceCompletionStage<V>
-
thenAcceptAsync
public CompletionStage<Void> thenAcceptAsync(Consumer<? super V> action)
- Specified by:
thenAcceptAsyncin interfaceCompletionStage<V>
-
thenAcceptAsync
public CompletionStage<Void> thenAcceptAsync(Consumer<? super V> action, Executor executor)
- Specified by:
thenAcceptAsyncin interfaceCompletionStage<V>
-
thenRun
public CompletionStage<Void> thenRun(Runnable action)
- Specified by:
thenRunin interfaceCompletionStage<V>
-
thenRunAsync
public CompletionStage<Void> thenRunAsync(Runnable action)
- Specified by:
thenRunAsyncin interfaceCompletionStage<V>
-
thenRunAsync
public CompletionStage<Void> thenRunAsync(Runnable action, Executor executor)
- Specified by:
thenRunAsyncin interfaceCompletionStage<V>
-
thenCombine
public <U,V1> CompletionStage<V1> thenCombine(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)
- Specified by:
thenCombinein interfaceCompletionStage<V>
-
thenCombineAsync
public <U,V1> CompletionStage<V1> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)
- Specified by:
thenCombineAsyncin interfaceCompletionStage<V>
-
thenCombineAsync
public <U,V1> CompletionStage<V1> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn, Executor executor)
- Specified by:
thenCombineAsyncin interfaceCompletionStage<V>
-
thenAcceptBoth
public <U> CompletionStage<Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action)
- Specified by:
thenAcceptBothin interfaceCompletionStage<V>
-
thenAcceptBothAsync
public <U> CompletionStage<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action)
- Specified by:
thenAcceptBothAsyncin interfaceCompletionStage<V>
-
thenAcceptBothAsync
public <U> CompletionStage<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super V,? super U> action, Executor executor)
- Specified by:
thenAcceptBothAsyncin interfaceCompletionStage<V>
-
runAfterBoth
public CompletionStage<Void> runAfterBoth(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBothin interfaceCompletionStage<V>
-
runAfterBothAsync
public CompletionStage<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBothAsyncin interfaceCompletionStage<V>
-
runAfterBothAsync
public CompletionStage<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterBothAsyncin interfaceCompletionStage<V>
-
applyToEither
public <U> CompletionStage<U> applyToEither(CompletionStage<? extends V> other, Function<? super V,U> fn)
- Specified by:
applyToEitherin interfaceCompletionStage<V>
-
applyToEitherAsync
public <U> CompletionStage<U> applyToEitherAsync(CompletionStage<? extends V> other, Function<? super V,U> fn)
- Specified by:
applyToEitherAsyncin interfaceCompletionStage<V>
-
applyToEitherAsync
public <U> CompletionStage<U> applyToEitherAsync(CompletionStage<? extends V> other, Function<? super V,U> fn, Executor executor)
- Specified by:
applyToEitherAsyncin interfaceCompletionStage<V>
-
acceptEither
public CompletionStage<Void> acceptEither(CompletionStage<? extends V> other, Consumer<? super V> action)
- Specified by:
acceptEitherin interfaceCompletionStage<V>
-
acceptEitherAsync
public CompletionStage<Void> acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action)
- Specified by:
acceptEitherAsyncin interfaceCompletionStage<V>
-
acceptEitherAsync
public CompletionStage<Void> acceptEitherAsync(CompletionStage<? extends V> other, Consumer<? super V> action, Executor executor)
- Specified by:
acceptEitherAsyncin interfaceCompletionStage<V>
-
runAfterEither
public CompletionStage<Void> runAfterEither(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherin interfaceCompletionStage<V>
-
runAfterEitherAsync
public CompletionStage<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherAsyncin interfaceCompletionStage<V>
-
runAfterEitherAsync
public CompletionStage<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterEitherAsyncin interfaceCompletionStage<V>
-
thenCompose
public <U> CompletionStage<U> thenCompose(Function<? super V,? extends CompletionStage<U>> fn)
- Specified by:
thenComposein interfaceCompletionStage<V>
-
thenComposeAsync
public <U> CompletionStage<U> thenComposeAsync(Function<? super V,? extends CompletionStage<U>> fn)
- Specified by:
thenComposeAsyncin interfaceCompletionStage<V>
-
thenComposeAsync
public <U> CompletionStage<U> thenComposeAsync(Function<? super V,? extends CompletionStage<U>> fn, Executor executor)
- Specified by:
thenComposeAsyncin interfaceCompletionStage<V>
-
handle
public <U> CompletionStage<U> handle(BiFunction<? super V,Throwable,? extends U> fn)
- Specified by:
handlein interfaceCompletionStage<V>
-
handleAsync
public <U> CompletionStage<U> handleAsync(BiFunction<? super V,Throwable,? extends U> fn)
- Specified by:
handleAsyncin interfaceCompletionStage<V>
-
handleAsync
public <U> CompletionStage<U> handleAsync(BiFunction<? super V,Throwable,? extends U> fn, Executor executor)
- Specified by:
handleAsyncin interfaceCompletionStage<V>
-
whenComplete
public CompletionStage<V> whenComplete(BiConsumer<? super V,? super Throwable> action)
- Specified by:
whenCompletein interfaceCompletionStage<V>
-
whenCompleteAsync
public CompletionStage<V> whenCompleteAsync(BiConsumer<? super V,? super Throwable> action)
- Specified by:
whenCompleteAsyncin interfaceCompletionStage<V>
-
whenCompleteAsync
public CompletionStage<V> whenCompleteAsync(BiConsumer<? super V,? super Throwable> action, Executor executor)
- Specified by:
whenCompleteAsyncin interfaceCompletionStage<V>
-
exceptionally
public CompletionStage<V> exceptionally(Function<Throwable,? extends V> fn)
- Specified by:
exceptionallyin interfaceCompletionStage<V>
-
toCompletableFuture
public CompletableFuture<V> toCompletableFuture()
- Specified by:
toCompletableFuturein interfaceCompletionStage<V>
-
complete
public boolean complete(V value)
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfaceFuture<V>
-
get
public V get() throws InterruptedException, ExecutionException
- Specified by:
getin interfaceFuture<V>- Throws:
InterruptedExceptionExecutionException
-
get
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
getin interfaceFuture<V>- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
isSuccess
public boolean isSuccess()
Description copied from interface:RFutureReturnstrueif and only if the I/O operation was completed successfully.
-
cause
public Throwable cause()
Description copied from interface:RFutureReturns the cause of the failed I/O operation if the I/O operation has failed.
-
getNow
public V getNow()
Description copied from interface:RFutureReturn the result without blocking. If the future is not done yet this will returnnull. As it is possible that anullvalue is used to mark the future as successful you also need to check if the future is really done withFuture.isDone()and not relay on the returnednullvalue.
-
join
public V join()
Description copied from interface:RFutureUse toCompletableFuture().join() method instead
-
await
public boolean await(long timeout, TimeUnit unit) throws InterruptedExceptionDescription copied from interface:RFutureUse snippet below instead.try { toCompletableFuture().get(); } catch (Exception e) { // skip }- Specified by:
awaitin interfaceRFuture<V>- Parameters:
timeout- - wait timeoutunit- - time unit- Returns:
trueif and only if the future was completed within the specified time limit- Throws:
InterruptedException- if the current thread was interrupted
-
await
public boolean await(long timeoutMillis) throws InterruptedExceptionDescription copied from interface:RFutureUse snippet below instead.try { toCompletableFuture().get(); } catch (Exception e) { // skip }- Specified by:
awaitin interfaceRFuture<V>- Parameters:
timeoutMillis- - timeout value- Returns:
trueif and only if the future was completed within the specified time limit- Throws:
InterruptedException- if the current thread was interrupted
-
sync
public RFuture<V> sync() throws InterruptedException
Description copied from interface:RFutureUse toCompletableFuture().get() method instead- Specified by:
syncin interfaceRFuture<V>- Returns:
- Future object
- Throws:
InterruptedException- if the current thread was interrupted
-
syncUninterruptibly
public RFuture<V> syncUninterruptibly()
Description copied from interface:RFutureUse toCompletableFuture().join() method instead- Specified by:
syncUninterruptiblyin interfaceRFuture<V>- Returns:
- Future object
-
await
public RFuture<V> await() throws InterruptedException
Description copied from interface:RFutureUse snippet below instead.try { toCompletableFuture().get(); } catch (Exception e) { // skip }- Specified by:
awaitin interfaceRFuture<V>- Returns:
- Future object
- Throws:
InterruptedException- if the current thread was interrupted
-
awaitUninterruptibly
public RFuture<V> awaitUninterruptibly()
Description copied from interface:RFutureUse snippet below instead.try { rFuture.toCompletableFuture().join(); } catch (Exception e) { // skip }- Specified by:
awaitUninterruptiblyin interfaceRFuture<V>- Returns:
- Future object
-
awaitUninterruptibly
public boolean awaitUninterruptibly(long timeout, TimeUnit unit)Description copied from interface:RFutureUse snippet below instead.try { toCompletableFuture().get(); } catch (Exception e) { // skip }- Specified by:
awaitUninterruptiblyin interfaceRFuture<V>- Parameters:
timeout- - timeout valueunit- - timeout unit value- Returns:
trueif and only if the future was completed within the specified time limit
-
awaitUninterruptibly
public boolean awaitUninterruptibly(long timeoutMillis)
Description copied from interface:RFutureUse snippet below instead.try { toCompletableFuture().get(); } catch (Exception e) { // skip }- Specified by:
awaitUninterruptiblyin interfaceRFuture<V>- Parameters:
timeoutMillis- - timeout value- Returns:
trueif and only if the future was completed within the specified time limit
-
onComplete
public void onComplete(BiConsumer<? super V,? super Throwable> action)
Description copied from interface:RFutureUse whenComplete() method instead- Specified by:
onCompletein interfaceRFuture<V>- Parameters:
action- - callback
-
-