org.jcreme.processing
Class AbstractProducer

java.lang.Object
  extended byorg.jcreme.processing.AbstractProducer
All Implemented Interfaces:
Producer
Direct Known Subclasses:
BaseProducer, FileReaderProducer, FilesReaderProducer, MultiplexedProducer

public abstract class AbstractProducer
extends java.lang.Object
implements Producer

This class takes care of the basic production mechanisms. It is valid for any Producer since it does nor introduce any dependency on a Consumer. Producers should basically derive from this class although this is by no a necessity.

Version:
$Revision: 1.2 $
Author:
$Author: dbregeon $

Constructor Summary
AbstractProducer(int initialProductionQueueSize, int initialValidationQueueSize)
          Creates new AbstractProducer
 
Method Summary
protected  java.util.Collection getItemsBeingConsumed()
          Returns the Collection of the items that are being consumed.
 java.util.Collection getProducedItems()
          Returns the Collection of the items that are available for consumption.
 boolean isProductionOver()
          Returns true if the production is over, false if not.
 java.lang.Object nextItem()
          Returns the next item free for consumption.
 java.lang.Object nextItem(int timeout)
          Returns the next item free for consumption.
abstract  boolean produceItem()
          Produces next item, i.e. marks it as consumable.
protected  void publishItem(java.lang.Object theItem)
          This method enables to put a newly produced item in the production queue.
 void setProductionOver(boolean bool)
          Sets a flag that shows whether the production is over.
 boolean validateItem(java.lang.Object theItem)
          Validates an item, i.e. marks it as having been consumed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractProducer

public AbstractProducer(int initialProductionQueueSize,
                        int initialValidationQueueSize)
Creates new AbstractProducer

Parameters:
initialProductionQueueSize - the size of the production queue when it is initialized.
initialValidationQueueSize - the size of the validation queue when it is initialized.
Method Detail

nextItem

public java.lang.Object nextItem()
Returns the next item free for consumption. If no item is available, the call blocks until one is available.

Specified by:
nextItem in interface Producer
Returns:
The next item free for consumption.
See Also:
Producer.nextItem()

nextItem

public java.lang.Object nextItem(int timeout)
Returns the next item free for consumption. If no item is available, the call blocks until the timeout expires or an object is available.

Parameters:
timeout - the number of milliseconds the call will wait for an available item.
Returns:
The next item free for consumption.
See Also:
Producer.nextItem()

validateItem

public boolean validateItem(java.lang.Object theItem)
Validates an item, i.e. marks it as having been consumed. After a successfull call to this method, the item should be removed from the memory of the Producer. An unsuccessfull call to this method may call for a redo action.

Specified by:
validateItem in interface Producer
Parameters:
theItem - The item to be validated.
Returns:
true is validation was successful.
See Also:
Producer.validateItem(java.lang.Object)

publishItem

protected void publishItem(java.lang.Object theItem)
This method enables to put a newly produced item in the production queue. After a call to this method, it can be consumed by any consumer that uses this producer.

Parameters:
theItem - the item to make available for consumption.

setProductionOver

public void setProductionOver(boolean bool)
Sets a flag that shows whether the production is over.

Specified by:
setProductionOver in interface Producer
Parameters:
bool - The boolean value that the flag has to be set on.
See Also:
Producer.setProductionOver(boolean)

isProductionOver

public boolean isProductionOver()
Returns true if the production is over, false if not.

Specified by:
isProductionOver in interface Producer
Returns:
True if the production is over, false if not.
See Also:
Producer.isProductionOver()

produceItem

public abstract boolean produceItem()
Produces next item, i.e. marks it as consumable. This method does the actual "Production" work.

Specified by:
produceItem in interface Producer
Returns:
True if there are still objects to produce, false otherwise.

getItemsBeingConsumed

protected java.util.Collection getItemsBeingConsumed()
Returns the Collection of the items that are being consumed.

Returns:
The Collection of the items that are being consumed.

getProducedItems

public java.util.Collection getProducedItems()
Returns the Collection of the items that are available for consumption.

Returns:
The Collection of the items that are available for consumption.


Copyright 2006 null. All Rights Reserved.