Task
Interface SimpleTaskHandlerIF<ReturnValueType>

All Known Subinterfaces:
NetworkTaskHandlerIF<ReturnValueType>
All Known Implementing Classes:
NetworkTaskHandler, SimpleTaskHandler

public interface SimpleTaskHandlerIF<ReturnValueType>

TaskHandlerIF is an interface that encapsulates the various lifecyle stages that a task will go through. This allows task writers to add event handling code as a task progresses through various stages.

Here's a quick rundown of the various paths that can be taken:

  1. beforeStart -> started -> stopped -> ok
  2. beforeStart -> started -> stopped -> error
  3. beforeStart -> started -> stopped -> interrupted
  4. beforeStart -> started -> stopped -> cancelled

Since:
Oct 5, 2007, 9:59:16 AM
Version:
1.0
Author:
Nazmul Idris

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.
 

Method Detail

beforeStart

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.


started

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.


stopped

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.


interrupted

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.

Parameters:
e - this holds the underlying exception that holds more information on the

ok

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

Parameters:
value - this is optional. the task may want to pass an object or objects to the task

error

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.

Parameters:
e - this is used to pass the exception that caused the task to stop to be reported to the

cancelled

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: stopped(long, AbstractTask), error(Throwable,long, AbstractTask), ok(ReturnValueType, long, Task.AbstractTask), and interrupted(Throwable, AbstractTask).

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


shutdownCalled

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.



Copyright © 2011. All Rights Reserved.