jconch.pipeline
Class Producer<OUT_T>

java.lang.Object
  extended by jconch.pipeline.PipelineStage
      extended by jconch.pipeline.Producer<OUT_T>
Type Parameters:
OUT_T - The type of the object that is produced by this element.
Direct Known Subclasses:
CollectionProducer, FactoryProducer

public abstract class Producer<OUT_T>
extends PipelineStage

The base implementation of a pipe that produces new elements to retrieve.

Author:
Robert Fischer

Field Summary
protected  PipeLink<OUT_T> link
          The link we drop into.
 
Constructor Summary
protected Producer(ThreadingModel threading, PipeLink<OUT_T> link)
          Constructor.
 
Method Summary
 void execute()
          Checks state, generates an element, and then puts it into the queue.
 PipeLink<OUT_T> getLinkOut()
          Provides the pipeline link out.
protected abstract  boolean isExhausted()
          Determines if the pipeline stage will not produce any more elements.
 boolean isFinished()
          In addition to the basic checks, checks for error conditions.
abstract  OUT_T produceItem()
          Method that must be implemented to queue the producer.
 
Methods inherited from class jconch.pipeline.PipelineStage
getThreadingModel, isStarted, logMessage, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

link

protected final PipeLink<OUT_T> link
The link we drop into.

Constructor Detail

Producer

protected Producer(ThreadingModel threading,
                   PipeLink<OUT_T> link)
Constructor.

Parameters:
threading - The threading model.
link - The link we produce things into.
Throws:
org.apache.commons.lang.NullArgumentException - If either argument is null.
Method Detail

getLinkOut

public PipeLink<OUT_T> getLinkOut()
Provides the pipeline link out.

Returns:
The link that the producer feeds into; never null.

produceItem

public abstract OUT_T produceItem()
Method that must be implemented to queue the producer.

Returns:
The next item for the producer, or null if there are no more elements.

isFinished

public final boolean isFinished()
In addition to the basic checks, checks for error conditions. If the pipeline is not supposed to handle any more elements, either because of an error or because a producer is exhausted.

Specified by:
isFinished in class PipelineStage
Returns:
If the pipeline is done producing/consuming elements.

execute

public final void execute()
Checks state, generates an element, and then puts it into the queue.

Specified by:
execute in class PipelineStage

isExhausted

protected abstract boolean isExhausted()
Determines if the pipeline stage will not produce any more elements. This may be called more than once, and once it returns true, it shall always return true.

Returns:
If the stage is exhausted.