Class AggregateProcessor
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.support.AsyncProcessorSupport
-
- org.apache.camel.processor.aggregate.AggregateProcessor
-
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.AsyncProcessor
,org.apache.camel.Navigate<org.apache.camel.Processor>
,org.apache.camel.Processor
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.spi.HasId
,org.apache.camel.spi.IdAware
,org.apache.camel.spi.RouteIdAware
,org.apache.camel.spi.ShutdownAware
,org.apache.camel.spi.ShutdownPrepared
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
,org.apache.camel.Traceable
public class AggregateProcessor extends org.apache.camel.support.AsyncProcessorSupport implements org.apache.camel.Navigate<org.apache.camel.Processor>, org.apache.camel.Traceable, org.apache.camel.spi.ShutdownPrepared, org.apache.camel.spi.ShutdownAware, org.apache.camel.spi.IdAware, org.apache.camel.spi.RouteIdAware
An implementation of the Aggregator pattern where a batch of messages are processed (up to a maximum amount or until some timeout is reached) and messages for the same correlation key are combined together using some kind ofAggregationStrategy
(by default the latest message is used) to compress many message exchanges into a smaller number of exchanges. A good example of this is stock market data; you may be receiving 30,000 messages/second and you may want to throttle it right down so that multiple messages for the same stock are combined (or just the latest message is used and older prices are discarded). Another idea is to combine line item messages together into a single invoice message.
-
-
Field Summary
Fields Modifier and Type Field Description static String
AGGREGATE_OPTIMISTIC_LOCKING_EXECUTOR
static String
AGGREGATE_TIMEOUT_CHECKER
static String
COMPLETED_BY_CONSUMER
static String
COMPLETED_BY_FORCE
static String
COMPLETED_BY_INTERVAL
static String
COMPLETED_BY_PREDICATE
static String
COMPLETED_BY_SIZE
static String
COMPLETED_BY_STRATEGY
static String
COMPLETED_BY_TIMEOUT
-
Constructor Summary
Constructors Constructor Description AggregateProcessor(org.apache.camel.CamelContext camelContext, org.apache.camel.AsyncProcessor processor, org.apache.camel.Expression correlationExpression, org.apache.camel.AggregationStrategy aggregationStrategy, ExecutorService executorService, boolean shutdownExecutorService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearClosedCorrelationKeysCache()
Clear all the closed correlation keys stored in the cacheboolean
deferShutdown(org.apache.camel.ShutdownRunningTask shutdownRunningTask)
protected void
doAggregationComplete(String complete, List<org.apache.camel.Exchange> list, String key, org.apache.camel.Exchange originalExchange, org.apache.camel.Exchange answer, boolean aggregateFailed)
protected void
doAggregationRepositoryAdd(org.apache.camel.CamelContext camelContext, String key, org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange)
protected boolean
doInOptimisticLock(org.apache.camel.Exchange exchange, String key, org.apache.camel.AsyncCallback callback, int attempt, boolean sync)
protected boolean
doProcess(org.apache.camel.Exchange exchange, String key, org.apache.camel.AsyncCallback callback, boolean sync)
protected boolean
doProcess(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback)
protected void
doShutdown()
protected void
doStart()
protected void
doStop()
int
forceCompletionOfAllGroups()
int
forceCompletionOfGroup(String key)
int
forceDiscardingOfAllGroups()
int
forceDiscardingOfGroup(String key)
AggregateController
getAggregateController()
org.apache.camel.spi.AggregationRepository
getAggregationRepository()
org.apache.camel.AggregationStrategy
getAggregationStrategy()
Integer
getCloseCorrelationKeyOnCompletion()
int
getClosedCorrelationKeysCacheSize()
Current number of closed correlation keys in the memory cachelong
getCompletionInterval()
org.apache.camel.Predicate
getCompletionPredicate()
int
getCompletionSize()
org.apache.camel.Expression
getCompletionSizeExpression()
long
getCompletionTimeout()
long
getCompletionTimeoutCheckerInterval()
org.apache.camel.Expression
getCompletionTimeoutExpression()
org.apache.camel.Expression
getCorrelationExpression()
org.apache.camel.spi.ExceptionHandler
getExceptionHandler()
String
getId()
int
getInProgressCompleteExchanges()
ScheduledExecutorService
getOptimisticLockingExecutorService()
OptimisticLockRetryPolicy
getOptimisticLockRetryPolicy()
int
getPendingExchangesSize()
String
getRouteId()
AggregateProcessorStatistics
getStatistics()
ScheduledExecutorService
getTimeoutCheckerExecutorService()
String
getTraceLabel()
boolean
hasNext()
boolean
isCompleteAllOnStop()
protected String
isCompleted(String key, org.apache.camel.Exchange exchange)
Tests whether the given exchange is complete or notboolean
isCompletionFromBatchConsumer()
boolean
isCompletionOnNewCorrelationGroup()
boolean
isDiscardOnAggregationFailure()
boolean
isDiscardOnCompletionTimeout()
boolean
isEagerCheckCompletion()
boolean
isIgnoreInvalidCorrelationKeys()
boolean
isOptimisticLocking()
boolean
isParallelProcessing()
protected String
isPreCompleted(String key, org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange)
Tests whether the given exchanges is pre-complete or notboolean
isShutdownOptimisticLockingExecutorService()
boolean
isShutdownTimeoutCheckerExecutorService()
List<org.apache.camel.Processor>
next()
protected org.apache.camel.Exchange
onAggregation(org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange)
protected org.apache.camel.Exchange
onCompletion(String key, org.apache.camel.Exchange original, org.apache.camel.Exchange aggregated, boolean fromTimeout, boolean aggregateFailed)
protected void
onOptimisticLockingFailure(org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange)
void
prepareShutdown(boolean suspendOnly, boolean forced)
boolean
process(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback)
protected void
restoreTimeoutMapFromAggregationRepository()
Restores the timeout map with timeout values from the aggregation repository.void
setAggregateController(AggregateController aggregateController)
void
setAggregationRepository(org.apache.camel.spi.AggregationRepository aggregationRepository)
void
setAggregationStrategy(org.apache.camel.AggregationStrategy aggregationStrategy)
void
setCloseCorrelationKeyOnCompletion(Integer closeCorrelationKeyOnCompletion)
void
setCompleteAllOnStop(boolean completeAllOnStop)
void
setCompletionFromBatchConsumer(boolean completionFromBatchConsumer)
void
setCompletionInterval(long completionInterval)
void
setCompletionOnNewCorrelationGroup(boolean completionOnNewCorrelationGroup)
void
setCompletionPredicate(org.apache.camel.Predicate completionPredicate)
void
setCompletionSize(int completionSize)
void
setCompletionSizeExpression(org.apache.camel.Expression completionSizeExpression)
void
setCompletionTimeout(long completionTimeout)
void
setCompletionTimeoutCheckerInterval(long completionTimeoutCheckerInterval)
void
setCompletionTimeoutExpression(org.apache.camel.Expression completionTimeoutExpression)
void
setCorrelationExpression(org.apache.camel.Expression correlationExpression)
void
setDiscardOnAggregationFailure(boolean discardOnAggregationFailure)
void
setDiscardOnCompletionTimeout(boolean discardOnCompletionTimeout)
void
setEagerCheckCompletion(boolean eagerCheckCompletion)
void
setExceptionHandler(org.apache.camel.spi.ExceptionHandler exceptionHandler)
void
setForceCompletionOnStop(boolean forceCompletionOnStop)
void
setId(String id)
void
setIgnoreInvalidCorrelationKeys(boolean ignoreInvalidCorrelationKeys)
void
setOptimisticLocking(boolean optimisticLocking)
void
setOptimisticLockingExecutorService(ScheduledExecutorService optimisticLockingExecutorService)
void
setOptimisticLockRetryPolicy(OptimisticLockRetryPolicy optimisticLockRetryPolicy)
void
setParallelProcessing(boolean parallelProcessing)
void
setRouteId(String routeId)
void
setShutdownOptimisticLockingExecutorService(boolean shutdownOptimisticLockingExecutorService)
void
setShutdownTimeoutCheckerExecutorService(boolean shutdownTimeoutCheckerExecutorService)
void
setTimeoutCheckerExecutorService(ScheduledExecutorService timeoutCheckerExecutorService)
String
toString()
protected void
trackTimeout(String key, org.apache.camel.Exchange exchange)
-
Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doInit, doLifecycleChange, doResume, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
AGGREGATE_TIMEOUT_CHECKER
public static final String AGGREGATE_TIMEOUT_CHECKER
- See Also:
- Constant Field Values
-
AGGREGATE_OPTIMISTIC_LOCKING_EXECUTOR
public static final String AGGREGATE_OPTIMISTIC_LOCKING_EXECUTOR
- See Also:
- Constant Field Values
-
COMPLETED_BY_SIZE
public static final String COMPLETED_BY_SIZE
- See Also:
- Constant Field Values
-
COMPLETED_BY_PREDICATE
public static final String COMPLETED_BY_PREDICATE
- See Also:
- Constant Field Values
-
COMPLETED_BY_CONSUMER
public static final String COMPLETED_BY_CONSUMER
- See Also:
- Constant Field Values
-
COMPLETED_BY_STRATEGY
public static final String COMPLETED_BY_STRATEGY
- See Also:
- Constant Field Values
-
COMPLETED_BY_INTERVAL
public static final String COMPLETED_BY_INTERVAL
- See Also:
- Constant Field Values
-
COMPLETED_BY_TIMEOUT
public static final String COMPLETED_BY_TIMEOUT
- See Also:
- Constant Field Values
-
COMPLETED_BY_FORCE
public static final String COMPLETED_BY_FORCE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AggregateProcessor
public AggregateProcessor(org.apache.camel.CamelContext camelContext, org.apache.camel.AsyncProcessor processor, org.apache.camel.Expression correlationExpression, org.apache.camel.AggregationStrategy aggregationStrategy, ExecutorService executorService, boolean shutdownExecutorService)
-
-
Method Detail
-
getTraceLabel
public String getTraceLabel()
- Specified by:
getTraceLabel
in interfaceorg.apache.camel.Traceable
-
next
public List<org.apache.camel.Processor> next()
- Specified by:
next
in interfaceorg.apache.camel.Navigate<org.apache.camel.Processor>
-
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interfaceorg.apache.camel.Navigate<org.apache.camel.Processor>
-
getId
public String getId()
- Specified by:
getId
in interfaceorg.apache.camel.spi.HasId
-
setId
public void setId(String id)
- Specified by:
setId
in interfaceorg.apache.camel.spi.IdAware
-
getRouteId
public String getRouteId()
- Specified by:
getRouteId
in interfaceorg.apache.camel.spi.RouteIdAware
-
setRouteId
public void setRouteId(String routeId)
- Specified by:
setRouteId
in interfaceorg.apache.camel.spi.RouteIdAware
-
process
public boolean process(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback)
- Specified by:
process
in interfaceorg.apache.camel.AsyncProcessor
-
doProcess
protected boolean doProcess(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback) throws Exception
- Throws:
Exception
-
doInOptimisticLock
protected boolean doInOptimisticLock(org.apache.camel.Exchange exchange, String key, org.apache.camel.AsyncCallback callback, int attempt, boolean sync)
-
doProcess
protected boolean doProcess(org.apache.camel.Exchange exchange, String key, org.apache.camel.AsyncCallback callback, boolean sync)
-
doAggregationComplete
protected void doAggregationComplete(String complete, List<org.apache.camel.Exchange> list, String key, org.apache.camel.Exchange originalExchange, org.apache.camel.Exchange answer, boolean aggregateFailed)
-
doAggregationRepositoryAdd
protected void doAggregationRepositoryAdd(org.apache.camel.CamelContext camelContext, String key, org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange)
-
onOptimisticLockingFailure
protected void onOptimisticLockingFailure(org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange)
-
isPreCompleted
protected String isPreCompleted(String key, org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange)
Tests whether the given exchanges is pre-complete or not- Parameters:
key
- the correlation keyoldExchange
- the existing exchangenewExchange
- the incoming exchange- Returns:
- null if not pre-completed, otherwise a String with the type that triggered the pre-completion
-
isCompleted
protected String isCompleted(String key, org.apache.camel.Exchange exchange)
Tests whether the given exchange is complete or not- Parameters:
key
- the correlation keyexchange
- the incoming exchange- Returns:
- null if not completed, otherwise a String with the type that triggered the completion
-
trackTimeout
protected void trackTimeout(String key, org.apache.camel.Exchange exchange)
-
onAggregation
protected org.apache.camel.Exchange onAggregation(org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange)
-
onCompletion
protected org.apache.camel.Exchange onCompletion(String key, org.apache.camel.Exchange original, org.apache.camel.Exchange aggregated, boolean fromTimeout, boolean aggregateFailed)
-
restoreTimeoutMapFromAggregationRepository
protected void restoreTimeoutMapFromAggregationRepository() throws Exception
Restores the timeout map with timeout values from the aggregation repository. This is needed in case the aggregator has been stopped and started again (for example a server restart). Then the existing exchanges from theAggregationRepository
must have their timeout conditions restored.- Throws:
Exception
-
getClosedCorrelationKeysCacheSize
public int getClosedCorrelationKeysCacheSize()
Current number of closed correlation keys in the memory cache
-
clearClosedCorrelationKeysCache
public void clearClosedCorrelationKeysCache()
Clear all the closed correlation keys stored in the cache
-
getStatistics
public AggregateProcessorStatistics getStatistics()
-
getInProgressCompleteExchanges
public int getInProgressCompleteExchanges()
-
getCompletionPredicate
public org.apache.camel.Predicate getCompletionPredicate()
-
setCompletionPredicate
public void setCompletionPredicate(org.apache.camel.Predicate completionPredicate)
-
isEagerCheckCompletion
public boolean isEagerCheckCompletion()
-
setEagerCheckCompletion
public void setEagerCheckCompletion(boolean eagerCheckCompletion)
-
getCompletionTimeout
public long getCompletionTimeout()
-
setCompletionTimeout
public void setCompletionTimeout(long completionTimeout)
-
getCompletionTimeoutExpression
public org.apache.camel.Expression getCompletionTimeoutExpression()
-
setCompletionTimeoutExpression
public void setCompletionTimeoutExpression(org.apache.camel.Expression completionTimeoutExpression)
-
getCompletionInterval
public long getCompletionInterval()
-
setCompletionInterval
public void setCompletionInterval(long completionInterval)
-
getCompletionSize
public int getCompletionSize()
-
setCompletionSize
public void setCompletionSize(int completionSize)
-
getCompletionSizeExpression
public org.apache.camel.Expression getCompletionSizeExpression()
-
setCompletionSizeExpression
public void setCompletionSizeExpression(org.apache.camel.Expression completionSizeExpression)
-
isIgnoreInvalidCorrelationKeys
public boolean isIgnoreInvalidCorrelationKeys()
-
setIgnoreInvalidCorrelationKeys
public void setIgnoreInvalidCorrelationKeys(boolean ignoreInvalidCorrelationKeys)
-
getCloseCorrelationKeyOnCompletion
public Integer getCloseCorrelationKeyOnCompletion()
-
setCloseCorrelationKeyOnCompletion
public void setCloseCorrelationKeyOnCompletion(Integer closeCorrelationKeyOnCompletion)
-
isCompletionFromBatchConsumer
public boolean isCompletionFromBatchConsumer()
-
setCompletionFromBatchConsumer
public void setCompletionFromBatchConsumer(boolean completionFromBatchConsumer)
-
isCompletionOnNewCorrelationGroup
public boolean isCompletionOnNewCorrelationGroup()
-
setCompletionOnNewCorrelationGroup
public void setCompletionOnNewCorrelationGroup(boolean completionOnNewCorrelationGroup)
-
isCompleteAllOnStop
public boolean isCompleteAllOnStop()
-
getCompletionTimeoutCheckerInterval
public long getCompletionTimeoutCheckerInterval()
-
setCompletionTimeoutCheckerInterval
public void setCompletionTimeoutCheckerInterval(long completionTimeoutCheckerInterval)
-
getExceptionHandler
public org.apache.camel.spi.ExceptionHandler getExceptionHandler()
-
setExceptionHandler
public void setExceptionHandler(org.apache.camel.spi.ExceptionHandler exceptionHandler)
-
isParallelProcessing
public boolean isParallelProcessing()
-
setParallelProcessing
public void setParallelProcessing(boolean parallelProcessing)
-
isOptimisticLocking
public boolean isOptimisticLocking()
-
setOptimisticLocking
public void setOptimisticLocking(boolean optimisticLocking)
-
getAggregationRepository
public org.apache.camel.spi.AggregationRepository getAggregationRepository()
-
setAggregationRepository
public void setAggregationRepository(org.apache.camel.spi.AggregationRepository aggregationRepository)
-
isDiscardOnCompletionTimeout
public boolean isDiscardOnCompletionTimeout()
-
setDiscardOnCompletionTimeout
public void setDiscardOnCompletionTimeout(boolean discardOnCompletionTimeout)
-
isDiscardOnAggregationFailure
public boolean isDiscardOnAggregationFailure()
-
setDiscardOnAggregationFailure
public void setDiscardOnAggregationFailure(boolean discardOnAggregationFailure)
-
setForceCompletionOnStop
public void setForceCompletionOnStop(boolean forceCompletionOnStop)
-
setCompleteAllOnStop
public void setCompleteAllOnStop(boolean completeAllOnStop)
-
setTimeoutCheckerExecutorService
public void setTimeoutCheckerExecutorService(ScheduledExecutorService timeoutCheckerExecutorService)
-
getTimeoutCheckerExecutorService
public ScheduledExecutorService getTimeoutCheckerExecutorService()
-
isShutdownTimeoutCheckerExecutorService
public boolean isShutdownTimeoutCheckerExecutorService()
-
setShutdownTimeoutCheckerExecutorService
public void setShutdownTimeoutCheckerExecutorService(boolean shutdownTimeoutCheckerExecutorService)
-
setOptimisticLockingExecutorService
public void setOptimisticLockingExecutorService(ScheduledExecutorService optimisticLockingExecutorService)
-
getOptimisticLockingExecutorService
public ScheduledExecutorService getOptimisticLockingExecutorService()
-
isShutdownOptimisticLockingExecutorService
public boolean isShutdownOptimisticLockingExecutorService()
-
setShutdownOptimisticLockingExecutorService
public void setShutdownOptimisticLockingExecutorService(boolean shutdownOptimisticLockingExecutorService)
-
setOptimisticLockRetryPolicy
public void setOptimisticLockRetryPolicy(OptimisticLockRetryPolicy optimisticLockRetryPolicy)
-
getOptimisticLockRetryPolicy
public OptimisticLockRetryPolicy getOptimisticLockRetryPolicy()
-
getAggregationStrategy
public org.apache.camel.AggregationStrategy getAggregationStrategy()
-
setAggregationStrategy
public void setAggregationStrategy(org.apache.camel.AggregationStrategy aggregationStrategy)
-
getCorrelationExpression
public org.apache.camel.Expression getCorrelationExpression()
-
setCorrelationExpression
public void setCorrelationExpression(org.apache.camel.Expression correlationExpression)
-
getAggregateController
public AggregateController getAggregateController()
-
setAggregateController
public void setAggregateController(AggregateController aggregateController)
-
doStart
protected void doStart() throws Exception
- Overrides:
doStart
in classorg.apache.camel.support.AsyncProcessorSupport
- Throws:
Exception
-
doStop
protected void doStop() throws Exception
- Overrides:
doStop
in classorg.apache.camel.support.AsyncProcessorSupport
- Throws:
Exception
-
prepareShutdown
public void prepareShutdown(boolean suspendOnly, boolean forced)
- Specified by:
prepareShutdown
in interfaceorg.apache.camel.spi.ShutdownPrepared
-
deferShutdown
public boolean deferShutdown(org.apache.camel.ShutdownRunningTask shutdownRunningTask)
- Specified by:
deferShutdown
in interfaceorg.apache.camel.spi.ShutdownAware
-
getPendingExchangesSize
public int getPendingExchangesSize()
- Specified by:
getPendingExchangesSize
in interfaceorg.apache.camel.spi.ShutdownAware
-
doShutdown
protected void doShutdown() throws Exception
- Overrides:
doShutdown
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
forceCompletionOfGroup
public int forceCompletionOfGroup(String key)
-
forceCompletionOfAllGroups
public int forceCompletionOfAllGroups()
-
forceDiscardingOfGroup
public int forceDiscardingOfGroup(String key)
-
forceDiscardingOfAllGroups
public int forceDiscardingOfAllGroups()
-
-