E - the type of the elements in the bufferpublic class BlockingBuffer<E> extends SynchronizedBuffer<E>
Buffer to make get() and
remove() block when the Buffer is empty.
If either get or remove is called on an empty
Buffer, the calling thread waits for notification that
an add or addAll operation has completed.
When one or more entries are added to an empty Buffer,
all threads blocked in get or remove are notified.
There is no guarantee that concurrent blocked get or
remove requests will be "unblocked" and receive data in the
order that they arrive.
This class is Serializable from Commons Collections 3.1. This class contains an extra field in 3.2, however the serialization specification will handle this gracefully.
collection, lock| Modifier | Constructor and Description |
|---|---|
protected |
BlockingBuffer(Buffer<E> buffer)
Constructor that wraps (not copies).
|
protected |
BlockingBuffer(Buffer<E> buffer,
long timeoutMillis)
Constructor that wraps (not copies).
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E o) |
boolean |
addAll(Collection<? extends E> c) |
static <E> BlockingBuffer<E> |
blockingBuffer(Buffer<E> buffer)
Factory method to create a blocking buffer.
|
static <E> BlockingBuffer<E> |
blockingBuffer(Buffer<E> buffer,
long timeoutMillis)
Factory method to create a blocking buffer with a timeout value.
|
E |
get()
Gets the next value from the buffer, waiting until an object is
added if the buffer is empty.
|
E |
get(long timeout)
Gets the next value from the buffer, waiting until an object is
added for up to the specified timeout value if the buffer is empty.
|
E |
remove()
Removes the next value from the buffer, waiting until an object is
added if the buffer is empty.
|
E |
remove(long timeout)
Removes the next value from the buffer, waiting until an object is
added for up to the specified timeout value if the buffer is empty.
|
decorated, synchronizedBufferclear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, synchronizedCollection, toArray, toArray, toStringprotected BlockingBuffer(Buffer<E> buffer)
buffer - the buffer to decorate, must not be nullIllegalArgumentException - if the buffer is nullprotected BlockingBuffer(Buffer<E> buffer, long timeoutMillis)
buffer - the buffer to decorate, must not be nulltimeoutMillis - the timeout value in milliseconds, zero or less for no timeoutIllegalArgumentException - if the buffer is nullpublic static <E> BlockingBuffer<E> blockingBuffer(Buffer<E> buffer)
E - the type of the elements in the bufferbuffer - the buffer to decorate, must not be nullIllegalArgumentException - if buffer is nullpublic static <E> BlockingBuffer<E> blockingBuffer(Buffer<E> buffer, long timeoutMillis)
E - the type of the elements in the bufferbuffer - the buffer to decorate, must not be nulltimeoutMillis - the timeout value in milliseconds, zero or less for no timeoutIllegalArgumentException - if the buffer is nullpublic boolean add(E o)
add in interface Collection<E>add in class SynchronizedCollection<E>public boolean addAll(Collection<? extends E> c)
addAll in interface Collection<E>addAll in class SynchronizedCollection<E>public E get()
get in interface Buffer<E>get in class SynchronizedBuffer<E>BufferUnderflowException - if an interrupt is received
if the buffer is emptypublic E get(long timeout)
timeout - the timeout value in millisecondsBufferUnderflowException - if an interrupt is receivedBufferUnderflowException - if the timeout expirespublic E remove()
remove in interface Buffer<E>remove in class SynchronizedBuffer<E>BufferUnderflowException - if an interrupt is received
if the buffer is already emptypublic E remove(long timeout)
timeout - the timeout value in millisecondsBufferUnderflowException - if an interrupt is receivedBufferUnderflowException - if the timeout expiresCopyright © 2001-2013 The Apache Software Foundation. All Rights Reserved.