wt.util
Class Consumer

java.lang.Object
  extended bywt.util.Consumer
All Implemented Interfaces:
Iterator
Direct Known Subclasses:
FileConsumer

public abstract class Consumer
extends Object
implements Iterator

Provides support for a multi-threaded producer/consumer. Subclasses should call the init() method before using the consumer.

Supported API: false
Extendable: false


Nested Class Summary
protected static interface Consumer.Producer
          A utility interface that the Consumer uses to producer data.
protected static interface Consumer.Queue
          Utility interface that the Consumer uses to buffer data.
protected static class Consumer.SynchronizedQueue
          Provides basic synchronization for a multi-threaded producer/consumer situation.
 
Field Summary
protected static int DEFAULT_BUFFER_SIZE
           
protected  Consumer.Producer producer
           
protected  Consumer.Queue queue
           
 
Constructor Summary
Consumer()
           
 
Method Summary
protected  Consumer.Queue createQueue(int max_buffer_size)
          Hook to let subclasses create a different queue.
 void finalize()
          This method should be called if you would like to stop iterating prematurely, to allow cleanup work to be done.
 boolean hasNext()
           
protected  void init(Consumer.Producer p)
           
protected  void init(Consumer.Producer p, Consumer.Queue q)
           
protected  void init(Consumer.Producer p, int max_buffer_size)
           
 Object next()
           
 void remove()
          Throws an UnsupportedOperationException.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

protected static final int DEFAULT_BUFFER_SIZE
See Also:
Constant Field Values

producer

protected Consumer.Producer producer

queue

protected Consumer.Queue queue
Constructor Detail

Consumer

public Consumer()
Method Detail

init

protected final void init(Consumer.Producer p,
                          Consumer.Queue q)
Parameters:
p - The producer that will load the data.
q - The queue to get data from.

init

protected final void init(Consumer.Producer p,
                          int max_buffer_size)
Parameters:
p - The producer that will load the data.
max_buffer_size - The number of lines that should be buffered internally by the consumer.

init

protected final void init(Consumer.Producer p)
Parameters:
p - The producer that will load the data.

createQueue

protected Consumer.Queue createQueue(int max_buffer_size)
Hook to let subclasses create a different queue.

Parameters:
max_buffer_size - The maximum size the queue can attain.

hasNext

public final boolean hasNext()
Specified by:
hasNext in interface Iterator
Returns:
true if queue.hasNext() is true.

next

public final Object next()
Specified by:
next in interface Iterator
Returns:
the next entry in the queue.

remove

public final void remove()
Throws an UnsupportedOperationException.

Specified by:
remove in interface Iterator

finalize

public void finalize()
This method should be called if you would like to stop iterating prematurely, to allow cleanup work to be done.