|
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.UnbiasedQueue.SynchronizedQueue
An inner class for wrapping arbitrary queues with synchronization.
Nested Class Summary |
Nested classes inherited from class net.jxta.impl.util.UnbiasedQueue |
UnbiasedQueue.SynchronizedQueue |
Field Summary | |
(package private) UnbiasedQueue |
innerqueue
|
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 | |
UnbiasedQueue.SynchronizedQueue(UnbiasedQueue queue)
{@inheritDoc} |
Method Summary | |
void |
clear()
Flush the queue of all pending objects. |
void |
close()
Close the queue. This will prevent any further objects from being enqueued. |
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. |
int |
getMaxQueueSize()
How many objects will fit in this queue |
long |
getNumDequeued()
Return the total number of objects which have been dequeued from this queue during its existance. |
long |
getNumDropped()
Return the total number of objects which have been dropped by this queue during its existance. |
long |
getNumEnqueued()
Return the total number of objects which have been enqueued on to this queue during its existance. |
boolean |
isClosed()
Atomically return whether or not this queue has been closed. Closed queues will not accept "push" requests, but elements will still be returned with "pop". |
Object |
peek()
Return the next Object from the queue without removing it. |
Object |
pop()
Remove and return the next Object from the queue. |
Object |
pop(long timeout)
Gets a Object from the queue. If no Object is immediately available, then wait the specified amount of time for an Object to be inserted. |
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. If the queue is full then the object will not be pushed. This method does not use any synchronization and should not be used if other threads are using UnbiasedQueue.pop(long) to
retrieve elements. |
boolean |
push(Object obj,
long timeout)
Push an object onto the queue. If the queue is full then the push will wait for up to "timeout" milliseconds to push the object. At the end of "timeout" milliseconds, the push will either return false or remove the oldest item from the queue and insert "obj". This behaviour is contolled by the constructor parameter "dropOldest". |
boolean |
pushBack(Object obj)
Attempt to push an object back at the head the queue. If the queue is full then the object will not be pushed. This method does not use any synchronization and should not be used if other threads are using UnbiasedQueue.pop(long) to retrieve elements. |
boolean |
pushBack(Object obj,
long timeout)
Push an object back at the head of the queue. If the queue is full then the push will wait for up to "timeout" milliseconds to push the object. At the end of "timeout" milliseconds, the push will either return false or remove the oldest item from the queue and insert "obj". This behaviour is contolled by the constructor parameter "dropOldest". Timeout control is accomplished via synchronization and Object.wait(long) . UnbiasedQueue.pushBack(Object,long) should only
be used in conjunction with UnbiasedQueue.push(Object,long) and
UnbiasedQueue.pop(long) |
void |
setMaxQueueSize(int maxObjs)
Set how many objects this queue may store. Note that if there are more objects already in the queue than the specified amount then the queue will retain its current capacity. |
Methods inherited from class net.jxta.impl.util.UnbiasedQueue |
interrupt, synchronizedQueue, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
UnbiasedQueue innerqueue
Constructor Detail |
public UnbiasedQueue.SynchronizedQueue(UnbiasedQueue queue)
Method Detail |
public boolean isClosed()
isClosed
in class UnbiasedQueue
public void close()
close
in class UnbiasedQueue
public void clear()
clear
in class UnbiasedQueue
public boolean push(Object obj)
UnbiasedQueue.pop(long)
to
retrieve elements.
push
in class UnbiasedQueue
obj
- object to push
public boolean pushBack(Object obj)
UnbiasedQueue.pop(long)
to retrieve elements.
pushBack
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 boolean pushBack(Object obj, long timeout) throws InterruptedException
Object.wait(long)
. UnbiasedQueue.pushBack(Object,long)
should only
be used in conjunction with UnbiasedQueue.push(Object,long)
and
UnbiasedQueue.pop(long)
pushBack
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 peek()
peek
in class UnbiasedQueue
public Object pop()
pop
in class UnbiasedQueue
public Object pop(long timeout) throws InterruptedException
pop
in class UnbiasedQueue
timeout
- Amount of time to wait in milliseconds for an object to
be available. Per Java convention, a timeout of zero (0) means wait an
infinite amount of time. Negative values mean do not wait at all.
InterruptedException
- if the operation is interrupted before
the timeout interval is completed.public Object[] popMulti(int maxObjs)
popMulti
in class UnbiasedQueue
maxObjs
- the maximum number of items to return.
public int getMaxQueueSize()
getMaxQueueSize
in class UnbiasedQueue
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()
UnbiasedQueue
UnbiasedQueue.push(Object)
and UnbiasedQueue.pop(long)
methods to regulate how you
use the queue.
getCurrentInQueue
in class UnbiasedQueue
public long getNumEnqueued()
getNumEnqueued
in class UnbiasedQueue
public double getAvgInQueueAtEnqueue()
getAvgInQueueAtEnqueue
in class UnbiasedQueue
public long getNumDequeued()
getNumDequeued
in class UnbiasedQueue
public double getAvgInQueueAtDequeue()
getAvgInQueueAtDequeue
in class UnbiasedQueue
public long getNumDropped()
getNumDropped
in class UnbiasedQueue
|
JXTA J2SE | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |