|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.plt.concurrent.TaskController<R>
edu.rice.cs.plt.concurrent.IncrementalTaskController<I,R>
edu.rice.cs.plt.swing.SwingWorker<R,I>
public abstract class SwingWorker<R,I>
A utility class providing the core functionality of javax.swing.SwingWorker (first available
in Java 6), in addition to supporting the IncrementalTaskController interface. Allows a task to be
separated into two parts: a working portion that calculates a value (or sequence of intermediate values)
in the background, and a GUI portion that executes in the Swing event thread when the working portion is
complete. Implementations should define doInBackground() and, optionally, process(java.util.List)
and done(). The doInBackground() implementation may call publish(I...)
and authorizeContinue(); other protected methods should generally be ignored as implementation
details.
Implementations should be able to migrate seamlessly to the Java 6 API version by simply changing
the parent class, as long as they stick to methods that are defined in both classes. This version doesn't
support PropertyChangeListeners, a progress property, the Runnable interface, a getState() method
(although status() provides similar information), or an isCancelled() method that can be
polled by doInBackground() (isCancelled() is defined, but its result is never
true before doInBackground() returns; implementations should instead handle cancellation
by checking for an interrupt). There is also (currently) no thread pooling —
each worker runs in a new thread. This version adds the methods provided by
IncrementalTaskController, as well as authorizeContinue(), which supports the implementation
of IncrementalTaskController.pause().
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class edu.rice.cs.plt.concurrent.IncrementalTaskController |
|---|
IncrementalTaskController.CanceledPausingState, IncrementalTaskController.FreshPausingState, IncrementalTaskController.PausedStartingState, IncrementalTaskController.PausedState, IncrementalTaskController.PausingState, IncrementalTaskController.StartedPausingState |
| Field Summary |
|---|
| Fields inherited from class edu.rice.cs.plt.concurrent.TaskController |
|---|
state |
| Constructor Summary | |
|---|---|
SwingWorker()
|
|
| Method Summary | |
|---|---|
protected void |
authorizeContinue()
Called by doInBackground() to ensure that the task has not been paused or canceled. |
protected abstract R |
doInBackground()
Work to be performed in a worker thread. |
protected void |
done()
Action to be performed in the event thread when work has completed. |
protected void |
doPause()
Pause computation and call IncrementalTaskController.paused(). |
protected void |
doResume()
Resume computation (after a pause) and call TaskController.started(). |
protected void |
doStart()
Begin computation and call TaskController.started(). |
protected void |
doStop()
Terminate computation and call TaskController.stopped(). |
void |
execute()
|
protected void |
process(List<I> chunks)
Action to be performed in the event thread when intermediate results are available. |
protected void |
publish(I... chunks)
Called by doInBackground() when intermediate results are available. |
| Methods inherited from class edu.rice.cs.plt.concurrent.IncrementalTaskController |
|---|
intermediateListeners, intermediateQueue, pause, paused, stepped, steps |
| Methods inherited from class edu.rice.cs.plt.concurrent.TaskController |
|---|
attemptGet, attemptGet, cancel, cancel, discard, finishedCleanly, finishedWithImplementationException, finishedWithTaskException, finishListeners, get, get, get, hasValue, isCanceled, isCancelled, isDone, isResolved, runningState, 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 |
|---|
public SwingWorker()
| Method Detail |
|---|
public final void execute()
protected abstract R doInBackground()
throws Exception
Exceptionprotected void process(List<I> chunks)
protected void done()
protected final void publish(I... chunks)
doInBackground() when intermediate results are available.
protected void authorizeContinue()
throws InterruptedException
Called by doInBackground() to ensure that the task has not been paused or canceled.
If paused, this method blocks until the task is restarted. If canceled, throws an
InterruptedException.
Tasks that wish to maintain migration compatibility with javax.swing.SwingWorker cannot
call this method or support pausing. Instead, they should simply respond to an interrupt when canceled
(checking, for example, via Thread.interrupted()).
InterruptedExceptionprotected final void doStart()
TaskControllerTaskController.started(). If starting does not occur immediately (for example,
blocking occurs first), the started() call may occur in a different thread.
doStart in class TaskController<R>protected final void doPause()
IncrementalTaskControllerIncrementalTaskController.paused(). If pausing does not occur immediately, the paused()
call may occur in a different thread. Will only be called after started() has been invoked.
When execution should resume again, doStart() will be invoked (but only after paused()
has been called). In order to support responsive canceling, a call to doStop() may occur
concurrently, or before paused() is called.
doPause in class IncrementalTaskController<I,R>protected final void doResume()
IncrementalTaskControllerTaskController.started(). If starting does not occur immediately
(for example, blocking occurs first), the started() call may occur in a different thread.
doResume in class IncrementalTaskController<I,R>protected final void doStop()
TaskControllerTaskController.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.
doStop in class TaskController<R>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||