|
Project JXTA | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.jxta.impl.util.UnbiasedQueue
net.jxta.impl.util.ConsumerBiasedQueue
public class ConsumerBiasedQueue
A queue who's implementation is biased towards effciency in removing elements from the queue. FIXME 20020511 bondolo@jxta.org This could be more efficient with a circular queue implementation, but its a pain to write since we allow the queue to be resizable. FIXME 20020511 bondolo@jxta.org Exercise for the reader: Extend this class so that it does both LIFO and FIFO.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class net.jxta.impl.util.UnbiasedQueue |
---|
UnbiasedQueue.SynchronizedQueue |
Field Summary |
---|
Fields inherited from class net.jxta.impl.util.UnbiasedQueue |
---|
closeFlag, DEFAULT_MAX_OBJECTS, DROP_OLDEST_OBJECT, dropOldestObject, DROPPED_OBJECT_WARNING_INTERVAL, maxObjects, nextDroppedWarn, numDequeued, numDropped, numEnqueued, queue, sumOfQueueSizesDequeue, sumOfQueueSizesEnqueue |
Constructor Summary | |
---|---|
ConsumerBiasedQueue()
Default constructor. 100 element FIFO queue which drops oldest element when full. |
|
ConsumerBiasedQueue(int size,
boolean dropOldest)
Full featured constructor for creating a new ConsumerBiasedQueue. |
Method Summary | |
---|---|
void |
clear()
Flush the queue of all pending objects. |
double |
getAvgInQueueAtDequeue()
Return the average number of elements in the queue at dequeue time. |
double |
getAvgInQueueAtEnqueue()
Return the average number of elements in the queue at Enqueue time. |
int |
getCurrentInQueue()
Return the number of elements currently in the queue. |
Object |
pop()
Return next obj in the queue if there is one. |
Object[] |
popMulti(int maxObjs)
Returns an array of objects, possibly empty, from the queue. |
boolean |
push(Object obj)
Attempt to push an object onto the queue. |
boolean |
push(Object obj,
long timeout)
Push an object onto the queue. |
void |
setMaxQueueSize(int maxObjs)
Set how many objects this queue may store. |
Methods inherited from class net.jxta.impl.util.UnbiasedQueue |
---|
close, getMaxQueueSize, getNumDequeued, getNumDropped, getNumEnqueued, interrupt, isClosed, peek, pop, pushBack, pushBack, synchronizedQueue, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ConsumerBiasedQueue()
public ConsumerBiasedQueue(int size, boolean dropOldest)
size
- Queue will be not grow larger than this size. Use
Integer.MAX_VALUE for "unbounded" queue size.dropOldest
- Controls behaviour of element insertion when the queue is
full. If "true" and the queue is full upon a push operation then the
oldest element will be dropped to be replaced with the element currently
being pushed. If "false" then then newest item will be dropped.Method Detail |
---|
public void clear()
clear
in class UnbiasedQueue
public boolean push(Object obj)
UnbiasedQueue
UnbiasedQueue.pop(long)
to
retrieve elements.
push
in class UnbiasedQueue
obj
- object to push
public boolean push(Object obj, long timeout) throws InterruptedException
push
in class UnbiasedQueue
obj
- Object to be pushed onto the queuetimeout
- Time in milliseconds to try to insert the item into a full
queue. Per Java standards, a timeout of "0" (zero) will wait indefinitly.
Negative values force no wait period at all.
InterruptedException
- if the operation is interrupted before
the timeout interval is completed.public Object pop()
pop
in class UnbiasedQueue
public Object[] popMulti(int maxObjs)
popMulti
in class UnbiasedQueue
maxObjs
- the maximum number of items to return.
public void setMaxQueueSize(int maxObjs)
setMaxQueueSize
in class UnbiasedQueue
maxObjs
- The number of objects which the queue must be able to
store.public int getCurrentInQueue()
getCurrentInQueue
in class UnbiasedQueue
public double getAvgInQueueAtEnqueue()
getAvgInQueueAtEnqueue
in class UnbiasedQueue
public double getAvgInQueueAtDequeue()
getAvgInQueueAtDequeue
in class UnbiasedQueue
|
JXTA J2SE | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |