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>
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()Use snippet below instead.booleanawait(long timeoutMillis)Use snippet below instead.booleanawait(long timeout, TimeUnit unit)Use snippet below instead.RPromise<T>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.TgetNow()Return the result without blocking.booleanhasListeners()booleanisCancelled()booleanisDone()booleanisSuccess()Returnstrueif and only if the I/O operation was completed successfully.static <V> RFuture<V>newFailedFuture(Throwable cause)static <V> RFuture<V>newSucceededFuture(V result)voidonComplete(BiConsumer<? super T,? super Throwable> action)Use whenComplete() method insteadbooleansetUncancellable()Make this future impossible to cancel.RPromise<T>sync()Use toCompletableFuture().get() method insteadRPromise<T>syncUninterruptibly()Use toCompletableFuture().join() method insteadStringtoString()booleantryFailure(Throwable cause)Marks this future as a failure and notifies all listeners.booleantrySuccess(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:RFutureReturnstrueif and only if the I/O operation was completed successfully.
-
isDone
public boolean isDone()
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelledin interfaceFuture<T>- Overrides:
isCancelledin classCompletableFuture<T>
-
trySuccess
public boolean trySuccess(T result)
Description copied from interface:RPromiseMarks this future as a success and notifies all listeners.- Specified by:
trySuccessin interfaceRPromise<T>- Parameters:
result- object- Returns:
trueif and only if successfully marked this future as a success. Otherwisefalsebecause this future is already marked as either a success or a failure.
-
cause
public Throwable cause()
Description copied from interface:RFutureReturns 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:RPromiseMarks this future as a failure and notifies all listeners.- Specified by:
tryFailurein interfaceRPromise<T>- Parameters:
cause- object- Returns:
trueif and only if successfully marked this future as a failure. Otherwisefalsebecause this future is already marked as either a success or a failure.
-
setUncancellable
public boolean setUncancellable()
Description copied from interface:RPromiseMake this future impossible to cancel.- Specified by:
setUncancellablein interfaceRPromise<T>- Returns:
trueif and only if successfully marked this future as uncancellable or it is already done without being cancelled.falseif this future has been cancelled already.
-
await
public RPromise<T> await() throws InterruptedException
Description copied from interface:RFutureUse snippet below instead.try { toCompletableFuture().get(); } catch (Exception e) { // skip }
-
awaitUninterruptibly
public RPromise<T> awaitUninterruptibly()
Description copied from interface:RFutureUse snippet below instead.try { rFuture.toCompletableFuture().join(); } catch (Exception e) { // skip }- Specified by:
awaitUninterruptiblyin interfaceRFuture<T>- Specified by:
awaitUninterruptiblyin interfaceRPromise<T>- Returns:
- Future object
-
sync
public RPromise<T> sync() throws InterruptedException
Description copied from interface:RFutureUse toCompletableFuture().get() method instead
-
syncUninterruptibly
public RPromise<T> syncUninterruptibly()
Description copied from interface:RFutureUse toCompletableFuture().join() method instead- Specified by:
syncUninterruptiblyin interfaceRFuture<T>- Specified by:
syncUninterruptiblyin interfaceRPromise<T>- Returns:
- Future object
-
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<T>- 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<T>- 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
-
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<T>- 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<T>- Parameters:
timeoutMillis- - timeout value- Returns:
trueif and only if the future was completed within the specified time limit
-
getNow
public T 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.
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
-
hasListeners
public boolean hasListeners()
- Specified by:
hasListenersin interfaceRPromise<T>
-
toString
public String toString()
- Overrides:
toStringin classCompletableFuture<T>
-
onComplete
public void onComplete(BiConsumer<? super T,? super Throwable> action)
Description copied from interface:RFutureUse whenComplete() method instead- Specified by:
onCompletein interfaceRFuture<T>- Parameters:
action- - callback
-
-