edu.rice.cs.util.swing
Class AsyncTask<ParamType,ResType>

java.lang.Object
  extended by edu.rice.cs.util.swing.AsyncTask<ParamType,ResType>

public abstract class AsyncTask<ParamType,ResType>
extends Object

The AsyncTask base class is a framework that facilitates execution of operations asynchronously in order to free up the event-handling thread. This task is passed to an implementation of the AsyncTaskLauncher to be run.

Any code that should be performed in asynchronously with the UI should be put in the runAsync method. Any code that is run in this method should NOT modify any Swing components at all. All modifications to Swing components must either be enqueued on the event-handling thread or performed in the complete method. If there is any data that must be passed from the asynchronous step to the completion step, it should be returned by the runAsync method. The same data returned by the runAsync method will be given to the complete method. In short, implementations of an AsyncTask need not manage the information passing between the task thread and the UI thread.

The runAsync method is given a progress monitor in order for the task to provide feedback to the user as to the progress of the task. The min and max values for the progress are specified by the getMinProgress and getMaxProgress methods in the task.

Author:
jlugo

Constructor Summary
AsyncTask()
          Default Constructor
AsyncTask(String name)
          Creates a task that has the given name
 
Method Summary
abstract  void complete(AsyncCompletionArgs<ResType> args)
          Performs te completion step where modifications to swing components are made.
abstract  String getDiscriptionMessage()
          Sets the description of the task that should be displayed in the progress monitor that the user sees.
 int getMaxProgress()
          Reutrns the minimum value of the progress monitor
 int getMinProgress()
          Returns the minimum value of the progress monitor
 String getName()
          Returns the name of this specific type of task.
abstract  ResType runAsync(ParamType param, IAsyncProgress monitor)
          This is the method of the task that is run on the separate thread.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AsyncTask

public AsyncTask()
Default Constructor


AsyncTask

public AsyncTask(String name)
Creates a task that has the given name

Parameters:
name - The name of the task.
Method Detail

runAsync

public abstract ResType runAsync(ParamType param,
                                 IAsyncProgress monitor)
                          throws Exception
This is the method of the task that is run on the separate thread. Any implementation of this method should not make any changes to GUI components unless those calls are made explicitly thread safe by the developer. Any code that modifies swing GUI components in any way should be located in the complete method.

Parameters:
param - Any parameter that should be passed to the task when it is executed
monitor - An object that controls the flow of information about task progress both to and from the runAsync method. This also offers a means of passing a result from the async step to the completion step.
Throws:
RuntimeException
Exception

complete

public abstract void complete(AsyncCompletionArgs<ResType> args)
Performs te completion step where modifications to swing components are made. This method runs in the event thread so changes made to swing components are safe.


getDiscriptionMessage

public abstract String getDiscriptionMessage()
Sets the description of the task that should be displayed in the progress monitor that the user sees. While the task is in progress, a separate note can be set in order to display specific information about the progress of the task. This can be set by calling ProgressMonitor.setNote

Returns:
A brief description of the task being performed

getName

public String getName()
Returns the name of this specific type of task. If this is not overridden

Returns:
the name of the task

getMinProgress

public int getMinProgress()
Returns the minimum value of the progress monitor

Returns:
The minimum value (0.0%) of the progress monitor

getMaxProgress

public int getMaxProgress()
Reutrns the minimum value of the progress monitor

Returns:
The minimum value (100.0%) of the progress monitor

toString

public String toString()
Overrides:
toString in class Object