public class AggregateProcessor extends ServiceSupport implements AsyncProcessor, Navigate<Processor>, Traceable, ShutdownPrepared
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 |
---|---|
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() |
AggregationRepository |
getAggregationRepository() |
AggregationStrategy |
getAggregationStrategy() |
Integer |
getCloseCorrelationKeyOnCompletion() |
long |
getCompletionInterval() |
Predicate |
getCompletionPredicate() |
int |
getCompletionSize() |
Expression |
getCompletionSizeExpression() |
long |
getCompletionTimeout() |
Expression |
getCompletionTimeoutExpression() |
Expression |
getCorrelationExpression() |
ExceptionHandler |
getExceptionHandler() |
OptimisticLockRetryPolicy |
getOptimisticLockRetryPolicy() |
ScheduledExecutorService |
getTimeoutCheckerExecutorService() |
String |
getTraceLabel()
Gets the trace label used for logging when tracing is enabled.
|
boolean |
hasNext()
Are there more outputs?
|
protected String |
isCompleted(String key,
Exchange exchange)
Tests whether the given exchange is complete or not
|
boolean |
isCompletionFromBatchConsumer() |
boolean |
isDiscardOnCompletionTimeout() |
boolean |
isEagerCheckCompletion() |
boolean |
isIgnoreInvalidCorrelationKeys() |
boolean |
isOptimisticLocking() |
boolean |
isParallelProcessing() |
boolean |
isShutdownTimeoutCheckerExecutorService() |
List<Processor> |
next()
Next group of outputs
|
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) |
void |
prepareShutdown(boolean forced)
Prepares for 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 |
setAggregationRepository(AggregationRepository aggregationRepository) |
void |
setAggregationStrategy(AggregationStrategy aggregationStrategy) |
void |
setCloseCorrelationKeyOnCompletion(Integer closeCorrelationKeyOnCompletion) |
void |
setCompletionFromBatchConsumer(boolean completionFromBatchConsumer) |
void |
setCompletionInterval(long completionInterval) |
void |
setCompletionPredicate(Predicate completionPredicate) |
void |
setCompletionSize(int completionSize) |
void |
setCompletionSizeExpression(Expression completionSizeExpression) |
void |
setCompletionTimeout(long completionTimeout) |
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 |
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() |
doResume, doSuspend, getStatus, getVersion, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, 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 doAggregationRepositoryAdd(CamelContext camelContext, String key, Exchange oldExchange, Exchange newExchange)
protected void onOptimisticLockingFailure(Exchange oldExchange, Exchange newExchange)
protected String isCompleted(String key, Exchange exchange)
key
- the correlation keyexchange
- the incoming exchangeprotected Exchange onAggregation(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 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 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 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)
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 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.
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
forced
- true is forcing a more aggressive shutdown, false is for preparing to shutdown.protected void doShutdown() throws Exception
ServiceSupport
doShutdown
in class ServiceSupport
Exception
public int forceCompletionOfAllGroups()
Apache Camel