|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sf.saffron.runtime.QueueIterator
Adapter which exposes a 'push' producer on one thread into an
Iterator
for use by another thread.
The queue contains at most one object. If you call next()
, your thread will wait until another thread calls put(java.lang.Object)
or
done(java.lang.Throwable)
. Nulls are allowed. If the producer has an error, they can
pass it to the consumer via done(java.lang.Throwable)
.
Field Summary | |
private Semaphore |
empty
The producer notifies empty every time it produces an
object (or finishes). |
private Semaphore |
full
Conversely, the consumer notifies full every time it reads
the next object. |
private boolean |
hasNext_
|
private Object |
next_
|
private Throwable |
throwable_
|
private boolean |
waitingForProducer_
Protects the avail_ semaphore. |
Constructor Summary | |
QueueIterator()
|
Method Summary | |
private void |
checkError()
Throws an error if one has been set via done(Throwable) . |
void |
done(Throwable throwable)
Producer calls done to say that there are no more objects,
setting throwable if there was an error. |
boolean |
hasNext()
|
Object |
next()
|
void |
put(Object o)
Producer calls put to add another object (which may be
null). |
void |
remove()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private Object next_
private Semaphore empty
empty
every time it produces an
object (or finishes). The consumer waits for it.
private Semaphore full
full
every time it reads
the next object. The producer waits for it, then starts work.
private Throwable throwable_
private boolean hasNext_
private boolean waitingForProducer_
avail_
semaphore.
Constructor Detail |
public QueueIterator()
Method Detail |
public void done(Throwable throwable)
done
to say that there are no more objects,
setting throwable
if there was an error.
public boolean hasNext()
hasNext
in interface Iterator
public Object next()
next
in interface Iterator
public void put(Object o)
put
to add another object (which may be
null).
public void remove()
remove
in interface Iterator
private void checkError()
done(Throwable)
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |