|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.collections.collection.SynchronizedCollection org.apache.commons.collections.buffer.SynchronizedBuffer org.apache.commons.collections.buffer.BoundedBuffer
public class BoundedBuffer
Decorates another Buffer
to ensure a fixed maximum size.
Note: This class should only be used if you need to add bounded
behaviour to another buffer. If you just want a bounded buffer then
you should use BoundedFifoBuffer
or CircularFifoBuffer
.
The decoration methods allow you to specify a timeout value. This alters the behaviour of the add methods when the buffer is full. Normally, when the buffer is full, the add method will throw an exception. With a timeout, the add methods will wait for up to the timeout period to try and add the elements.
Field Summary |
---|
Fields inherited from class org.apache.commons.collections.collection.SynchronizedCollection |
---|
collection, lock |
Constructor Summary | |
---|---|
protected |
BoundedBuffer(Buffer buffer,
int maximumSize,
long timeout)
Constructor that wraps (not copies) another buffer, making it bounded waiting only up to a maximum amount of time. |
Method Summary | |
---|---|
boolean |
add(java.lang.Object o)
|
boolean |
addAll(java.util.Collection c)
|
static BoundedBuffer |
decorate(Buffer buffer,
int maximumSize)
Factory method to create a bounded buffer. |
static BoundedBuffer |
decorate(Buffer buffer,
int maximumSize,
long timeout)
Factory method to create a bounded buffer that blocks for a maximum amount of time. |
boolean |
isFull()
Returns true if this collection is full and no new elements can be added. |
java.util.Iterator |
iterator()
Iterators must be manually synchronized. |
int |
maxSize()
Gets the maximum size of the collection (the bound). |
java.lang.Object |
remove()
Gets and removes the next object from the buffer. |
Methods inherited from class org.apache.commons.collections.buffer.SynchronizedBuffer |
---|
decorate, get, getBuffer |
Methods inherited from class org.apache.commons.collections.collection.SynchronizedCollection |
---|
clear, contains, containsAll, decorate, equals, hashCode, isEmpty, remove, removeAll, retainAll, size, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Collection |
---|
clear, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, size, toArray, toArray |
Constructor Detail |
---|
protected BoundedBuffer(Buffer buffer, int maximumSize, long timeout)
buffer
- the buffer to wrap, must not be nullmaximumSize
- the maximum size, must be size one or greatertimeout
- the maximum amount of time to wait
java.lang.IllegalArgumentException
- if the buffer is null
java.lang.IllegalArgumentException
- if the maximum size is zero or lessMethod Detail |
---|
public static BoundedBuffer decorate(Buffer buffer, int maximumSize)
When the buffer is full, it will immediately throw a
BufferOverflowException
on calling add()
.
buffer
- the buffer to decorate, must not be nullmaximumSize
- the maximum size, must be size one or greater
java.lang.IllegalArgumentException
- if the buffer is null
java.lang.IllegalArgumentException
- if the maximum size is zero or lesspublic static BoundedBuffer decorate(Buffer buffer, int maximumSize, long timeout)
buffer
- the buffer to decorate, must not be nullmaximumSize
- the maximum size, must be size one or greatertimeout
- the maximum amount of time to wait in milliseconds
java.lang.IllegalArgumentException
- if the buffer is null
java.lang.IllegalArgumentException
- if the maximum size is zero or lesspublic java.lang.Object remove()
Buffer
remove
in interface Buffer
remove
in class SynchronizedBuffer
public boolean add(java.lang.Object o)
add
in interface java.util.Collection
add
in class SynchronizedCollection
public boolean addAll(java.util.Collection c)
addAll
in interface java.util.Collection
addAll
in class SynchronizedCollection
public java.util.Iterator iterator()
SynchronizedCollection
synchronized (coll) { Iterator it = coll.iterator(); // do stuff with iterator }
iterator
in interface java.lang.Iterable
iterator
in interface java.util.Collection
iterator
in class SynchronizedCollection
public boolean isFull()
BoundedCollection
isFull
in interface BoundedCollection
true
if the collection is fullpublic int maxSize()
BoundedCollection
maxSize
in interface BoundedCollection
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |