org.apache.commons.collections.buffer
Class BlockingBuffer
java.lang.Object
|
+--org.apache.commons.collections.collection.SynchronizedCollection
|
+--org.apache.commons.collections.buffer.SynchronizedBuffer
|
+--org.apache.commons.collections.buffer.BlockingBuffer
- All Implemented Interfaces:
- Buffer, Collection
- public class BlockingBuffer
- extends SynchronizedBuffer
Decorates another 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(java.lang.Object)
or addAll(java.util.Collection)
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.
- Since:
- Commons Collections 3.0
- Version:
- $Revision: 1.2 $ $Date: 2004/01/14 21:43:08 $
- Author:
- Stephen Colebourne, Janek Bogucki, Phil Steitz
Methods inherited from class org.apache.commons.collections.collection.SynchronizedCollection |
clear, contains, containsAll, decorate, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString |
Methods inherited from interface java.util.Collection |
clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
BlockingBuffer
protected BlockingBuffer(Buffer buffer)
- Constructor that wraps (not copies).
- Parameters:
buffer
- the buffer to decorate, must not be null- Throws:
IllegalArgumentException
- if the buffer is null
decorate
public static Buffer decorate(Buffer buffer)
- Factory method to create a blocking buffer.
- Parameters:
buffer
- the buffer to decorate, must not be null- Throws:
IllegalArgumentException
- if buffer is null
add
public boolean add(Object o)
- Overrides:
add
in class SynchronizedCollection
addAll
public boolean addAll(Collection c)
- Overrides:
addAll
in class SynchronizedCollection
get
public Object get()
- Description copied from interface:
Buffer
- Gets the next object from the buffer without removing it.
- Overrides:
get
in class SynchronizedBuffer
- Following copied from interface:
org.apache.commons.collections.Buffer
- Returns:
- the next object in the buffer, which is not removed
- Throws:
BufferUnderflowException
- if the buffer is empty
remove
public Object remove()
- Description copied from interface:
Buffer
- Gets and removes the next object from the buffer.
- Overrides:
remove
in class SynchronizedBuffer
- Following copied from interface:
org.apache.commons.collections.Buffer
- Returns:
- the next object in the buffer, which is also removed
- Throws:
BufferUnderflowException
- if the buffer is already empty
Copyright © 2001-2004 Apache Software Foundation. All Rights Reserved.