Task
Class SimpleTask<ReturnValueType>

java.lang.Object
  extended by Task.AbstractTask
      extended by Task.SimpleTask<ReturnValueType>

public class SimpleTask<ReturnValueType>
extends AbstractTask

Task is a SwingWorker that's optimzed for calling services in the platform and handling mundane error processing, etc.

When using this class, you can bind your UI to the following properties:

PropertyNames.Status
A string message will be sent as status changes happen
PropertyNames.State
A State change will be issued when the background thread is started/stopped. Also, upon completion of the task, a OK or Err property will be fired. In the OK property, change event, the first parameter (old value) is the return value from the TaskExecutorIF, and the 2nd parameter (new value) is the State enum.
Similarly, for the Err property, the first value is the Throwable, and the 2nd is the State enum.
Registering tasks with container
When an instance of this class is created, it's registered with the container, using the container's ContainerTaskManager object. This provides the container with the monitor running/dead tasks.

Since:
May 30, 2007, 1:33:23 PM
Version:
1.0
Author:
Nazmul Idris

Nested Class Summary
 
Nested classes/interfaces inherited from class Task.AbstractTask
AbstractTask.PropertyNames, AbstractTask.State, AbstractTask.Type
 
Field Summary
protected  TaskExecutorIF<ReturnValueType> _exec
           
protected  javax.swing.SwingWorker<ReturnValueType,java.lang.Void> _swingWorker
           
 
Fields inherited from class Task.AbstractTask
_autoShutdownRay, _boundProperties, _boundPropertiesLock, _shutdownCalled, _state, _status, _taskManager
 
Constructor Summary
SimpleTask(TaskManager taskManager, TaskExecutorIF<ReturnValueType> exec, java.lang.String name, java.lang.String descr, AutoShutdownSignals... autoShutdownPolicy)
          use this constructor if you want the tasks to show up in the DesktopAppContainerIF
 
Method Summary
protected  void _createSwingWorker()
          instantiates the underlying swing worker implementation...
 void doShutdown()
          subclass should implement this method as is appropriate for them. this is called when the task is stopped, based on the AutoShutdownSignals policy
 void execute()
          For each invocation, this method creates a new SwingWorker object to perform a background task, and then it uses the provided TasKHandler to notify you of the changes to the task's lifecycle.
 javax.swing.SwingWorker<ReturnValueType,java.lang.Void> getSwingWorker()
           
 AbstractTask.Type getType()
           
 void setTaskHandler(SimpleTaskHandlerIF<ReturnValueType> handler)
           
 
Methods inherited from class Task.AbstractTask
_assertIsNotShutdown, _assertNoSwingWorkerCurrentlyActive, addStatusListener, cancel, clearAllStatusListeners, formattedString, getAutoShutdownPolicy, getBoundProperties, getDescription, getName, getState, getStatus, getTaskManager, getUIHook, hasAutoShutdownPolicy, isShutdown, setAutoShutdownPolicy, setDescription, setName, setState, setStatus, setTaskManager, shutdown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_exec

protected TaskExecutorIF<ReturnValueType> _exec

_swingWorker

protected javax.swing.SwingWorker<ReturnValueType,java.lang.Void> _swingWorker
Constructor Detail

SimpleTask

public SimpleTask(TaskManager taskManager,
                  TaskExecutorIF<ReturnValueType> exec,
                  java.lang.String name,
                  java.lang.String descr,
                  AutoShutdownSignals... autoShutdownPolicy)
           throws java.lang.IllegalArgumentException
use this constructor if you want the tasks to show up in the DesktopAppContainerIF

Throws:
java.lang.IllegalArgumentException
Method Detail

getType

public AbstractTask.Type getType()
Specified by:
getType in class AbstractTask

doShutdown

public void doShutdown()
subclass should implement this method as is appropriate for them. this is called when the task is stopped, based on the AutoShutdownSignals policy

Specified by:
doShutdown in class AbstractTask

setTaskHandler

public void setTaskHandler(SimpleTaskHandlerIF<ReturnValueType> handler)
                    throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

getSwingWorker

public javax.swing.SwingWorker<ReturnValueType,java.lang.Void> getSwingWorker()
Specified by:
getSwingWorker in class AbstractTask

execute

public void execute()
             throws TaskException
For each invocation, this method creates a new SwingWorker object to perform a background task, and then it uses the provided TasKHandler to notify you of the changes to the task's lifecycle.

Specified by:
execute in class AbstractTask
Throws:
TaskException

_createSwingWorker

protected void _createSwingWorker()
instantiates the underlying swing worker implementation...



Copyright © 2011. All Rights Reserved.