edu.rice.cs.plt.concurrent
Class PollingTaskController<R>

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

public abstract class PollingTaskController<R>
extends TaskController<R>

A TaskController for tasks that are run without any facility for executing code when the task is complete — instead, the controller must either block, poll for the task's current status. When most of the controller's methods are invoked, the current status is polled before proceeding; operations depending on completion block (finishListeners() are handled by blocking in a new daemon thread).

To implement a concrete instance, a subclass must provide TaskController.doStart(), TaskController.doStop(), update(), finish(), and, optionally, TaskController.discard().


Nested Class Summary
protected  class PollingTaskController.PollingCancelingState
          CancelingState variant based on a PollingRunner.
protected  class PollingTaskController.PollingRunningState
          RunningState variant based on a PollingRunner.
 
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
protected PollingTaskController()
           
 
Method Summary
protected abstract  void finish()
          Block until the task is complete or this thread is interrupted.
protected abstract  void finish(long timeout, TimeUnit unit)
          Block until the task is complete, this thread is interrupted, or the given timeout is reached.
 ListenerSet.Sink finishListeners()
          Access the ListenerSet responding to the completion of computation.
protected  TaskController.RunningState runningState()
          Produce a running state.
protected abstract  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.TaskController
attemptGet, attemptGet, cancel, cancel, discard, doStart, doStop, 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

PollingTaskController

protected PollingTaskController()
Method Detail

finishListeners

public ListenerSet.Sink finishListeners()
Access the ListenerSet responding to the completion of computation. The first time this method is invoked, a daemon thread is started that will wait for computation to complete (otherwise, any registered listeners will not run until the task is manually polled).

Overrides:
finishListeners in class TaskController<R>

update

protected abstract void update()
Check the current status and call the appropriate method if the task is complete. This method is invoked frequently and should not block.


finish

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

Throws:
InterruptedException

finish

protected abstract void finish(long timeout,
                               TimeUnit unit)
                        throws InterruptedException,
                               TimeoutException
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.

Throws:
InterruptedException
TimeoutException

runningState

protected TaskController.RunningState runningState()
Description copied from class: TaskController
Produce a running state. May be overridden to change the way RunningStates are implemented.

Overrides:
runningState in class TaskController<R>