barchart-util-concurrent
2.0.16 / 2012-12-19T12:07:36.441-0600

com.barchart.util.concurrent
Class FutureCallbackList<E>

java.lang.Object
  extended by com.barchart.util.concurrent.FutureCallbackList<E>
Type Parameters:
E - The deferred result type
All Implemented Interfaces:
FutureCallback<List<E>,FutureCallbackList<E>>, Future<List<E>>

public class FutureCallbackList<E>
extends Object
implements FutureCallback<List<E>,FutureCallbackList<E>>

Groups a number of FutureCallbackTask results together, and executes a single callback only after all FutureCallbacks have completed (succeeded or failed.) This class does not support direct access to succeed() or fail(), and will throw and UnsupportedOperationException for them.

Author:
jeremy
See Also:
FutureCallbackTask

Constructor Summary
FutureCallbackList(List<? extends FutureCallback<E,?>> results_)
          Create a FutureCallbackList from the specified FutureCallback objects.
 
Method Summary
 FutureCallbackList<E> addResultListener(FutureListener<List<E>> callback)
          Add a callback listener that will be called when all FutureCallbacks have completed.
 boolean cancel(boolean interrupt)
           
 FutureCallbackList<E> fail(Throwable error)
          Notify listeners that an error occurred.
 List<E> get()
           
 List<E> get(long timeout, TimeUnit unit)
           
 List<E> getUnchecked()
          Get the return value, or null if a checked exception was caught.
 boolean isCancelled()
           
 boolean isDone()
           
 FutureCallbackList<E> succeed(List<E> result)
          Notify listeners that a result is available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FutureCallbackList

public FutureCallbackList(List<? extends FutureCallback<E,?>> results_)
Create a FutureCallbackList from the specified FutureCallback objects.

Parameters:
deferreds_ - The list of deferred results to monitor
Method Detail

addResultListener

public FutureCallbackList<E> addResultListener(FutureListener<List<E>> callback)
Add a callback listener that will be called when all FutureCallbacks have completed. The callback will be passed a list of results collected from the FutureCallbacks. A null member may indicate that a FutureCallback failed, but does not guarantee it (since a FutureCallback callback could return a null value on purpose.)

Specified by:
addResultListener in interface FutureCallback<List<E>,FutureCallbackList<E>>
Parameters:
callback - The object to notify of the deferred results

cancel

public boolean cancel(boolean interrupt)
Specified by:
cancel in interface Future<List<E>>

get

public List<E> get()
Specified by:
get in interface Future<List<E>>

getUnchecked

public List<E> getUnchecked()
Description copied from interface: FutureCallback
Get the return value, or null if a checked exception was caught.

Specified by:
getUnchecked in interface FutureCallback<List<E>,FutureCallbackList<E>>

get

public List<E> get(long timeout,
                   TimeUnit unit)
            throws InterruptedException,
                   TimeoutException
Specified by:
get in interface Future<List<E>>
Throws:
InterruptedException
TimeoutException

isCancelled

public boolean isCancelled()
Specified by:
isCancelled in interface Future<List<E>>

isDone

public boolean isDone()
Specified by:
isDone in interface Future<List<E>>

succeed

public FutureCallbackList<E> succeed(List<E> result)
Description copied from interface: FutureCallback
Notify listeners that a result is available. Returns the current FutureCallbackTask instance to allow simple synchronous returns when the result is already available:
return new FutureCallbackTask().succeed(result);

Specified by:
succeed in interface FutureCallback<List<E>,FutureCallbackList<E>>
Returns:
This FutureCallbackTask object (for chaining calls)

fail

public FutureCallbackList<E> fail(Throwable error)
Description copied from interface: FutureCallback
Notify listeners that an error occurred. Returns the current FutureCallbackTask instance to allow simple synchronous returns when an error has already occurred:
return new FutureCallbackTask().fail(exception);

Specified by:
fail in interface FutureCallback<List<E>,FutureCallbackList<E>>

barchart-util-concurrent
2.0.16 / 2012-12-19T12:07:36.441-0600

Copyright © 2011-2012 Barchart, Inc.. All Rights Reserved.