com.ning.http.client.listenable
Class AbstractListenableFuture<V>

java.lang.Object
  extended by com.ning.http.client.listenable.AbstractListenableFuture<V>
All Implemented Interfaces:
ListenableFuture<V>, Future<V>
Direct Known Subclasses:
ApacheResponseFuture, JDKFuture, NettyResponseFuture

public abstract class AbstractListenableFuture<V>
extends Object
implements ListenableFuture<V>

An abstract base implementation of the listener support provided by ListenableFuture. This class uses an ExecutionList to guarantee that all registered listeners will be executed. Listener/Executor pairs are stored in the execution list and executed in the order in which they were added, but because of thread scheduling issues there is no guarantee that the JVM will execute them in order. In addition, listeners added after the task is complete will be executed immediately, even if some previously added listeners have not yet been executed.

Since:
1
Author:
Sven Mawson

Constructor Summary
AbstractListenableFuture()
           
 
Method Summary
 ListenableFuture<V> addListener(Runnable listener, Executor exec)
          Adds a listener and executor to the ListenableFuture.
protected  void done()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.ning.http.client.ListenableFuture
abort, content, done, getAndSetWriteBody, getAndSetWriteHeaders, touch
 
Methods inherited from interface java.util.concurrent.Future
cancel, get, get, isCancelled, isDone
 

Constructor Detail

AbstractListenableFuture

public AbstractListenableFuture()
Method Detail

addListener

public ListenableFuture<V> addListener(Runnable listener,
                                       Executor exec)
Description copied from interface: ListenableFuture

Adds a listener and executor to the ListenableFuture. The listener will be passed to the executor for execution when the Future's computation is complete.

There is no guaranteed ordering of execution of listeners, they may get called in the order they were added and they may get called out of order, but any listener added through this method is guaranteed to be called once the computation is complete.

Specified by:
addListener in interface ListenableFuture<V>
Parameters:
listener - the listener to run when the computation is complete.
exec - the executor to run the listener in.
Returns:
this Future

done

protected void done()


Copyright © 2011. All Rights Reserved.