Jacson

de.spieleck.util
Class TaskQueue

java.lang.Object
  extended byde.spieleck.util.TaskQueue
All Implemented Interfaces:
TaskSource

public class TaskQueue
extends java.lang.Object
implements TaskSource

A queue of Tasks (Runnables) for the ThreadPool.

Version:
0.0
Author:
fsn

Field Summary
protected  java.lang.Object cLock
          Lock for counting
protected  boolean started
          Did we allready have an assignement?
protected  java.util.LinkedList tasks
          The queue of Files which need to be processed
protected  boolean workExpected
          Can we finish now?
 
Constructor Summary
TaskQueue()
          Construct a queue.
 
Method Summary
 void addTask(java.lang.Runnable r)
          Add a task to execute
 java.lang.Runnable getTask()
          Get the next task to execute
 boolean isStarted()
          Have we been started ?
 boolean isWorkLeft()
          Is there something left to do?
 void setWorkExpected(boolean workExpected)
          In case we expect that the queue empties in between (since we are feeding in tasks slowly and the tasks finish fast), but we want to avoid isWorkLeft() to return * the "wrong message", we can use this.
 void waitStart()
          Block a thread until we are started
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tasks

protected java.util.LinkedList tasks
The queue of Files which need to be processed


started

protected boolean started
Did we allready have an assignement?


workExpected

protected boolean workExpected
Can we finish now?


cLock

protected java.lang.Object cLock
Lock for counting

Constructor Detail

TaskQueue

public TaskQueue()
Construct a queue.

Method Detail

getTask

public java.lang.Runnable getTask()
                           throws java.lang.InterruptedException
Get the next task to execute

Specified by:
getTask in interface TaskSource
Returns:
a Task to be executed.
Throws:
java.lang.InterruptedException - when the running task gets interrupted.

addTask

public void addTask(java.lang.Runnable r)
Add a task to execute


setWorkExpected

public void setWorkExpected(boolean workExpected)
In case we expect that the queue empties in between (since we are feeding in tasks slowly and the tasks finish fast), but we want to avoid isWorkLeft() to return * the "wrong message", we can use this.
 TaskQueue tq = new TaskQueue(...)
 tq.setWorkExpected(true);
 ....
 
But one must not fail to call
 tq.setWorkExpected(false);
 
when no feeds are expected any more, since, otherwise isWorkLeft() will return true forever!


isStarted

public boolean isStarted()
Have we been started ?

Specified by:
isStarted in interface TaskSource
Returns:
true if something has been done.

isWorkLeft

public boolean isWorkLeft()
Is there something left to do? As long as we expect new work to come, this is true; If we do not expect more work to come, it depends on what we have left.

Specified by:
isWorkLeft in interface TaskSource
Returns:
true if there is still something to do.

waitStart

public void waitStart()
               throws java.lang.InterruptedException
Description copied from interface: TaskSource
Block a thread until we are started

Specified by:
waitStart in interface TaskSource
Throws:
java.lang.InterruptedException - when the running task gets interrupted.

Spieleck

Copyleft 2002 spieleck.de.