nl.uva.vlet.tasks
Class ActionTask

java.lang.Object
  extended by nl.uva.vlet.tasks.ActionTask
All Implemented Interfaces:
java.lang.Runnable

public abstract class ActionTask
extends java.lang.Object
implements java.lang.Runnable

Simple Task class which extends the Runnable class. This class creates it's own thread and monitors it. The main purpose is to manage all the 'Task' threads in the Multi Threaded Gui. Tasks (+their threads) are linked to a BrowserController which implements the ITaskSource interface. Update: This class is now part of nl.uva.vlet.Main to provide a single thread+task class for easier multithreaded programming.

TODO: better thread management. Now each task creates it's own thread.


Constructor Summary
ActionTask(ITaskSource source, java.lang.String taskName)
          Construct a new ActionTask origination from the taskSource source with the human readable name taskName
 
Method Summary
static void debugPrintTasks()
          print out the task list to the debugStream
static void disposeClass()
           
protected abstract  void doTask()
          Start task.
 java.lang.Exception getException()
          Returns stored exception
 float getProgress()
          Provide progress information.
 java.lang.Throwable getThrowable()
          Returns stored throwable
 VlException getVlException()
          Returns stored VlException only is the exception was of type VlException
 boolean hasException()
          Checks whether the thread has 'stored' an exception for later use
 boolean hasStarted()
           
static boolean hasTasksRunning(ITaskSource bc)
          Returns true if the ITaskSource has tasks running
 boolean hasVlException()
           
 void interrupt()
          Sends the running thread an interupt signal.
 boolean isAlive()
          Checks whether the worker thread is alive
 void join()
          use the Thread.join() method to join with the running task thread.
 void messagePrintln(java.lang.String str)
          Print a message in the ActionTasks message window
 void run()
          This method is called by thread.start() to start the runnable.
protected  void setException(java.lang.Throwable e)
          Store exception for later use
protected  void setTaskSource(ITaskSource newSource)
          Set TaskSource/Task Watcher to (new) watcher.
 void startTask()
          Starts this task.
static void stopActionsFor(ITaskSource source, boolean all)
          Send a stop signal to all tasks originating from the ITaskSource
abstract  void stopTask()
          Default stop method: PLEASE implement this if your ActionTask can be stopped! This is to improve pre-emptive multithreaded tasks !
 java.lang.String toString()
           
 void waitFor()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ActionTask

public ActionTask(ITaskSource source,
                  java.lang.String taskName)
Construct a new ActionTask origination from the taskSource source with the human readable name taskName

Method Detail

debugPrintTasks

public static final void debugPrintTasks()
print out the task list to the debugStream


hasTasksRunning

public static final boolean hasTasksRunning(ITaskSource bc)
Returns true if the ITaskSource has tasks running


stopActionsFor

public static void stopActionsFor(ITaskSource source,
                                  boolean all)
Send a stop signal to all tasks originating from the ITaskSource


startTask

public final void startTask()
Starts this task. Spawns a new thread an invokes the start method of the thread.


setTaskSource

protected final void setTaskSource(ITaskSource newSource)
Set TaskSource/Task Watcher to (new) watcher. This is done by the gui to tranfer responsibility to (for example) a backgrounded transfer watcher. This will make it appear the GUI isn't busy anymore, freeing the GUI, so the user can continue.

Parameters:
newWatcher -

run

public final void run()
This method is called by thread.start() to start the runnable. The ActionTask object will execute the 'doTask' method which is implemented by the subclass.

Specified by:
run in interface java.lang.Runnable

setException

protected void setException(java.lang.Throwable e)
Store exception for later use


messagePrintln

public final void messagePrintln(java.lang.String str)
Print a message in the ActionTasks message window


isAlive

public final boolean isAlive()
Checks whether the worker thread is alive


toString

public final java.lang.String toString()
Overrides:
toString in class java.lang.Object

interrupt

public final void interrupt()
Sends the running thread an interupt signal.

See Also:
Thread.interrupt()

join

public final void join()
                throws java.lang.InterruptedException
use the Thread.join() method to join with the running task thread.

Throws:
java.lang.InterruptedException

hasException

public final boolean hasException()
Checks whether the thread has 'stored' an exception for later use

See Also:
#setException(VlException), getException()

getException

public final java.lang.Exception getException()
Returns stored exception


getThrowable

public final java.lang.Throwable getThrowable()
Returns stored throwable


getVlException

public final VlException getVlException()
Returns stored VlException only is the exception was of type VlException


hasVlException

public final boolean hasVlException()

getProgress

public float getProgress()
Provide progress information.

Returns:
The progress between 0.0 and 1.0 or -1 (<0.0) if not supported.

doTask

protected abstract void doTask()
                        throws VlException
Start task. Method will be executed in own subthread! protected: may only be called by this superclass !

Throws:
VlException

stopTask

public abstract void stopTask()
Default stop method: PLEASE implement this if your ActionTask can be stopped! This is to improve pre-emptive multithreaded tasks !


disposeClass

public static void disposeClass()

hasStarted

public boolean hasStarted()

waitFor

public void waitFor()
             throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException