Package org.redisson.misc
Class RedissonPromise<T>
- java.lang.Object
-
- java.util.concurrent.CompletableFuture<T>
-
- org.redisson.misc.RedissonPromise<T>
-
- Type Parameters:
T
- type of object
- All Implemented Interfaces:
CompletionStage<T>
,Future<T>
,RFuture<T>
,RPromise<T>
- Direct Known Subclasses:
BatchPromise
,RedissonExecutorBatchFuture
,RemotePromise
public class RedissonPromise<T> extends CompletableFuture<T> implements RPromise<T>
- Author:
- Nikita Koksharov
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTask
-
-
Constructor Summary
Constructors Constructor Description RedissonPromise()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RPromise<T>
await()
Waits for this future to be completed.boolean
await(long timeoutMillis)
Waits for this future to be completed within the specified time limit.boolean
await(long timeout, TimeUnit unit)
Waits for this future to be completed within the specified time limit.RPromise<T>
awaitUninterruptibly()
Waits for this future to be completed without interruption.boolean
awaitUninterruptibly(long timeoutMillis)
Waits for this future to be completed within the specified time limit without interruption.boolean
awaitUninterruptibly(long timeout, TimeUnit unit)
Waits for this future to be completed within the specified time limit without interruption.boolean
cancel(boolean mayInterruptIfRunning)
Throwable
cause()
Returns the cause of the failed I/O operation if the I/O operation has failed.T
getNow()
Return the result without blocking.boolean
hasListeners()
boolean
isCancelled()
boolean
isDone()
boolean
isSuccess()
Returnstrue
if and only if the I/O operation was completed successfully.static <V> RFuture<V>
newFailedFuture(Throwable cause)
static <V> RFuture<V>
newSucceededFuture(V result)
void
onComplete(BiConsumer<? super T,? super Throwable> action)
boolean
setUncancellable()
Make this future impossible to cancel.RPromise<T>
sync()
Waits for this future until it is done, and rethrows the cause of the failure if this future failed.RPromise<T>
syncUninterruptibly()
Waits for this future until it is done, and rethrows the cause of the failure if this future failed.String
toString()
boolean
tryFailure(Throwable cause)
Marks this future as a failure and notifies all listeners.boolean
trySuccess(T result)
Marks this future as a success and notifies all listeners.-
Methods inherited from class java.util.concurrent.CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, complete, completeAsync, completeAsync, completedFuture, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCompletedExceptionally, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, whenComplete, whenCompleteAsync, whenCompleteAsync
-
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
acceptEither, acceptEitherAsync, acceptEitherAsync, applyToEither, applyToEitherAsync, applyToEitherAsync, exceptionally, handle, handleAsync, handleAsync, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, whenComplete, whenCompleteAsync, whenCompleteAsync
-
-
-
-
Method Detail
-
newSucceededFuture
public static <V> RFuture<V> newSucceededFuture(V result)
-
isSuccess
public boolean isSuccess()
Description copied from interface:RFuture
Returnstrue
if and only if the I/O operation was completed successfully.
-
isDone
public boolean isDone()
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfaceFuture<T>
- Overrides:
isCancelled
in classCompletableFuture<T>
-
trySuccess
public boolean trySuccess(T result)
Description copied from interface:RPromise
Marks this future as a success and notifies all listeners.- Specified by:
trySuccess
in interfaceRPromise<T>
- Parameters:
result
- object- Returns:
true
if and only if successfully marked this future as a success. Otherwisefalse
because this future is already marked as either a success or a failure.
-
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.
-
tryFailure
public boolean tryFailure(Throwable cause)
Description copied from interface:RPromise
Marks this future as a failure and notifies all listeners.- Specified by:
tryFailure
in interfaceRPromise<T>
- Parameters:
cause
- object- Returns:
true
if and only if successfully marked this future as a failure. Otherwisefalse
because this future is already marked as either a success or a failure.
-
setUncancellable
public boolean setUncancellable()
Description copied from interface:RPromise
Make this future impossible to cancel.- Specified by:
setUncancellable
in interfaceRPromise<T>
- Returns:
true
if and only if successfully marked this future as uncancellable or it is already done without being cancelled.false
if this future has been cancelled already.
-
await
public RPromise<T> await() throws InterruptedException
Description copied from interface:RFuture
Waits for this future to be completed.
-
awaitUninterruptibly
public RPromise<T> awaitUninterruptibly()
Description copied from interface:RFuture
Waits for this future to be completed without interruption. This method catches anInterruptedException
and discards it silently.- Specified by:
awaitUninterruptibly
in interfaceRFuture<T>
- Specified by:
awaitUninterruptibly
in interfaceRPromise<T>
- Returns:
- Future object
-
sync
public RPromise<T> sync() throws InterruptedException
Description copied from interface:RFuture
Waits for this future until it is done, and rethrows the cause of the failure if this future failed.
-
syncUninterruptibly
public RPromise<T> syncUninterruptibly()
Description copied from interface:RFuture
Waits for this future until it is done, and rethrows the cause of the failure if this future failed.- Specified by:
syncUninterruptibly
in interfaceRFuture<T>
- Specified by:
syncUninterruptibly
in interfaceRPromise<T>
- Returns:
- Future object
-
await
public boolean await(long timeout, TimeUnit unit) throws InterruptedException
Description copied from interface:RFuture
Waits for this future to be completed within the specified time limit.- Specified by:
await
in interfaceRFuture<T>
- 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
Waits for this future to be completed within the specified time limit.- Specified by:
await
in interfaceRFuture<T>
- 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
-
awaitUninterruptibly
public boolean awaitUninterruptibly(long timeout, TimeUnit unit)
Description copied from interface:RFuture
Waits for this future to be completed within the specified time limit without interruption. This method catches anInterruptedException
and discards it silently.- Specified by:
awaitUninterruptibly
in interfaceRFuture<T>
- 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
Waits for this future to be completed within the specified time limit without interruption. This method catches anInterruptedException
and discards it silently.- Specified by:
awaitUninterruptibly
in interfaceRFuture<T>
- Parameters:
timeoutMillis
- - timeout value- Returns:
true
if and only if the future was completed within the specified time limit
-
getNow
public T 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.
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
hasListeners
public boolean hasListeners()
- Specified by:
hasListeners
in interfaceRPromise<T>
-
toString
public String toString()
- Overrides:
toString
in classCompletableFuture<T>
-
onComplete
public void onComplete(BiConsumer<? super T,? super Throwable> action)
- Specified by:
onComplete
in interfaceRFuture<T>
-
-