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(java.util.concurrent.ExecutorService executor)
Creates a new
AbstractListenableFuture . |
Modifier and Type | Method and Description |
---|---|
protected java.util.concurrent.Future<T> |
addToListeners(GenericCompletionListener<? extends java.util.concurrent.Future<T>> listener)
Add the given listener to the total list of listeners to be notified.
|
protected java.util.concurrent.ExecutorService |
executor()
Returns the current executor.
|
protected void |
notifyListener(java.util.concurrent.ExecutorService executor,
java.util.concurrent.Future<?> future,
GenericCompletionListener listener)
Notify a specific listener of completion.
|
protected void |
notifyListeners()
Notify all registered listeners of future completion.
|
protected void |
notifyListeners(java.util.concurrent.Future<?> future)
Notify all registered listeners with a special future on completion.
|
protected java.util.concurrent.Future<T> |
removeFromListeners(GenericCompletionListener<? extends java.util.concurrent.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(java.util.concurrent.ExecutorService executor)
AbstractListenableFuture
.executor
- the executor in which the callbacks will be executed in.protected java.util.concurrent.ExecutorService executor()
protected java.util.concurrent.Future<T> addToListeners(GenericCompletionListener<? extends java.util.concurrent.Future<T>> listener)
If the future is already done, the listener will be notified immediately.
listener
- the listener to add.protected void notifyListener(java.util.concurrent.ExecutorService executor, java.util.concurrent.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(java.util.concurrent.Future<?> future)
future
- the future to pass on to the listeners.protected java.util.concurrent.Future<T> removeFromListeners(GenericCompletionListener<? extends java.util.concurrent.Future<T>> listener)
listener
- the listener to remove.Copyright © 2006-2009 Dustin Sallings, 2009-2013 Couchbase, Inc.