public class AggregateProcessor extends ServiceSupport implements AsyncProcessor, Navigate<Processor>, Traceable, ShutdownPrepared, ShutdownAware, IdAware
AggregationStrategy
(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.Modifier and Type | Field and Description |
---|---|
static String |
AGGREGATE_TIMEOUT_CHECKER |
shutdown, shuttingdown, started, starting, stopped, stopping, suspended, suspending
Constructor and Description |
---|
AggregateProcessor(CamelContext camelContext,
Processor processor,
Expression correlationExpression,
AggregationStrategy aggregationStrategy,
ExecutorService executorService,
boolean shutdownExecutorService) |
Modifier and Type | Method and Description |
---|---|
void |
clearClosedCorrelationKeysCache()
Clear all the closed correlation keys stored in the cache
|
boolean |
deferShutdown(ShutdownRunningTask shutdownRunningTask)
To defer shutdown during first phase of shutdown.
|
protected void |
doAggregationComplete(String complete,
List<Exchange> list,
String key,
Exchange originalExchange,
Exchange answer) |
protected void |
doAggregationRepositoryAdd(CamelContext camelContext,
String key,
Exchange oldExchange,
Exchange newExchange) |
protected void |
doProcess(Exchange exchange) |
protected void |
doShutdown()
Implementations override this method to perform customized shutdown.
|
protected void |
doStart()
Implementations override this method to support customized start/stop.
|
protected void |
doStop()
Implementations override this method to support customized start/stop.
|
int |
forceCompletionOfAllGroups() |
int |
forceCompletionOfGroup(String key) |
AggregateController |
getAggregateController() |
AggregationRepository |
getAggregationRepository() |
AggregationStrategy |
getAggregationStrategy() |
Integer |
getCloseCorrelationKeyOnCompletion() |
int |
getClosedCorrelationKeysCacheSize()
Current number of closed correlation keys in the memory cache
|
long |
getCompletionInterval() |
Predicate |
getCompletionPredicate() |
int |
getCompletionSize() |
Expression |
getCompletionSizeExpression() |
long |
getCompletionTimeout() |
long |
getCompletionTimeoutCheckerInterval() |
Expression |
getCompletionTimeoutExpression() |
Expression |
getCorrelationExpression() |
ExceptionHandler |
getExceptionHandler() |
String |
getId()
Returns the id
|
int |
getInProgressCompleteExchanges() |
OptimisticLockRetryPolicy |
getOptimisticLockRetryPolicy() |
int |
getPendingExchangesSize()
Gets the number of pending exchanges.
|
AggregateProcessorStatistics |
getStatistics() |
ScheduledExecutorService |
getTimeoutCheckerExecutorService() |
String |
getTraceLabel()
Gets the trace label used for logging when tracing is enabled.
|
boolean |
hasNext()
Are there more outputs?
Important only invoke this once, as this method do not carry state, and is not intended to be used in a while loop,
but used by a if statement instead.
|
boolean |
isCompleteAllOnStop() |
protected String |
isCompleted(String key,
Exchange exchange)
Tests whether the given exchange is complete or not
|
boolean |
isCompletionFromBatchConsumer() |
boolean |
isCompletionOnNewCorrelationGroup() |
boolean |
isDiscardOnCompletionTimeout() |
boolean |
isEagerCheckCompletion() |
boolean |
isIgnoreInvalidCorrelationKeys() |
boolean |
isOptimisticLocking() |
boolean |
isParallelProcessing() |
protected String |
isPreCompleted(String key,
Exchange oldExchange,
Exchange newExchange)
Tests whether the given exchanges is pre-complete or not
|
boolean |
isShutdownTimeoutCheckerExecutorService() |
List<Processor> |
next()
Next group of outputs
Important only invoke this once, as this method do not carry state, and is not intended to be used in a while loop,
but used by a if statement instead.
|
protected Exchange |
onAggregation(Exchange oldExchange,
Exchange newExchange) |
protected Exchange |
onCompletion(String key,
Exchange original,
Exchange aggregated,
boolean fromTimeout) |
protected void |
onOptimisticLockingFailure(Exchange oldExchange,
Exchange newExchange) |
protected boolean |
onPreCompletionAggregation(Exchange oldExchange,
Exchange newExchange) |
void |
prepareShutdown(boolean suspendOnly,
boolean forced)
Prepares for stop/shutdown.
|
void |
process(Exchange exchange)
Processes the message exchange
|
boolean |
process(Exchange exchange,
AsyncCallback callback)
Processes the message exchange.
|
protected void |
restoreTimeoutMapFromAggregationRepository()
Restores the timeout map with timeout values from the aggregation repository.
|
void |
setAggregateController(AggregateController aggregateController) |
void |
setAggregationRepository(AggregationRepository aggregationRepository) |
void |
setAggregationStrategy(AggregationStrategy aggregationStrategy) |
void |
setCloseCorrelationKeyOnCompletion(Integer closeCorrelationKeyOnCompletion) |
void |
setCompleteAllOnStop(boolean completeAllOnStop) |
void |
setCompletionFromBatchConsumer(boolean completionFromBatchConsumer) |
void |
setCompletionInterval(long completionInterval) |
void |
setCompletionOnNewCorrelationGroup(boolean completionOnNewCorrelationGroup) |
void |
setCompletionPredicate(Predicate completionPredicate) |
void |
setCompletionSize(int completionSize) |
void |
setCompletionSizeExpression(Expression completionSizeExpression) |
void |
setCompletionTimeout(long completionTimeout) |
void |
setCompletionTimeoutCheckerInterval(long completionTimeoutCheckerInterval) |
void |
setCompletionTimeoutExpression(Expression completionTimeoutExpression) |
void |
setCorrelationExpression(Expression correlationExpression) |
void |
setDiscardOnCompletionTimeout(boolean discardOnCompletionTimeout) |
void |
setEagerCheckCompletion(boolean eagerCheckCompletion) |
void |
setExceptionHandler(ExceptionHandler exceptionHandler) |
void |
setForceCompletionOnStop(boolean forceCompletionOnStop) |
void |
setId(String id)
Sets the id
|
void |
setIgnoreInvalidCorrelationKeys(boolean ignoreInvalidCorrelationKeys) |
void |
setOptimisticLocking(boolean optimisticLocking) |
void |
setOptimisticLockRetryPolicy(OptimisticLockRetryPolicy optimisticLockRetryPolicy) |
void |
setParallelProcessing(boolean parallelProcessing) |
void |
setShutdownTimeoutCheckerExecutorService(boolean shutdownTimeoutCheckerExecutorService) |
void |
setTimeoutCheckerExecutorService(ScheduledExecutorService timeoutCheckerExecutorService) |
String |
toString() |
protected void |
trackTimeout(String key,
Exchange exchange) |
doResume, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
public static final String AGGREGATE_TIMEOUT_CHECKER
public AggregateProcessor(CamelContext camelContext, Processor processor, Expression correlationExpression, AggregationStrategy aggregationStrategy, ExecutorService executorService, boolean shutdownExecutorService)
public String getTraceLabel()
Traceable
getTraceLabel
in interface Traceable
public List<Processor> next()
Navigate
public boolean hasNext()
Navigate
public void process(Exchange exchange) throws Exception
Processor
public boolean process(Exchange exchange, AsyncCallback callback)
AsyncProcessor
Processor.process(org.apache.camel.Exchange)
, but the caller supports having the exchange asynchronously processed.
If there was a failure processing then the caused Exception
would be set on the Exchange
.process
in interface AsyncProcessor
exchange
- the message exchangecallback
- the AsyncCallback
will be invoked when the processing of the exchange is completed.
If the exchange is completed synchronously, then the callback is also invoked synchronously.
The callback should therefore be careful of starting recursive loop.protected void doAggregationComplete(String complete, List<Exchange> list, String key, Exchange originalExchange, Exchange answer)
protected void doAggregationRepositoryAdd(CamelContext camelContext, String key, Exchange oldExchange, Exchange newExchange)
protected void onOptimisticLockingFailure(Exchange oldExchange, Exchange newExchange)
protected String isPreCompleted(String key, Exchange oldExchange, Exchange newExchange)
key
- the correlation keyoldExchange
- the existing exchangenewExchange
- the incoming exchangeprotected String isCompleted(String key, Exchange exchange)
key
- the correlation keyexchange
- the incoming exchangeprotected void trackTimeout(String key, Exchange exchange)
protected Exchange onAggregation(Exchange oldExchange, Exchange newExchange)
protected boolean onPreCompletionAggregation(Exchange oldExchange, Exchange newExchange)
protected Exchange onCompletion(String key, Exchange original, Exchange aggregated, boolean fromTimeout)
protected void restoreTimeoutMapFromAggregationRepository() throws Exception
AggregationRepository
must have their timeout conditions restored.Exception
public int getClosedCorrelationKeysCacheSize()
public void clearClosedCorrelationKeysCache()
public AggregateProcessorStatistics getStatistics()
public int getInProgressCompleteExchanges()
public Predicate getCompletionPredicate()
public void setCompletionPredicate(Predicate completionPredicate)
public boolean isEagerCheckCompletion()
public void setEagerCheckCompletion(boolean eagerCheckCompletion)
public long getCompletionTimeout()
public void setCompletionTimeout(long completionTimeout)
public Expression getCompletionTimeoutExpression()
public void setCompletionTimeoutExpression(Expression completionTimeoutExpression)
public long getCompletionInterval()
public void setCompletionInterval(long completionInterval)
public int getCompletionSize()
public void setCompletionSize(int completionSize)
public Expression getCompletionSizeExpression()
public void setCompletionSizeExpression(Expression completionSizeExpression)
public boolean isIgnoreInvalidCorrelationKeys()
public void setIgnoreInvalidCorrelationKeys(boolean ignoreInvalidCorrelationKeys)
public Integer getCloseCorrelationKeyOnCompletion()
public void setCloseCorrelationKeyOnCompletion(Integer closeCorrelationKeyOnCompletion)
public boolean isCompletionFromBatchConsumer()
public void setCompletionFromBatchConsumer(boolean completionFromBatchConsumer)
public boolean isCompletionOnNewCorrelationGroup()
public void setCompletionOnNewCorrelationGroup(boolean completionOnNewCorrelationGroup)
public boolean isCompleteAllOnStop()
public long getCompletionTimeoutCheckerInterval()
public void setCompletionTimeoutCheckerInterval(long completionTimeoutCheckerInterval)
public ExceptionHandler getExceptionHandler()
public void setExceptionHandler(ExceptionHandler exceptionHandler)
public boolean isParallelProcessing()
public void setParallelProcessing(boolean parallelProcessing)
public boolean isOptimisticLocking()
public void setOptimisticLocking(boolean optimisticLocking)
public AggregationRepository getAggregationRepository()
public void setAggregationRepository(AggregationRepository aggregationRepository)
public boolean isDiscardOnCompletionTimeout()
public void setDiscardOnCompletionTimeout(boolean discardOnCompletionTimeout)
public void setForceCompletionOnStop(boolean forceCompletionOnStop)
public void setCompleteAllOnStop(boolean completeAllOnStop)
public void setTimeoutCheckerExecutorService(ScheduledExecutorService timeoutCheckerExecutorService)
public ScheduledExecutorService getTimeoutCheckerExecutorService()
public boolean isShutdownTimeoutCheckerExecutorService()
public void setShutdownTimeoutCheckerExecutorService(boolean shutdownTimeoutCheckerExecutorService)
public void setOptimisticLockRetryPolicy(OptimisticLockRetryPolicy optimisticLockRetryPolicy)
public OptimisticLockRetryPolicy getOptimisticLockRetryPolicy()
public AggregationStrategy getAggregationStrategy()
public void setAggregationStrategy(AggregationStrategy aggregationStrategy)
public Expression getCorrelationExpression()
public void setCorrelationExpression(Expression correlationExpression)
public AggregateController getAggregateController()
public void setAggregateController(AggregateController aggregateController)
protected void doStart() throws Exception
ServiceSupport
ServiceSupport.doStop()
for more details.doStart
in class ServiceSupport
Exception
ServiceSupport.doStop()
protected void doStop() throws Exception
ServiceSupport
ServiceSupport.doStop()
method when
the service is being stopped. This method will also be invoked
if the service is still in uninitialized state (eg has not
been started). The method is always called to allow the service
to do custom logic when the service is being stopped, such as when
CamelContext
is shutting down.doStop
in class ServiceSupport
Exception
ServiceSupport.doStart()
public void prepareShutdown(boolean suspendOnly, boolean forced)
ShutdownPrepared
ShutdownStrategy
supports preparing for shutdown using two steps.
First a regular preparation, where the given forced parameter will be false.
And if the shutdown times out, then the ShutdownStrategy
performs a more aggressive
shutdown, calling this method a second time with true for the given forced parameter.
For example by graceful stopping any threads or the likes.
In addition a service can also be suspended (not stopped), and when this happens the parameter
suspendOnly has the value true. This can be used to prepare the service
for suspension, such as marking a worker thread to skip action.
For forced shutdown, then the service is expected to aggressively shutdown any child services, such
as thread pools etc. This is the last chance it has to perform such duties.prepareShutdown
in interface ShutdownPrepared
suspendOnly
- true if the intention is to only suspend the service, and not stop/shutdown the service.forced
- true is forcing a more aggressive shutdown, false is for preparing to shutdown.public boolean deferShutdown(ShutdownRunningTask shutdownRunningTask)
ShutdownAware
SedaConsumer
.deferShutdown
in interface ShutdownAware
shutdownRunningTask
- the configured option for how to act when shutting down running tasks.public int getPendingExchangesSize()
ShutdownAware
Exchange
which are pending.
For example the SedaConsumer
.
Return zero to indicate no pending exchanges and therefore ready to shutdown.getPendingExchangesSize
in interface ShutdownAware
protected void doShutdown() throws Exception
ServiceSupport
doShutdown
in class ServiceSupport
Exception
public int forceCompletionOfGroup(String key)
public int forceCompletionOfAllGroups()
Apache Camel