Package org.redisson.misc
Class RedissonPromise<T>
- java.lang.Object
-
- org.redisson.misc.RedissonPromise<T>
-
- Type Parameters:
T
- type of object
- Direct Known Subclasses:
BatchPromise
,RedissonExecutorBatchFuture
,RemotePromise
public class RedissonPromise<T> extends Object implements RPromise<T>
- Author:
- Nikita Koksharov
-
-
Constructor Summary
Constructors Constructor Description RedissonPromise()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RPromise<T>
addListener(io.netty.util.concurrent.FutureListener<? super T> listener)
Adds the specified listener to this future.RPromise<T>
addListeners(io.netty.util.concurrent.FutureListener<? super T>... listeners)
Adds the specified listeners to this future.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
get()
T
get(long timeout, TimeUnit unit)
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)
RPromise<T>
removeListener(io.netty.util.concurrent.FutureListener<? super T> listener)
Removes the first occurrence of the specified listener from this future.RPromise<T>
removeListeners(io.netty.util.concurrent.FutureListener<? super T>... listeners)
Removes the first occurrence for each of the listeners from this future.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.
-
-
-
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.
-
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.
-
addListener
public RPromise<T> addListener(io.netty.util.concurrent.FutureListener<? super T> listener)
Description copied from interface:RFuture
Adds the specified listener to this future. The specified listener is notified when this future is done. If this future is already completed, the specified listener is notified immediately.- Specified by:
addListener
in interfaceRFuture<T>
- Specified by:
addListener
in interfaceRPromise<T>
- Parameters:
listener
- - listener for future object- Returns:
- Future object
-
addListeners
public RPromise<T> addListeners(io.netty.util.concurrent.FutureListener<? super T>... listeners)
Description copied from interface:RFuture
Adds the specified listeners to this future. The specified listeners are notified when this future is done. If this future is already completed, the specified listeners are notified immediately.- Specified by:
addListeners
in interfaceRFuture<T>
- Specified by:
addListeners
in interfaceRPromise<T>
- Parameters:
listeners
- - listeners for future object- Returns:
- Future object
-
removeListener
public RPromise<T> removeListener(io.netty.util.concurrent.FutureListener<? super T> listener)
Description copied from interface:RFuture
Removes the first occurrence of the specified listener from this future. The specified listener is no longer notified when this future is done. If the specified listener is not associated with this future, this method does nothing and returns silently.- Specified by:
removeListener
in interfaceRFuture<T>
- Specified by:
removeListener
in interfaceRPromise<T>
- Parameters:
listener
- - listener for future object- Returns:
- Future object
-
removeListeners
public RPromise<T> removeListeners(io.netty.util.concurrent.FutureListener<? super T>... listeners)
Description copied from interface:RFuture
Removes the first occurrence for each of the listeners from this future. The specified listeners are no longer notified when this future is done. If the specified listeners are not associated with this future, this method does nothing and returns silently.- Specified by:
removeListeners
in interfaceRFuture<T>
- Specified by:
removeListeners
in interfaceRPromise<T>
- Parameters:
listeners
- - listeners for future object- Returns:
- Future object
-
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
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfaceFuture<T>
-
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
-
get
public T get() throws InterruptedException, ExecutionException
- Specified by:
get
in interfaceFuture<T>
- Throws:
InterruptedException
ExecutionException
-
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
-
get
public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
get
in interfaceFuture<T>
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
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>
-
-