org.apache.camel.processor
Class BatchProcessor

java.lang.Object
  extended by org.apache.camel.impl.ServiceSupport
      extended by org.apache.camel.processor.BatchProcessor
All Implemented Interfaces:
Navigate<Processor>, Processor, Service
Direct Known Subclasses:
Aggregator, Resequencer

public class BatchProcessor
extends ServiceSupport
implements Processor, Navigate<Processor>

A base class for any kind of Processor which implements some kind of batch processing.

Version:
$Revision: 791088 $

Field Summary
static int DEFAULT_BATCH_SIZE
           
static long DEFAULT_BATCH_TIMEOUT
           
 
Constructor Summary
BatchProcessor(Processor processor, Collection<Exchange> collection)
           
 
Method Summary
protected  void doStart()
           
protected  void doStop()
           
 int getBatchSize()
           
 long getBatchTimeout()
           
 ExceptionHandler getExceptionHandler()
           
 int getOutBatchSize()
           
 Processor getProcessor()
           
 boolean hasNext()
          Are there more outputs?
 boolean isBatchConsumer()
           
 boolean isGroupExchanges()
           
 List<Processor> next()
          Next group of outputs
 void process(Exchange exchange)
          Enqueues an exchange for later batch processing.
protected  void processExchange(Exchange exchange)
          Strategy Method to process an exchange in the batch.
 void setBatchConsumer(boolean batchConsumer)
           
 void setBatchSize(int batchSize)
          Sets the in batch size.
 void setBatchTimeout(long batchTimeout)
           
 void setExceptionHandler(ExceptionHandler exceptionHandler)
           
 void setGroupExchanges(boolean groupExchanges)
           
 void setOutBatchSize(int outBatchSize)
          Sets the out batch size.
 String toString()
           
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, removeChildService, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_BATCH_TIMEOUT

public static final long DEFAULT_BATCH_TIMEOUT
See Also:
Constant Field Values

DEFAULT_BATCH_SIZE

public static final int DEFAULT_BATCH_SIZE
See Also:
Constant Field Values
Constructor Detail

BatchProcessor

public BatchProcessor(Processor processor,
                      Collection<Exchange> collection)
Method Detail

toString

public String toString()
Overrides:
toString in class Object

getExceptionHandler

public ExceptionHandler getExceptionHandler()

setExceptionHandler

public void setExceptionHandler(ExceptionHandler exceptionHandler)

getBatchSize

public int getBatchSize()

setBatchSize

public void setBatchSize(int batchSize)
Sets the in batch size. This is the number of incoming exchanges that this batch processor will process before its completed. The default value is DEFAULT_BATCH_SIZE.

Parameters:
batchSize - the size

getOutBatchSize

public int getOutBatchSize()

setOutBatchSize

public void setOutBatchSize(int outBatchSize)
Sets the out batch size. If the batch processor holds more exchanges than this out size then the completion is triggered. Can for instance be used to ensure that this batch is completed when a certain number of exchanges has been collected. By default this feature is not enabled.

Parameters:
outBatchSize - the size

getBatchTimeout

public long getBatchTimeout()

setBatchTimeout

public void setBatchTimeout(long batchTimeout)

isGroupExchanges

public boolean isGroupExchanges()

setGroupExchanges

public void setGroupExchanges(boolean groupExchanges)

isBatchConsumer

public boolean isBatchConsumer()

setBatchConsumer

public void setBatchConsumer(boolean batchConsumer)

getProcessor

public Processor getProcessor()

next

public List<Processor> next()
Description copied from interface: Navigate
Next group of outputs

Specified by:
next in interface Navigate<Processor>
Returns:
next group or null if no more outputs

hasNext

public boolean hasNext()
Description copied from interface: Navigate
Are there more outputs?

Specified by:
hasNext in interface Navigate<Processor>
Returns:
true if more outputs

processExchange

protected void processExchange(Exchange exchange)
                        throws Exception
Strategy Method to process an exchange in the batch. This method allows derived classes to perform custom processing before or after an individual exchange is processed

Throws:
Exception

doStart

protected void doStart()
                throws Exception
Specified by:
doStart in class ServiceSupport
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Specified by:
doStop in class ServiceSupport
Throws:
Exception

process

public void process(Exchange exchange)
             throws Exception
Enqueues an exchange for later batch processing.

Specified by:
process in interface Processor
Parameters:
exchange - the message exchange
Throws:
Exception - if an internal processing error has occurred.


Apache CAMEL