Task
Class SimpleTaskHandler<ReturnValueType>

java.lang.Object
  extended by Task.SimpleTaskHandler<ReturnValueType>
All Implemented Interfaces:
SimpleTaskHandlerIF<ReturnValueType>
Direct Known Subclasses:
NetworkTaskHandler

public class SimpleTaskHandler<ReturnValueType>
extends java.lang.Object
implements SimpleTaskHandlerIF<ReturnValueType>

TaskHandler is a convenience class that you can extend in order to override only the methods that you want to override for your task handler.

Since:
Oct 5, 2007, 10:12:06 AM
Version:
1.0
Author:
Nazmul Idris
See Also:
more information on the TaskHandlerIF

Constructor Summary
SimpleTaskHandler()
           
 
Method Summary
 void beforeStart(AbstractTask task)
          this method is called before the background thread is started. good place to do prep work if any needs to be done.
 void cancelled(long time, AbstractTask task)
          This is called after started(). it signifies that the task was cancelled by cancel() being called on it's SwingWorker thread.
 void error(java.lang.Throwable e, long time, AbstractTask task)
          this is called after stopped(). it signifies failure of task execution.
 void interrupted(java.lang.Throwable e, AbstractTask task)
          this is called after the task has been interrupted. ok or error may not be called after this.
 void ok(ReturnValueType value, long time, AbstractTask task)
          this is called after stopped(). it signifies successful task completion.
 void shutdownCalled(AbstractTask task)
          This method is called on the task handler when AbstractTask.shutdown() is called.
 void started(AbstractTask task)
          this is called after the task is started, it's not running in the background at this point, but is just about to. all the states have been setup (in the task) and updates sent out.
 void stopped(long time, AbstractTask task)
          this is called after the task has ended normally (not interrupted). ok or error may be called after this.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleTaskHandler

public SimpleTaskHandler()
Method Detail

beforeStart

public void beforeStart(AbstractTask task)
this method is called before the background thread is started. good place to do prep work if any needs to be done. this may not run in the EDT.

Specified by:
beforeStart in interface SimpleTaskHandlerIF<ReturnValueType>
Parameters:
task -

started

public void started(AbstractTask task)
this is called after the task is started, it's not running in the background at this point, but is just about to. all the states have been setup (in the task) and updates sent out. this may not run in the EDT.

Specified by:
started in interface SimpleTaskHandlerIF<ReturnValueType>
Parameters:
task -

stopped

public void stopped(long time,
                    AbstractTask task)
this is called after the task has ended normally (not interrupted). ok or error may be called after this. this runs in the EDT.

Specified by:
stopped in interface SimpleTaskHandlerIF<ReturnValueType>

interrupted

public void interrupted(java.lang.Throwable e,
                        AbstractTask task)
this is called after the task has been interrupted. ok or error may not be called after this. this is caused by underlying IOException, InterruptedIOException, or InterruptedException. this runs in the EDT.

Specified by:
interrupted in interface SimpleTaskHandlerIF<ReturnValueType>
Parameters:
e - this holds the underlying exception that holds more information on the

ok

public void ok(ReturnValueType value,
               long time,
               AbstractTask task)
this is called after stopped(). it signifies successful task completion. this runs in the EDT.

Specified by:
ok in interface SimpleTaskHandlerIF<ReturnValueType>
Parameters:
value - this is optional. the task may want to pass an object or objects to the task

error

public void error(java.lang.Throwable e,
                  long time,
                  AbstractTask task)
this is called after stopped(). it signifies failure of task execution. this runs in the EDT.

Specified by:
error in interface SimpleTaskHandlerIF<ReturnValueType>
Parameters:
e - this is used to pass the exception that caused the task to stop to be reported to the

cancelled

public void cancelled(long time,
                      AbstractTask task)
This is called after started(). it signifies that the task was cancelled by cancel() being called on it's SwingWorker thread. This is not the same as InterruptedIOException from the IO layer, which results in an Err. Cancel trumps: SimpleTaskHandlerIF.stopped(long, AbstractTask), SimpleTaskHandlerIF.error(Throwable,long, AbstractTask), SimpleTaskHandlerIF.ok(ReturnValueType, long, Task.AbstractTask), and SimpleTaskHandlerIF.interrupted(Throwable, AbstractTask).

In your handler implementation, just throw the results away, and assume everything has stopped and terminated. this runs in the EDT.

Specified by:
cancelled in interface SimpleTaskHandlerIF<ReturnValueType>

shutdownCalled

public void shutdownCalled(AbstractTask task)
This method is called on the task handler when AbstractTask.shutdown() is called. It signifies that the task is going to stop.

Specified by:
shutdownCalled in interface SimpleTaskHandlerIF<ReturnValueType>
Parameters:
task -


Copyright © 2011. All Rights Reserved.