public class SizeBoundedQueue
extends java.lang.Object
implements java.util.concurrent.BlockingQueue
TP.IncomingPacket
elements.
The queue maintains a max number of bytes and a total of all of the messages in the internal queues. Whenever a
message is added, we increment the total by the length of the message. When a message is removed, we decrement the
total. Removal blocks until a message is available, addition blocks if the max size has been exceeded, until there
is enough space to add another message.
Note that the max size should always be greater than the size of the largest message to be received, otherwise an
additon would always fail because msg.length > max size !Constructor and Description |
---|
SizeBoundedQueue() |
Modifier and Type | Method and Description |
---|---|
boolean |
add(java.lang.Object o) |
boolean |
addAll(java.util.Collection c) |
void |
clear() |
boolean |
contains(java.lang.Object o) |
boolean |
containsAll(java.util.Collection c) |
int |
drainTo(java.util.Collection c) |
int |
drainTo(java.util.Collection c,
int maxElements) |
java.lang.Object |
element() |
boolean |
isEmpty() |
java.util.Iterator |
iterator() |
boolean |
offer(java.lang.Object o) |
boolean |
offer(java.lang.Object o,
long timeout,
java.util.concurrent.TimeUnit unit) |
java.lang.Object |
peek() |
java.lang.Object |
poll() |
java.lang.Object |
poll(long timeout,
java.util.concurrent.TimeUnit unit) |
void |
put(java.lang.Object o) |
int |
remainingCapacity() |
java.lang.Object |
remove() |
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection c) |
boolean |
retainAll(java.util.Collection c) |
int |
size() |
java.lang.Object |
take() |
java.lang.Object[] |
toArray() |
java.lang.Object[] |
toArray(java.lang.Object[] a) |
public boolean add(java.lang.Object o)
add
in interface java.util.Collection
add
in interface java.util.concurrent.BlockingQueue
add
in interface java.util.Queue
public int drainTo(java.util.Collection c)
drainTo
in interface java.util.concurrent.BlockingQueue
public int drainTo(java.util.Collection c, int maxElements)
drainTo
in interface java.util.concurrent.BlockingQueue
public boolean offer(java.lang.Object o)
offer
in interface java.util.concurrent.BlockingQueue
offer
in interface java.util.Queue
public boolean offer(java.lang.Object o, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
offer
in interface java.util.concurrent.BlockingQueue
java.lang.InterruptedException
public java.lang.Object poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
poll
in interface java.util.concurrent.BlockingQueue
java.lang.InterruptedException
public void put(java.lang.Object o) throws java.lang.InterruptedException
put
in interface java.util.concurrent.BlockingQueue
java.lang.InterruptedException
public int remainingCapacity()
remainingCapacity
in interface java.util.concurrent.BlockingQueue
public java.lang.Object take() throws java.lang.InterruptedException
take
in interface java.util.concurrent.BlockingQueue
java.lang.InterruptedException
public java.lang.Object element()
element
in interface java.util.Queue
public java.lang.Object peek()
peek
in interface java.util.Queue
public java.lang.Object poll()
poll
in interface java.util.Queue
public java.lang.Object remove()
remove
in interface java.util.Queue
public boolean addAll(java.util.Collection c)
addAll
in interface java.util.Collection
public void clear()
clear
in interface java.util.Collection
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection
contains
in interface java.util.concurrent.BlockingQueue
public boolean containsAll(java.util.Collection c)
containsAll
in interface java.util.Collection
public boolean isEmpty()
isEmpty
in interface java.util.Collection
public java.util.Iterator iterator()
iterator
in interface java.lang.Iterable
iterator
in interface java.util.Collection
public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection
remove
in interface java.util.concurrent.BlockingQueue
public boolean removeAll(java.util.Collection c)
removeAll
in interface java.util.Collection
public boolean retainAll(java.util.Collection c)
retainAll
in interface java.util.Collection
public int size()
size
in interface java.util.Collection
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection
public java.lang.Object[] toArray(java.lang.Object[] a)
toArray
in interface java.util.Collection
Copyright ? 1998-2008 Bela Ban. All Rights Reserved.