Package cn.sliew.milky.concurrent
Class DefaultProgressivePromise<V>
- java.lang.Object
-
- cn.sliew.milky.concurrent.AbstractFuture<V>
-
- cn.sliew.milky.concurrent.DefaultPromise<V>
-
- cn.sliew.milky.concurrent.DefaultProgressivePromise<V>
-
- All Implemented Interfaces:
Future<V>,ProgressiveFuture<V>,ProgressivePromise<V>,Promise<V>,Future
public class DefaultProgressivePromise<V> extends DefaultPromise<V> implements ProgressivePromise<V>
-
-
Field Summary
-
Fields inherited from class cn.sliew.milky.concurrent.DefaultPromise
listeners
-
-
Constructor Summary
Constructors Constructor Description DefaultProgressivePromise()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ProgressivePromise<V>addListener(FutureListener<? extends Future<? super V>> listener)Adds the specified listener to this future.ProgressivePromise<V>await()Waits for this future to be completed.ProgressivePromise<V>removeListener(FutureListener<? extends Future<? super V>> listener)Removes the first occurrence of the specified listener from this future.ProgressivePromise<V>setFailure(Throwable cause)Marks this future as a failure and notifies all listeners.ProgressivePromise<V>setProgress(long progress, long total)Sets the current progress of the operation and notifies the listeners that implementProgressiveFutureListener.ProgressivePromise<V>setSuccess(V result)Marks this future as a success and notifies all listeners.ProgressivePromise<V>sync()Waits for this future until it is done, and rethrows the cause of the failure if this future failed.booleantryProgress(long progress, long total)Tries to set the current progress of the operation and notifies the listeners that implementProgressiveFutureListener.-
Methods inherited from class cn.sliew.milky.concurrent.DefaultPromise
await, cancel, cause, getNow, isCancelled, isDone, isSuccess, tryFailure, trySuccess
-
Methods inherited from class cn.sliew.milky.concurrent.AbstractFuture
get, get
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface cn.sliew.milky.concurrent.Promise
tryFailure, trySuccess
-
-
-
-
Method Detail
-
setProgress
public ProgressivePromise<V> setProgress(long progress, long total)
Description copied from interface:ProgressivePromiseSets the current progress of the operation and notifies the listeners that implementProgressiveFutureListener.- Specified by:
setProgressin interfaceProgressivePromise<V>
-
tryProgress
public boolean tryProgress(long progress, long total)Description copied from interface:ProgressivePromiseTries to set the current progress of the operation and notifies the listeners that implementProgressiveFutureListener. If the operation is already complete or the progress is out of range, this method does nothing but returningfalse.- Specified by:
tryProgressin interfaceProgressivePromise<V>
-
setSuccess
public ProgressivePromise<V> setSuccess(V result)
Description copied from interface:PromiseMarks this future as a success and notifies all listeners.If it is success or failed already it will throw an
IllegalStateException.- Specified by:
setSuccessin interfaceProgressivePromise<V>- Specified by:
setSuccessin interfacePromise<V>- Overrides:
setSuccessin classDefaultPromise<V>
-
setFailure
public ProgressivePromise<V> setFailure(Throwable cause)
Description copied from interface:PromiseMarks this future as a failure and notifies all listeners.If it is success or failed already it will throw an
IllegalStateException.- Specified by:
setFailurein interfaceProgressivePromise<V>- Specified by:
setFailurein interfacePromise<V>- Overrides:
setFailurein classDefaultPromise<V>
-
addListener
public ProgressivePromise<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>- Specified by:
addListenerin interfaceProgressiveFuture<V>- Specified by:
addListenerin interfaceProgressivePromise<V>- Specified by:
addListenerin interfacePromise<V>- Overrides:
addListenerin classDefaultPromise<V>
-
removeListener
public ProgressivePromise<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>- Specified by:
removeListenerin interfaceProgressiveFuture<V>- Specified by:
removeListenerin interfaceProgressivePromise<V>- Specified by:
removeListenerin interfacePromise<V>- Overrides:
removeListenerin classDefaultPromise<V>
-
sync
public ProgressivePromise<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>- Specified by:
syncin interfaceProgressiveFuture<V>- Specified by:
syncin interfaceProgressivePromise<V>- Specified by:
syncin interfacePromise<V>- Overrides:
syncin classDefaultPromise<V>- Throws:
InterruptedException
-
await
public ProgressivePromise<V> await() throws InterruptedException
Description copied from interface:FutureWaits for this future to be completed.- Specified by:
awaitin interfaceFuture<V>- Specified by:
awaitin interfaceProgressiveFuture<V>- Specified by:
awaitin interfaceProgressivePromise<V>- Specified by:
awaitin interfacePromise<V>- Overrides:
awaitin classDefaultPromise<V>- Throws:
InterruptedException- if the current thread was interrupted
-
-