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

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

java.lang.Object
  extended by java.util.concurrent.FutureTask<E>
      extended by com.barchart.util.concurrent.FutureCallbackTask<E>
Type Parameters:
E - The result type
All Implemented Interfaces:
FutureCallback<E,FutureCallbackTask<E>>, Runnable, Future<E>, RunnableFuture<E>

public class FutureCallbackTask<E>
extends FutureTask<E>
implements FutureCallback<E,FutureCallbackTask<E>>

Basic implementation of FutureCallback based on FutureTask.

Author:
jeremy
See Also:
FutureTask, FutureCallback

Constructor Summary
FutureCallbackTask(Callable<E> c)
          Create a future result handler.
FutureCallbackTask(Runnable r, E value)
          Create a future result handler.
 
Method Summary
 FutureCallbackTask<E> addResultListener(FutureListener<E> listener)
          Register a listener for this deferred result.
protected  void done()
          Notify listeners that a result is available.
 FutureCallbackTask<E> fail(Throwable error_)
          Notify listeners that an error occurred.
 void finalize()
          Log an error if this FutureCallbackTask is garbage collected before it has been called.
 E getUnchecked()
          Get the return value, or null if a checked exception was caught.
 FutureCallbackTask<E> succeed(E result_)
          Notify listeners that a result is available.
 
Methods inherited from class java.util.concurrent.FutureTask
cancel, get, get, isCancelled, isDone, run, runAndReset, set, setException
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.Future
cancel, get, get, isCancelled, isDone
 

Constructor Detail

FutureCallbackTask

public FutureCallbackTask(Runnable r,
                          E value)
Create a future result handler.


FutureCallbackTask

public FutureCallbackTask(Callable<E> c)
Create a future result handler.

Method Detail

addResultListener

public FutureCallbackTask<E> addResultListener(FutureListener<E> listener)
Description copied from interface: FutureCallback
Register a listener for this deferred result. If the result is already available, the listener may be called synchronously, so you should generally avoid any blocking code in the callback.

Specified by:
addResultListener in interface FutureCallback<E,FutureCallbackTask<E>>
Parameters:
listener - The listener object

succeed

public FutureCallbackTask<E> succeed(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<E,FutureCallbackTask<E>>
Returns:
This FutureCallbackTask object (for chaining calls)

fail

public FutureCallbackTask<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<E,FutureCallbackTask<E>>

getUnchecked

public 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<E,FutureCallbackTask<E>>

done

protected void done()
Notify listeners that a result is available.

Overrides:
done in class FutureTask<E>

finalize

public void finalize()
              throws Throwable
Log an error if this FutureCallbackTask is garbage collected before it has been called.

Overrides:
finalize in class Object
Throws:
Throwable

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

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