org.apache.commons.collections.buffer

Class BlockingBuffer

Implemented Interfaces:
Buffer, Collection, Serializable

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 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.

Version:
$Revision: 1.7 $ $Date: 2004/06/03 22:02:13 $
Authors:
Stephen Colebourne
Janek Bogucki
Phil Steitz
Since:
Commons Collections 3.0

Field Summary

Fields inherited from class org.apache.commons.collections.collection.SynchronizedCollection

collection, lock

Constructor Summary

BlockingBuffer(Buffer buffer)
Constructor that wraps (not copies).

Method Summary

boolean
add(Object o)
boolean
addAll(Collection c)
static Buffer
decorate(Buffer buffer)
Factory method to create a blocking buffer.
Object
get()
Object
remove()

Methods inherited from class org.apache.commons.collections.buffer.SynchronizedBuffer

decorate, get, getBuffer, remove

Methods inherited from class org.apache.commons.collections.collection.SynchronizedCollection

add, addAll, clear, contains, containsAll, decorate, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString

Constructor Details

BlockingBuffer

protected BlockingBuffer(Buffer buffer)
Constructor that wraps (not copies).
Parameters:
buffer - the buffer to decorate, must not be null

Method Details

add

public boolean add(Object o)
Overrides:
add in interface SynchronizedCollection

addAll

public boolean addAll(Collection c)
Overrides:
addAll in interface SynchronizedCollection

decorate

public static Buffer decorate(Buffer buffer)
Factory method to create a blocking buffer.
Overrides:
decorate in interface SynchronizedBuffer
Parameters:
buffer - the buffer to decorate, must not be null
Returns:
a new blocking Buffer

get

public Object get()
Specified by:
get in interface Buffer
Overrides:
get in interface SynchronizedBuffer

remove

public Object remove()
Specified by:
remove in interface Buffer
Overrides:
remove in interface SynchronizedBuffer

Copyright © 2001-2006 Apache Software Foundation. All Rights Reserved.