edu.rice.cs.plt.concurrent
Class FutureTaskController<T>

java.lang.Object
  extended by edu.rice.cs.plt.concurrent.TaskController<R>
      extended by edu.rice.cs.plt.concurrent.PollingTaskController<T>
          extended by edu.rice.cs.plt.concurrent.FutureTaskController<T>
All Implemented Interfaces:
ResolvingThunk<T>, Thunk<T>, Future<T>

public class FutureTaskController<T>
extends PollingTaskController<T>

Treats an arbitrary Future-producing computation as a TaskController. The task is considered "started" once the future has been created via TaskController.start() (even though some futures are not scheduled for immediate execution — the API provides no means for determining whether a task is actually running).


Nested Class Summary
 
Nested classes/interfaces inherited from class edu.rice.cs.plt.concurrent.PollingTaskController
PollingTaskController.PollingCancelingState, PollingTaskController.PollingRunningState
 
Nested classes/interfaces inherited from class edu.rice.cs.plt.concurrent.TaskController
TaskController.CanceledStartingState, TaskController.CanceledState, TaskController.CancelingState, TaskController.CleanlyFinishedState, TaskController.ComputingState, TaskController.ExecutionExceptionState, TaskController.FinishedState, TaskController.FreshStartingState, TaskController.FreshState, TaskController.InternalExceptionState, TaskController.RunningState, TaskController.StartingState, TaskController.State, TaskController.Status, TaskController.WaitingState
 
Field Summary
 
Fields inherited from class edu.rice.cs.plt.concurrent.TaskController
state
 
Constructor Summary
FutureTaskController(Thunk<? extends Future<? extends T>> futureThunk)
           
 
Method Summary
protected  void discard()
          Clean up after the task has completed.
protected  void doStart()
          Begin computation and call TaskController.started().
protected  void doStop()
          Terminate computation and call TaskController.stopped().
protected  void finish()
          Block until the task is complete or this thread is interrupted.
protected  void finish(long timeout, TimeUnit unit)
          Block until the task is complete, this thread is interrupted, or the given timeout is reached.
protected  void update()
          Check the current status and call the appropriate method if the task is complete.
 
Methods inherited from class edu.rice.cs.plt.concurrent.PollingTaskController
finishListeners, runningState
 
Methods inherited from class edu.rice.cs.plt.concurrent.TaskController
attemptGet, attemptGet, cancel, cancel, finishedCleanly, finishedWithImplementationException, finishedWithTaskException, get, get, get, hasValue, isCanceled, isCancelled, isDone, isResolved, start, started, status, stopped, value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FutureTaskController

public FutureTaskController(Thunk<? extends Future<? extends T>> futureThunk)
Method Detail

doStart

protected void doStart()
Description copied from class: TaskController
Begin computation and call TaskController.started(). If starting does not occur immediately (for example, blocking occurs first), the started() call may occur in a different thread.

Specified by:
doStart in class TaskController<T>

doStop

protected void doStop()
Description copied from class: TaskController
Terminate computation and call TaskController.stopped(). Never called before started() has been invoked. If termination does not occur immediately (for example, blocking occurs first), the stopped() call may occur in a different thread.

Specified by:
doStop in class TaskController<T>

discard

protected void discard()
Description copied from class: TaskController
Clean up after the task has completed. Called whenever the task enters a canceled or finished state (for example, when finishedCleanly() has been called, or when cancel() is invoked on a PAUSED controller). By default, does nothing, but can be overridden to close connections or throw away unnecessary objects. (Where TaskControllers live far beyond their computation life span (as simple wrappers for a value), this allows objects related to the computation to be garbage-collected in the interim.)

Overrides:
discard in class TaskController<T>

update

protected void update()
Description copied from class: PollingTaskController
Check the current status and call the appropriate method if the task is complete. This method is invoked frequently and should not block.

Specified by:
update in class PollingTaskController<T>

finish

protected void finish()
               throws InterruptedException
Description copied from class: PollingTaskController
Block until the task is complete or this thread is interrupted. Must not return until after one of the completion methods are called.

Specified by:
finish in class PollingTaskController<T>
Throws:
InterruptedException

finish

protected void finish(long timeout,
                      TimeUnit unit)
               throws InterruptedException,
                      TimeoutException
Description copied from class: PollingTaskController
Block until the task is complete, this thread is interrupted, or the given timeout is reached. Must not return until after one of the completion methods are called.

Specified by:
finish in class PollingTaskController<T>
Throws:
InterruptedException
TimeoutException