scranton
Class IteratorThread

java.lang.Object
  extended byjava.lang.Thread
      extended byscranton.IteratorThread
All Implemented Interfaces:
java.util.Iterator, java.lang.Runnable

public abstract class IteratorThread
extends java.lang.Thread
implements java.util.Iterator

An abstract class that implements the Iterator Interface by extending the Thread class allowing software developers to construct iterators over various containers by constructing an agorithm, as a run method, that visits each object int the container and calls the produce method to make the object available to the consumer employing the iterator.


Field Summary
protected  boolean finished
          Set to true when the producer terminates.
protected  boolean full
          Boolean mailbox flag used by the producer/consumer methods
protected  Guard iterating
          The flag in the Guard object is set to false if the structure is changed while the iteration is in progress.
protected  java.lang.Object mailbox
          The producer/consumer mailbox
protected  java.lang.Object removeback
          Feedback to the extended class used by the remove() method.
protected  java.lang.Object removebox
          The producer/consumer info to remove the object in the mailbox
protected  boolean terminate
          Set to true when the consumer terminates the process.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected IteratorThread(Guard fl)
           
 
Method Summary
protected  java.lang.Object consume()
          Classical thread synchronization referenced by the next method to obtain the object.
 boolean hasNext()
          Implements the Iterator's hasNext method
 java.lang.Object next()
          Implements the Iterator's next method
protected  void produce(java.lang.Object obj, java.lang.Object rem)
          Classical thread code for a producer method that is called by the extended class's run method each time an object is produced.
 void remove()
          Remove is not implemented within the thread.
 void terminate()
          Referenced by the client when the client wishes to abort the iteration.
protected  void tookLast()
          Called by the extended class's run method after all objects have been produced, it sets the "finished" flag after the last object has been consumed, or if the consumer terminated the iteration.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mailbox

protected java.lang.Object mailbox
The producer/consumer mailbox


removebox

protected java.lang.Object removebox
The producer/consumer info to remove the object in the mailbox


removeback

protected java.lang.Object removeback
Feedback to the extended class used by the remove() method.


full

protected boolean full
Boolean mailbox flag used by the producer/consumer methods


finished

protected boolean finished
Set to true when the producer terminates.


terminate

protected boolean terminate
Set to true when the consumer terminates the process.


iterating

protected Guard iterating
The flag in the Guard object is set to false if the structure is changed while the iteration is in progress.

Constructor Detail

IteratorThread

protected IteratorThread(Guard fl)
Method Detail

produce

protected void produce(java.lang.Object obj,
                       java.lang.Object rem)
Classical thread code for a producer method that is called by the extended class's run method each time an object is produced.

Parameters:
obj - The next object to be produced
rem - Object that contains information for the remove method

tookLast

protected void tookLast()
Called by the extended class's run method after all objects have been produced, it sets the "finished" flag after the last object has been consumed, or if the consumer terminated the iteration.


hasNext

public boolean hasNext()
Implements the Iterator's hasNext method

Specified by:
hasNext in interface java.util.Iterator

next

public java.lang.Object next()
Implements the Iterator's next method

Specified by:
next in interface java.util.Iterator

consume

protected java.lang.Object consume()
Classical thread synchronization referenced by the next method to obtain the object.

Returns:
Returns the object in the mailbox and sets the mail flag

remove

public void remove()
Remove is not implemented within the thread.

Specified by:
remove in interface java.util.Iterator

terminate

public void terminate()
Referenced by the client when the client wishes to abort the iteration.