-
- All Known Implementing Classes:
DefaultPromise
public interface Promise<V>
SpecialFuture
which is writable.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Future<V>
asFuture()
Return theFuture
instance is associated with this promise.boolean
cancel()
Cancel this asynchronous operation, unless it has already been completed or is not cancellable.Throwable
cause()
Returns the cause of the failed operation if the operation has failed.EventExecutor
executor()
V
getNow()
Return the successful result of this asynchronous operation, if any.boolean
isCancellable()
Returnstrue
if and only if the operation can be cancelled viacancel()
.boolean
isCancelled()
Returntrue
if this operation has been cancelled.boolean
isDone()
Returntrue
if this operation has been completed either successfully, unsuccessfully, or through cancellation.boolean
isFailed()
Returnstrue
if and only if the operation was completed and failed.boolean
isSuccess()
Returnstrue
if and only if the operation was completed successfully.Promise<V>
setFailure(Throwable cause)
Marks this promise as a failure and notifies all listeners attached to the future.Promise<V>
setSuccess(V result)
Marks this promise as a success and notifies all listeners attached to the future.boolean
setUncancellable()
Make this promise impossible to cancel.boolean
tryFailure(Throwable cause)
Marks this promise as a failure and notifies all listeners.boolean
trySuccess(V result)
Marks this future as a success and notifies all listeners.
-
-
-
Method Detail
-
setSuccess
Promise<V> setSuccess(V result)
Marks this promise as a success and notifies all listeners attached to the future.If it is success or failed already it will throw an
IllegalStateException
.
-
trySuccess
boolean trySuccess(V result)
Marks this future as a success and notifies all listeners.- Returns:
true
if and only if successfully marked this promise as a success. Otherwisefalse
because this promise is already marked as either a success or a failure.
-
setFailure
Promise<V> setFailure(Throwable cause)
Marks this promise as a failure and notifies all listeners attached to the future.If it is success or failed already it will throw an
IllegalStateException
.
-
tryFailure
boolean tryFailure(Throwable cause)
Marks this promise as a failure and notifies all listeners.- Returns:
true
if and only if successfully marked this promise as a failure. Otherwisefalse
because this promise is already marked as either a success or a failure.
-
setUncancellable
boolean setUncancellable()
Make this promise impossible to cancel.- Returns:
true
if and only if successfully marked this promise as uncancellable. Otherwisefalse
if this promise has been cancelled already, or has completed.
-
asFuture
Future<V> asFuture()
Return theFuture
instance is associated with this promise. This future will be completed upon completion of this promise.- Returns:
- A future instance associated with this promise.
-
cancel
boolean cancel()
Cancel this asynchronous operation, unless it has already been completed or is not cancellable.A cancelled operation is considered to be done and failed.
If the cancellation was successful, the result of this operation will be that it has failed with a
CancellationException
.Cancellation will not cause any threads working on the operation to be interrupted.
- Returns:
true
if the operation was cancelled by this call, otherwisefalse
.
-
isSuccess
boolean isSuccess()
Returnstrue
if and only if the operation was completed successfully.
-
isFailed
boolean isFailed()
Returnstrue
if and only if the operation was completed and failed.
-
isCancelled
boolean isCancelled()
Returntrue
if this operation has been cancelled.- Returns:
true
if this operation has been cancelled, otherwisefalse
.
-
isDone
boolean isDone()
Returntrue
if this operation has been completed either successfully, unsuccessfully, or through cancellation.- Returns:
true
if this operation has completed, otherwisefalse
.
-
isCancellable
boolean isCancellable()
Returnstrue
if and only if the operation can be cancelled viacancel()
. Note that this is inherently racy, as the operation could be made uncancellable at any time.- Returns:
true
if this operation can be cancelled.
-
getNow
V getNow()
Return the successful result of this asynchronous operation, if any. If the operation has not yet been completed, then this will throwIllegalStateException
. If the operation has been cancelled or failed with an exception, then this returnsnull
. Note that asynchronous operations can also be completed successfully with anull
result.- Returns:
- the result of this operation, if completed successfully.
- Throws:
IllegalStateException
- if thisFuture
orPromise
has not completed yet.
-
cause
Throwable cause()
Returns the cause of the failed operation if the operation has failed.- Returns:
- The cause of the failure, if any. Otherwise
null
if succeeded. - Throws:
IllegalStateException
- if thisPromise
has not completed yet.
-
executor
EventExecutor executor()
-
-