|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object uk.org.iscream.cms.util.Queue
A Queue class designed to operate in a multi-threaded environment, with added support for multiple "consumer" threads. Also offers blocking on the get() methods, which ensures the consumer waits until the queue actually contains some elements.
Field Summary | |
private int |
_count
A counter so we know how many data items have been passed through, for statistical purposes. |
private LinkedList |
_lists
The LinkedLists of queues. |
private int |
_maxSize
The maximum size of any Queue. |
private String |
_name
This is the friendly identifier of the component this class is running in. |
private QueueMonitor |
_queueMon
A reference to our QueueMonitor, if we have one. |
private int |
_removeAlgorithm
The remove algorithm to use upon a Queue reaching it's maximum size. |
static String[] |
algorithms
To allow opposite lookups. |
static int |
DROP
Pass to constructor to drop the new item upon reaching the maximum Queue limit. |
static int |
FIRST
Pass to constructor to remove the FIRST item from the Queue upon reaching the maximum limit. |
static int |
LAST
Pass to constructor to remove the LAST item from the Queue upon reaching the maximum limit. |
static int |
RANDOM
Pass to constructor to remove a RANDOM item from the Queue upon reaching the maximum limit. |
static String |
REVISION
The current CVS revision of this class |
Constructor Summary | |
Queue()
Constructs a Queue with no maximum size. |
|
Queue(int maxSize,
int removeAlgorithm)
Constructs a new Queue with a maximum size limit on any individual queue. |
Method Summary | |
void |
add(Object o)
This method adds a given object to every queue. |
void |
clearQueue(int queue)
This method erases the contents of a given queue. |
int |
elementCount()
Returns the total numer of elements to have passed through this queue. |
Object |
get(int queue)
This method returns an object from the front of a given queue. |
int |
getQueue()
This method assigns a queue to a consumer. |
int |
queueSize(int queue)
Returns the size of a given queue. |
void |
releaseQueue(int queue)
This method releases a get() method that's currently waiting on an empty queue. |
void |
removeQueue(int queue)
This method sets a entry to null in the list. |
private void |
removeQueueItem(LinkedList list)
This method removes an item from a Queue, using a method requested at construction. |
boolean |
startMonitor(long interval,
Queue destQueue,
String name)
Start a monitor on our own Queue. |
boolean |
startMonitor(long interval,
String name)
Start a monitor on our own Queue. |
boolean |
stopMonitor()
Stop a monitor on our Queue if we have on running. |
String |
toString()
Overrides the Object.toString()
method to provide clean logging (every class should have this). |
String |
xmlStatus()
This method returns an XML textual status of the queues. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final String REVISION
public static final int RANDOM
public static final int FIRST
public static final int LAST
public static final int DROP
public static final String[] algorithms
private LinkedList _lists
private int _count
private QueueMonitor _queueMon
private int _maxSize
private int _removeAlgorithm
private String _name
Constructor Detail |
public Queue(int maxSize, int removeAlgorithm)
maxSize
- the upper limit for a queueremoveAlgorithm
- the remove algorithm to use upon reaching the maxSizepublic Queue()
Method Detail |
public void add(Object o)
o
- An Object to be added to the queues.public Object get(int queue) throws InvalidQueueException
InvalidQueueException
- if the queue does not exist.public void releaseQueue(int queue)
queue
- the queue to release.public void clearQueue(int queue)
queue
- the queue to empty.public String xmlStatus()
public int queueSize(int queue) throws InvalidQueueException
queue
- The queue number to query.
InvalidQueueException
- if the queue does not exist.public int elementCount()
public int getQueue()
public void removeQueue(int queue)
queue
- The integer identifier for the queue, given by getQueue().public boolean startMonitor(long interval, Queue destQueue, String name)
interval
- The long interval, in milliseconds, at which to take samplesdestQueue
- The queue to monitor toname
- A name to identify this Queue with
public boolean startMonitor(long interval, String name)
interval
- The long interval, in milliseconds, at which to take samplesname
- A name to identify this Queue with
public boolean stopMonitor()
public String toString()
Object.toString()
method to provide clean logging (every class should have this).
This uses the uk.org.iscream.cms.server.util.FormatName class
to format the toString()
private void removeQueueItem(LinkedList list)
list
- The LinkedList from which to remove an item.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |