|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jut.lang.AbstractOneTimeIterable<T> jut.util.concurrent.BlockingOpenIterable<T>
public class BlockingOpenIterable<T>
consumer/producer utility class for asynchronous use. the producer(s) add items that are cached
in a bounded cache - if the cache is full, the addItem(Object)
method waits for the
consumer(s) to remove items. the consumer(s) remove items using the sole Iterator
of this
object, usually in a for (Itemtype item : blockingOpenIterable)
loop.
as alternative to asynchronous use, the item cache can be filled in advance, close()
can
be called and the items be consumed in a for
loop - all in one thread.
note that the consumer(s) will keep waiting for items even if the cache is empty until the
close()
method is called.
this class adds a utility for consumer/producer scenarios to the utilities of the standard JDK.
Constructor Summary | |
---|---|
BlockingOpenIterable()
create a consumer/producer Iterable with an unbounded internal cache. |
|
BlockingOpenIterable(int capacity)
create a consumer/producer Iterable with a defined internal cache capacity. |
Method Summary | |
---|---|
BlockingOpenIterable<T> |
addItem(T item)
add a new item to this BlockingOpenIterable , waiting if the cache is full. |
BlockingOpenIterable<T> |
addItems(Iterable<T> items)
add new items to this BlockingOpenIterable , waiting if the cache is full. |
BlockingOpenIterable<T> |
close()
close this BlockingOpenIterable so no more items may be added by
addItem(Object) . |
protected boolean |
iteratorHasNext()
returns true if the iterator has more elements. |
protected T |
iteratorNext()
returns the next element in the iterator. |
Methods inherited from class jut.lang.AbstractOneTimeIterable |
---|
iterator, onNext |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BlockingOpenIterable()
Iterable
with an unbounded internal cache.
public BlockingOpenIterable(int capacity)
Iterable
with a defined internal cache capacity.
capacity
- - the capacity of the items cache. if set to 0 or less, the capacity is set to
Integer.MAX_VALUE
.Method Detail |
---|
public BlockingOpenIterable<T> close()
BlockingOpenIterable
so no more items may be added by
addItem(Object)
.
public BlockingOpenIterable<T> addItem(T item) throws IllegalStateException
BlockingOpenIterable
, waiting if the cache is full.
item
- - the item to add.
IllegalStateException
- if this BlockingOpenIterable
has already been
closed. waiting threads may also return with this exception.public BlockingOpenIterable<T> addItems(Iterable<T> items) throws IllegalStateException
BlockingOpenIterable
, waiting if the cache is full.
items
- - the items to add.
IllegalStateException
- if this BlockingOpenIterable
has already been
closed. waiting threads may also return with this exception.protected boolean iteratorHasNext()
AbstractOneTimeIterable.iteratorNext()
would return an element rather than throwing an exception.) if no items are cached in this BlockingOpenIterable
, waits until either
items become available or close()
is called.
iteratorHasNext
in class AbstractOneTimeIterable<T>
true
if the iterator has more elements, false
if not.protected T iteratorNext() throws NoSuchElementException
BlockingOpenIterable
, waits until either
items become available or close()
is called.
iteratorNext
in class AbstractOneTimeIterable<T>
NoSuchElementException
- the iteration has no more elements (close()
was
called).
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |