Task
Class AbstractTask

java.lang.Object
  extended by Task.AbstractTask
Direct Known Subclasses:
NetworkTask, SimpleTask

public abstract class AbstractTask
extends java.lang.Object

AbstractTask is a super class that encapsulates some common functionality between various types of tasks:

  1. SimpleTask
  2. NetworkTask
  3. RecurringNetworkTask

Since:
Jun 29, 2007, 1:10:10 PM
Version:
1.0
Author:
Nazmul Idris

Nested Class Summary
static class AbstractTask.PropertyNames
          enumeration that holds list of properties that you can attach property change listeners for, right now there's only one, but you can add more in the future.
static class AbstractTask.State
          List of all the possible states that any kind of Task (Network, non network, etc) may have.
static class AbstractTask.Type
          identifies the type of the task
 
Field Summary
protected  AutoShutdownSignals[] _autoShutdownRay
          this holds all the AutoShutdownSignals types that this task will respond to
protected  java.beans.PropertyChangeSupport _boundProperties
           
protected  java.util.concurrent.locks.Lock _boundPropertiesLock
           
protected  boolean _shutdownCalled
           
protected  AbstractTask.State _state
           
protected  java.lang.String _status
           
protected  TaskManager _taskManager
           
 
Constructor Summary
AbstractTask()
           
 
Method Summary
protected  void _assertIsNotShutdown()
          makes sure that shutdown() has not been called yet.
protected  void _assertNoSwingWorkerCurrentlyActive()
          makes sure that an existing SwingWorker is not already in flight. also if cleared for execution (SwingWorker creation).
 void addStatusListener(java.beans.PropertyChangeListener l)
          PropertyChangeEvent.getNewValue() contains the status message.
 void cancel()
          This method causes the cancel() method to be called on the underlying SwingWorker object (and thread).
 void clearAllStatusListeners()
           
abstract  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
abstract  void execute()
           
 java.lang.String formattedString()
           
 AutoShutdownSignals[] getAutoShutdownPolicy()
           
protected  java.beans.PropertyChangeSupport getBoundProperties()
           
 java.lang.String getDescription()
           
 java.lang.String getName()
           
 java.lang.Object getState()
           
 java.lang.String getStatus()
           
abstract  javax.swing.SwingWorker getSwingWorker()
           
protected  TaskManager getTaskManager()
           
abstract  AbstractTask.Type getType()
           
 SwingUIHookAdapter getUIHook()
           
 boolean hasAutoShutdownPolicy(AutoShutdownSignals policy)
          returns true if this task has an autostop policy that matches the param
 boolean isShutdown()
           
 void setAutoShutdownPolicy(AutoShutdownSignals... policy)
           
 void setDescription(java.lang.String descr)
           
 void setName(java.lang.String name)
           
 void setState(AbstractTask.State stateValue)
           
 void setStatus(java.lang.String s)
           
protected  void setTaskManager(TaskManager container)
           
 void shutdown()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_autoShutdownRay

protected AutoShutdownSignals[] _autoShutdownRay
this holds all the AutoShutdownSignals types that this task will respond to


_shutdownCalled

protected boolean _shutdownCalled

_taskManager

protected TaskManager _taskManager

_boundPropertiesLock

protected java.util.concurrent.locks.Lock _boundPropertiesLock

_boundProperties

protected java.beans.PropertyChangeSupport _boundProperties

_status

protected java.lang.String _status

_state

protected AbstractTask.State _state
Constructor Detail

AbstractTask

public AbstractTask()
Method Detail

getType

public abstract AbstractTask.Type getType()

getUIHook

public SwingUIHookAdapter getUIHook()

getAutoShutdownPolicy

public AutoShutdownSignals[] getAutoShutdownPolicy()

setAutoShutdownPolicy

public void setAutoShutdownPolicy(AutoShutdownSignals... policy)

isShutdown

public boolean isShutdown()

shutdown

public void shutdown()

hasAutoShutdownPolicy

public boolean hasAutoShutdownPolicy(AutoShutdownSignals policy)
                              throws java.lang.IllegalArgumentException
returns true if this task has an autostop policy that matches the param

Throws:
java.lang.IllegalArgumentException

doShutdown

public abstract 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


getTaskManager

protected TaskManager getTaskManager()

setTaskManager

protected void setTaskManager(TaskManager container)

getStatus

public java.lang.String getStatus()

getState

public java.lang.Object getState()

getBoundProperties

protected java.beans.PropertyChangeSupport getBoundProperties()

setStatus

public void setStatus(java.lang.String s)

setState

public void setState(AbstractTask.State stateValue)

addStatusListener

public void addStatusListener(java.beans.PropertyChangeListener l)
PropertyChangeEvent.getNewValue() contains the status message. Here's an example:
 public void propertyChange(PropertyChangeEvent evt) {
   _setStatus(evt.getNewValue().toString());
 }
 


clearAllStatusListeners

public void clearAllStatusListeners()

getSwingWorker

public abstract javax.swing.SwingWorker getSwingWorker()

execute

public abstract void execute()
                      throws TaskException
Throws:
TaskException

cancel

public void cancel()
This method causes the cancel() method to be called on the underlying SwingWorker object (and thread). The implementation of the TaskExecutorIF needs to check SwingWorker.isCancelled() in order for this to work. The InterruptedException will be thrown when this method is called, if need be.


_assertNoSwingWorkerCurrentlyActive

protected void _assertNoSwingWorkerCurrentlyActive()
                                            throws TaskException
makes sure that an existing SwingWorker is not already in flight. also if cleared for execution (SwingWorker creation).

the cancel flag is cleared on the SwingUIHookAdapter.resetCancelFlag(). if a task was cancelled previously, then that cancellation is not longer active, since the getUIHook() is about to be bound to a new execution environment (thread/swingworker).

Throws:
TaskException - TaskException.Type.ExecutionAttemptAfterTaskIsShutdown

_assertIsNotShutdown

protected void _assertIsNotShutdown()
                             throws TaskException
makes sure that shutdown() has not been called yet.

Throws:
TaskException - TaskException.Type.ExecutionAttemptAfterTaskIsShutdown

getName

public java.lang.String getName()

getDescription

public java.lang.String getDescription()

setName

public void setName(java.lang.String name)

setDescription

public void setDescription(java.lang.String descr)

formattedString

public java.lang.String formattedString()


Copyright © 2011. All Rights Reserved.