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:
Processor, Service
Direct Known Subclasses:
Aggregator, Resequencer

public class BatchProcessor
extends ServiceSupport
implements Processor

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

Version:
$Revision: 64127 $

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()
           
protected  Collection<Exchange> getCollection()
           
 ExceptionHandler getExceptionHandler()
           
 int getOutBatchSize()
           
 Processor getProcessor()
           
protected  boolean isBatchCompleted(int num)
          A strategy method to decide if the batch is completed the resulting exchanges should be sent
 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 setBatchSize(int batchSize)
          Sets the in batch size.
 void setBatchTimeout(long batchTimeout)
           
 void setExceptionHandler(ExceptionHandler exceptionHandler)
           
 void setOutBatchSize(int outBatchSize)
          Sets the out batch size.
 String toString()
           
 
Methods inherited from class org.apache.camel.impl.ServiceSupport
addChildService, getThreadName, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, nextThreadCounter, 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)

getProcessor

public Processor getProcessor()

isBatchCompleted

protected boolean isBatchCompleted(int num)
A strategy method to decide if the batch is completed the resulting exchanges should be sent


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

getCollection

protected Collection<Exchange> getCollection()

process

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

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


Copyright © 2008 IONA Open Source Community. All Rights Reserved.