saffron.runtime
Class QueueIterator

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

class QueueIterator
extends Object
implements Iterator

QueueIterator 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
(package private) 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

waitingForProducer_

private boolean waitingForProducer_
Protects the avail_ semaphore.


hasNext_

private boolean hasNext_

next_

private Object next_

throwable_

private Throwable throwable_

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.

Constructor Detail

QueueIterator

QueueIterator()
Method Detail

hasNext

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

next

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

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


put

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


done

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


SourceForge.net_Logo