Package org.jgroups.util
Class SizeBoundedQueue<T>
java.lang.Object
org.jgroups.util.SizeBoundedQueue<T>
Blocking FIFO queue bounded by the max number of bytes of all elements. When adding threads are blocked due to
capacity constraints, and the application terminates, it is the caller's duty to interrupt all threads.
- Since:
- 4.0.4
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclear(boolean done) intdrainTo(Collection<T> c, int max_bytes) Removes and adds to collection c as many elements as possible (including waiters) but not exceeding max_bytes.intReturns the number of elements in the queueintbooleanbooleanisDone()booleanisEmpty()intFor testing only - should always be the same as size()remove()Removes and returns the first element or null if the queue is emptyintsize()Returns the accumulated size of all elements in the queuetoString()
-
Field Details
-
lock
-
not_full
-
not_empty
-
max_size
protected final int max_size -
queue
-
count
protected int count -
waiters
protected int waiters -
done
protected boolean done
-
-
Constructor Details
-
SizeBoundedQueue
public SizeBoundedQueue(int max_size) -
SizeBoundedQueue
-
-
Method Details
-
add
- Throws:
InterruptedException
-
remove
Removes and returns the first element or null if the queue is empty -
drainTo
Removes and adds to collection c as many elements as possible (including waiters) but not exceeding max_bytes. E.g. if we have elements {1000b, 2000b, 4000b} and max_bytes=6000, then only the first 2 elements are removed and the new size is 4000- Parameters:
c- The collection to transfer the removed elements tomax_bytes- The max number of bytes to remove- Returns:
- The accumulated number of bytes of all removed elements
-
clear
public void clear(boolean done) -
getElements
public int getElements()Returns the number of elements in the queue -
size
public int size()Returns the accumulated size of all elements in the queue -
isEmpty
public boolean isEmpty() -
getWaiters
public int getWaiters() -
hasWaiters
public boolean hasWaiters() -
isDone
public boolean isDone() -
queueSize
public int queueSize()For testing only - should always be the same as size() -
toString
-