de.jaetzold.util
Class TaskPerformer

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--de.jaetzold.util.TaskPerformer
All Implemented Interfaces:
Runnable

public class TaskPerformer
extends Thread

A Thread which processes Tasks. It continuously tries to get Tasks from its associated TaskQueue and calls their perform()-method. This call can return an Event or null. Any results from that call or any Exceptions are posted to the resultEventQueue of this TaskPerformer if it has any. In parts a similar functionality could've been aquired by using java.util.Timer and java.util.TimerTask. But this code here therefor works in Java 1.1.x and higher, and has some extra-features like the resultEventQueue and the associated possibility of passing exceptions from this thread to another.


Field Summary
protected  Queue resultEventQueue
           
protected  Object resultEventQueueMonitor
           
protected  Queue taskQueue
           
protected  Object taskQueueMonitor
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
TaskPerformer(Queue taskQueue)
           
 
Method Summary
 void endPerforming()
           
 Queue getResultEventQueue()
           
 Queue getTaskQueue()
           
 void haltPerforming()
           
 void haltPerforming(boolean interruptAndWait)
           
 void interrupt(Task task)
          Interrupts this Thread if it is currently processing the given Event.
 void resumePerforming()
           
 void run()
           
 void setResultEventQueue(Queue resultEventQueue)
           
 void setTaskQueue(Queue taskQueue)
           
 void waitForHalt()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

resultEventQueueMonitor

protected Object resultEventQueueMonitor

resultEventQueue

protected Queue resultEventQueue

taskQueue

protected Queue taskQueue

taskQueueMonitor

protected Object taskQueueMonitor
Constructor Detail

TaskPerformer

public TaskPerformer(Queue taskQueue)
Method Detail

getResultEventQueue

public Queue getResultEventQueue()

setResultEventQueue

public void setResultEventQueue(Queue resultEventQueue)

getTaskQueue

public Queue getTaskQueue()

setTaskQueue

public void setTaskQueue(Queue taskQueue)

interrupt

public void interrupt(Task task)
Interrupts this Thread if it is currently processing the given Event. If the given Event is null then this Thread is interrupted if it is currently processing any Event. This method should be used instead of interrupt(), because there should be no reason to interrupt this Thread while doing other things apart from processing an Event.

endPerforming

public void endPerforming()

haltPerforming

public void haltPerforming()

haltPerforming

public void haltPerforming(boolean interruptAndWait)

waitForHalt

public void waitForHalt()
                 throws InterruptedException

resumePerforming

public void resumePerforming()

run

public void run()
Overrides:
run in class Thread