public abstract class AbstractListenableFuture<T,L extends GenericCompletionListener> extends SpyObject implements ListenableFuture<T,L>
AbstractListenableFuture
implements common functionality shared
by all futures that implement the ListenableFuture
.
It handles storage and notification of listeners and making sure this is
done in a thread-safe manner. The subclassing methods need to implement
the abstract methods, which in turn need to call both
addToListeners(GenericCompletionListener)
and
removeFromListeners(GenericCompletionListener)
. See the
OperationFuture
as an example.Modifier | Constructor and Description |
---|---|
protected |
AbstractListenableFuture(ExecutorService executor)
Creates a new
AbstractListenableFuture . |
Modifier and Type | Method and Description |
---|---|
protected Future<T> |
addToListeners(GenericCompletionListener<? extends Future<T>> listener)
Add the given listener to the total list of listeners to be notified.
|
protected ExecutorService |
executor()
Returns the current executor.
|
protected void |
notifyListener(ExecutorService executor,
Future<?> future,
GenericCompletionListener listener)
Notify a specific listener of completion.
|
protected void |
notifyListeners()
Notify all registered listeners of future completion.
|
protected void |
notifyListeners(Future<?> future)
Notify all registered listeners with a special future on completion.
|
protected Future<T> |
removeFromListeners(GenericCompletionListener<? extends Future<T>> listener)
Remove a listener from the list of registered listeners.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addListener, removeListener
protected AbstractListenableFuture(ExecutorService executor)
AbstractListenableFuture
.executor
- the executor in which the callbacks will be executed in.protected ExecutorService executor()
protected Future<T> addToListeners(GenericCompletionListener<? extends Future<T>> listener)
If the future is already done, the listener will be notified immediately.
listener
- the listener to add.protected void notifyListener(ExecutorService executor, Future<?> future, GenericCompletionListener listener)
executor
- the executor to use.future
- the future to hand over.listener
- the listener to notify.protected void notifyListeners()
protected void notifyListeners(Future<?> future)
future
- the future to pass on to the listeners.protected Future<T> removeFromListeners(GenericCompletionListener<? extends Future<T>> listener)
listener
- the listener to remove.Copyright © 2023. All rights reserved.