org.xlattice.util.threads
Class ThreadList

java.lang.Object
  extended by org.xlattice.util.threads.ThreadList

public class ThreadList
extends java.lang.Object

A fixed-size list of Killables, Threads which can run jobs for us. This class is not thread-safe. All external calls should be synchronized on the class instance. XXX BAD IDEA: this class should be made thread-safe. XXX ERROR: removing a Thread doesn't affect the busy count!

Author:
Jim Dixon

Field Summary
static int MIN_CAPACITY
           
 
Constructor Summary
ThreadList(int n)
           
 
Method Summary
 void add(Killable o)
          Add a thread to the lit.
 boolean allBusy()
          Is everyone busy?
 boolean allIdle()
          Is everyone idle?
 int capacity()
           
 void die()
          Mark all list members as dying.
 void endJob()
          Decrease busy count.
 Killable pop()
          Remove last object from list.
 boolean remove(Killable o)
          Remove a specific item from the list.
 int size()
           
 void startJob()
          Increase busy count.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_CAPACITY

public static final int MIN_CAPACITY
See Also:
Constant Field Values
Constructor Detail

ThreadList

public ThreadList(int n)
Parameters:
n - list capacity; at least MIN_CAPACITY
Method Detail

startJob

public void startJob()
Increase busy count. If this is more than the _current_ list size, we have an internal error.


endJob

public void endJob()
Decrease busy count.


allBusy

public boolean allBusy()
Is everyone busy?


allIdle

public boolean allIdle()
Is everyone idle?


add

public void add(Killable o)
Add a thread to the lit.


capacity

public int capacity()
Returns:
the fixed capacity of the list

die

public void die()
Mark all list members as dying.


size

public int size()
Returns:
the number of Killables in the list

pop

public Killable pop()
Remove last object from list. XXX Utility doubtful, but it's in the tests.


remove

public boolean remove(Killable o)
Remove a specific item from the list. This does not kill the thread. XXX SHOULD NOT BE USED

Parameters:
o - the object to be removed
Returns:
true if the object was found in the list, false otherwise.