net.sf.saffron.runtime
Class QueueIterator

java.lang.Object
  |
  +--net.sf.saffron.runtime.QueueIterator
All Implemented Interfaces:
Iterator
Direct Known Subclasses:
ThreadIterator

public class QueueIterator
extends Object
implements Iterator

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

Since:
Oct 20, 2003
Version:
$Id: //open/saffron/src/net/sf/saffron/runtime/QueueIterator.java#1 $
Author:
jhyde

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

next_

private Object next_

empty

private Semaphore empty
The producer notifies empty every time it produces an object (or finishes). The consumer waits for it.


full

private Semaphore full
Conversely, the consumer notifies full every time it reads the next object. The producer waits for it, then starts work.


throwable_

private Throwable throwable_

hasNext_

private boolean hasNext_

waitingForProducer_

private boolean waitingForProducer_
Protects the avail_ semaphore.

Constructor Detail

QueueIterator

public QueueIterator()
Method Detail

done

public void done(Throwable throwable)
Producer calls done to say that there are no more objects, setting throwable if there was an error.


hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator

next

public Object next()
Specified by:
next in interface Iterator

put

public void put(Object o)
Producer calls put to add another object (which may be null).


remove

public void remove()
Specified by:
remove in interface Iterator

checkError

private void checkError()
Throws an error if one has been set via done(Throwable).


SourceForge.net_Logo