public class SizeBoundedQueue<T> extends Object
Modifier and Type | Class and Description |
---|---|
protected static class |
SizeBoundedQueue.El<T> |
Modifier and Type | Field and Description |
---|---|
protected int |
count |
protected Lock |
lock |
protected int |
max_size |
protected Condition |
not_empty |
protected Condition |
not_full |
protected Queue<SizeBoundedQueue.El<T>> |
queue |
protected int |
waiters |
Constructor and Description |
---|
SizeBoundedQueue(int max_size) |
SizeBoundedQueue(int max_size,
Lock lock) |
Modifier and Type | Method and Description |
---|---|
void |
add(T element,
int size) |
void |
clear() |
int |
drainTo(Collection<T> c,
int max_bytes)
Removes and adds to collection c as many elements as possible (including waiters) but not exceeding max_bytes.
|
int |
getElements()
Returns the number of elements in the queue
|
int |
getWaiters() |
boolean |
hasWaiters() |
boolean |
isEmpty() |
int |
queueSize()
For testing only - should always be the same as size()
|
T |
remove()
Removes and returns the first element or null if the queue is empty
|
int |
size()
Returns the accumulated size of all elements in the queue
|
String |
toString() |
protected final Lock lock
protected final Condition not_full
protected final Condition not_empty
protected final int max_size
protected final Queue<SizeBoundedQueue.El<T>> queue
protected int count
protected int waiters
public SizeBoundedQueue(int max_size)
public SizeBoundedQueue(int max_size, Lock lock)
public void add(T element, int size) throws InterruptedException
InterruptedException
public T remove()
public int drainTo(Collection<T> c, int max_bytes)
c
- The collection to transfer the removed elements tomax_bytes
- The max number of bytes to removepublic void clear()
public int getElements()
public int size()
public boolean isEmpty()
public int getWaiters()
public boolean hasWaiters()
public int queueSize()
Copyright © 2018 JBoss, a division of Red Hat. All rights reserved.