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)
CompletableFutureWrapper(V value)
-
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.boolean
await(long timeoutMillis)
Use snippet below instead.boolean
await(long timeout, TimeUnit unit)
Use snippet below instead.RFuture<V>
awaitUninterruptibly()
Use snippet below instead.boolean
awaitUninterruptibly(long timeoutMillis)
Use snippet below instead.boolean
awaitUninterruptibly(long timeout, TimeUnit unit)
Use snippet below instead.boolean
cancel(boolean mayInterruptIfRunning)
Throwable
cause()
Returns the cause of the failed I/O operation if the I/O operation has failed.boolean
complete(V value)
CompletionStage<V>
exceptionally(Function<Throwable,? extends V> fn)
V
get()
V
get(long timeout, TimeUnit unit)
V
getNow()
Return the result without blocking.V
getNow(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)
boolean
isCancelled()
boolean
isDone()
boolean
isSuccess()
Returnstrue
if and only if the I/O operation was completed successfully.V
join()
Use toCompletableFuture().join() method insteadvoid
onComplete(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(V value)
-
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:
thenApply
in interfaceCompletionStage<V>
-
thenApplyAsync
public <U> CompletionStage<U> thenApplyAsync(Function<? super V,? extends U> fn)
- Specified by:
thenApplyAsync
in interfaceCompletionStage<V>
-
thenApplyAsync
public <U> CompletionStage<U> thenApplyAsync(Function<? super V,? extends U> fn, Executor executor)
- Specified by:
thenApplyAsync
in interfaceCompletionStage<V>
-
thenAccept
public CompletionStage<Void> thenAccept(Consumer<? super V> action)
- Specified by:
thenAccept
in interfaceCompletionStage<V>
-
thenAcceptAsync
public CompletionStage<Void> thenAcceptAsync(Consumer<? super V> action)
- Specified by:
thenAcceptAsync
in interfaceCompletionStage<V>
-
thenAcceptAsync
public CompletionStage<Void> thenAcceptAsync(Consumer<? super V> action, Executor executor)
- Specified by:
thenAcceptAsync
in interfaceCompletionStage<V>
-
thenRun
public CompletionStage<Void> thenRun(Runnable action)
- Specified by:
thenRun
in interfaceCompletionStage<V>
-
thenRunAsync
public CompletionStage<Void> thenRunAsync(Runnable action)
- Specified by:
thenRunAsync
in interfaceCompletionStage<V>
-
thenRunAsync
public CompletionStage<Void> thenRunAsync(Runnable action, Executor executor)
- Specified by:
thenRunAsync
in interfaceCompletionStage<V>
-
thenCombine
public <U,V1> CompletionStage<V1> thenCombine(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)
- Specified by:
thenCombine
in interfaceCompletionStage<V>
-
thenCombineAsync
public <U,V1> CompletionStage<V1> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super V,? super U,? extends V1> fn)
- Specified by:
thenCombineAsync
in 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:
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
public CompletionStage<Void> runAfterBoth(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBoth
in interfaceCompletionStage<V>
-
runAfterBothAsync
public CompletionStage<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action)
- 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
public CompletionStage<Void> runAfterEither(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEither
in interfaceCompletionStage<V>
-
runAfterEitherAsync
public CompletionStage<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherAsync
in interfaceCompletionStage<V>
-
runAfterEitherAsync
public CompletionStage<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterEitherAsync
in interfaceCompletionStage<V>
-
thenCompose
public <U> CompletionStage<U> thenCompose(Function<? super V,? extends CompletionStage<U>> fn)
- Specified by:
thenCompose
in interfaceCompletionStage<V>
-
thenComposeAsync
public <U> CompletionStage<U> thenComposeAsync(Function<? super V,? extends CompletionStage<U>> fn)
- 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>
-
handle
public <U> CompletionStage<U> handle(BiFunction<? super V,Throwable,? extends U> fn)
- Specified by:
handle
in interfaceCompletionStage<V>
-
handleAsync
public <U> CompletionStage<U> handleAsync(BiFunction<? super V,Throwable,? extends U> fn)
- 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>
-
whenComplete
public CompletionStage<V> whenComplete(BiConsumer<? super V,? super Throwable> action)
- Specified by:
whenComplete
in interfaceCompletionStage<V>
-
whenCompleteAsync
public CompletionStage<V> whenCompleteAsync(BiConsumer<? super V,? super Throwable> action)
- 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>
-
exceptionally
public CompletionStage<V> exceptionally(Function<Throwable,? extends V> fn)
- Specified by:
exceptionally
in interfaceCompletionStage<V>
-
toCompletableFuture
public CompletableFuture<V> toCompletableFuture()
- Specified by:
toCompletableFuture
in interfaceCompletionStage<V>
-
complete
public boolean complete(V value)
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfaceFuture<V>
-
get
public V get() throws InterruptedException, ExecutionException
- Specified by:
get
in interfaceFuture<V>
- Throws:
InterruptedException
ExecutionException
-
get
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
get
in interfaceFuture<V>
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
isSuccess
public boolean isSuccess()
Description copied from interface:RFuture
Returnstrue
if and only if the I/O operation was completed successfully.
-
cause
public Throwable cause()
Description copied from interface:RFuture
Returns the cause of the failed I/O operation if the I/O operation has failed.
-
getNow
public V getNow()
Description copied from interface:RFuture
Return the result without blocking. If the future is not done yet this will returnnull
. As it is possible that anull
value 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 returnednull
value.
-
join
public V join()
Description copied from interface:RFuture
Use toCompletableFuture().join() method instead
-
await
public boolean await(long timeout, TimeUnit unit) throws InterruptedException
Description copied from interface:RFuture
Use snippet below instead.try { toCompletableFuture().get(); } catch (Exception e) { // skip }
- Specified by:
await
in interfaceRFuture<V>
- Parameters:
timeout
- - wait timeoutunit
- - time unit- Returns:
true
if 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 InterruptedException
Description copied from interface:RFuture
Use snippet below instead.try { toCompletableFuture().get(); } catch (Exception e) { // skip }
- Specified by:
await
in interfaceRFuture<V>
- Parameters:
timeoutMillis
- - timeout value- Returns:
true
if 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:RFuture
Use toCompletableFuture().get() method instead- Specified by:
sync
in interfaceRFuture<V>
- Returns:
- Future object
- Throws:
InterruptedException
- if the current thread was interrupted
-
syncUninterruptibly
public RFuture<V> syncUninterruptibly()
Description copied from interface:RFuture
Use toCompletableFuture().join() method instead- Specified by:
syncUninterruptibly
in interfaceRFuture<V>
- Returns:
- Future object
-
await
public RFuture<V> await() throws InterruptedException
Description copied from interface:RFuture
Use snippet below instead.try { toCompletableFuture().get(); } catch (Exception e) { // skip }
- Specified by:
await
in interfaceRFuture<V>
- Returns:
- Future object
- Throws:
InterruptedException
- if the current thread was interrupted
-
awaitUninterruptibly
public RFuture<V> awaitUninterruptibly()
Description copied from interface:RFuture
Use snippet below instead.try { rFuture.toCompletableFuture().join(); } catch (Exception e) { // skip }
- Specified by:
awaitUninterruptibly
in interfaceRFuture<V>
- Returns:
- Future object
-
awaitUninterruptibly
public boolean awaitUninterruptibly(long timeout, TimeUnit unit)
Description copied from interface:RFuture
Use snippet below instead.try { toCompletableFuture().get(); } catch (Exception e) { // skip }
- Specified by:
awaitUninterruptibly
in interfaceRFuture<V>
- Parameters:
timeout
- - timeout valueunit
- - timeout unit value- Returns:
true
if and only if the future was completed within the specified time limit
-
awaitUninterruptibly
public boolean awaitUninterruptibly(long timeoutMillis)
Description copied from interface:RFuture
Use snippet below instead.try { toCompletableFuture().get(); } catch (Exception e) { // skip }
- Specified by:
awaitUninterruptibly
in interfaceRFuture<V>
- Parameters:
timeoutMillis
- - timeout value- Returns:
true
if 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:RFuture
Use whenComplete() method instead- Specified by:
onComplete
in interfaceRFuture<V>
- Parameters:
action
- - callback
-
-