Package cn.sliew.milky.concurrent
Interface Promise<V>
-
- All Known Subinterfaces:
ProgressivePromise<V>
- All Known Implementing Classes:
DefaultProgressivePromise,DefaultPromise
public interface Promise<V> extends Future<V>
SpecialFuturewhich is writable.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Promise<V>addListener(FutureListener<? extends Future<? super V>> listener)Adds the specified listener to this future.Promise<V>await()Waits for this future to be completed.Promise<V>removeListener(FutureListener<? extends Future<? super V>> listener)Removes the first occurrence of the specified listener from this future.Promise<V>setFailure(Throwable cause)Marks this future as a failure and notifies all listeners.Promise<V>setSuccess(V result)Marks this future as a success and notifies all listeners.Promise<V>sync()Waits for this future until it is done, and rethrows the cause of the failure if this future failed.booleantryFailure(Throwable cause)Marks this future as a failure and notifies all listeners.booleantrySuccess(V result)Marks this future as a success and notifies all listeners.
-
-
-
Method Detail
-
setSuccess
Promise<V> setSuccess(V result)
Marks this future as a success and notifies all listeners.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:
trueif and only if successfully marked this future as a success. Otherwisefalsebecause this future is already marked as either a success or a failure.
-
setFailure
Promise<V> setFailure(Throwable cause)
Marks this future as a failure and notifies all listeners.If it is success or failed already it will throw an
IllegalStateException.
-
tryFailure
boolean tryFailure(Throwable cause)
Marks this future as a failure and notifies all listeners.- 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.
-
addListener
Promise<V> addListener(FutureListener<? extends Future<? super V>> listener)
Description copied from interface:FutureAdds 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:
addListenerin interfaceFuture<V>
-
removeListener
Promise<V> removeListener(FutureListener<? extends Future<? super V>> listener)
Description copied from interface:FutureRemoves 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:
removeListenerin interfaceFuture<V>
-
sync
Promise<V> sync() throws InterruptedException
Description copied from interface:FutureWaits for this future until it is done, and rethrows the cause of the failure if this future failed.- Specified by:
syncin interfaceFuture<V>- Throws:
InterruptedException
-
await
Promise<V> await() throws InterruptedException
Description copied from interface:FutureWaits for this future to be completed.- Specified by:
awaitin interfaceFuture<V>- Throws:
InterruptedException- if the current thread was interrupted
-
-