public class FlexibleAggregationStrategy<E> extends Object implements AggregationStrategy, CompletionAwareAggregationStrategy, TimeoutAwareAggregationStrategy
AggregationStrategy that is capable of performing the most typical aggregation duties,
with zero Java code.
It can perform the following logic:
Predicate written in any language, such as XPath, OGNL, Simple, Javascript, etc.Collection type, e.g. in a HashSet, LinkedList, ArrayList, etc.| Modifier and Type | Class and Description |
|---|---|
static interface |
FlexibleAggregationStrategy.CompletionAwareMixin |
static interface |
FlexibleAggregationStrategy.TimeoutAwareMixin |
| Constructor and Description |
|---|
FlexibleAggregationStrategy()
|
FlexibleAggregationStrategy(Class<E> type)
Initializes a new instance with the specified type as the
castAs type. |
| Modifier and Type | Method and Description |
|---|---|
FlexibleAggregationStrategy<E> |
accumulateInCollection(Class<? extends Collection> collectionType)
Accumulate the result of the pick expression in a collection of the designated type.
|
Exchange |
aggregate(Exchange oldExchange,
Exchange newExchange)
Aggregates an old and new exchange together to create a single combined exchange
|
FlexibleAggregationStrategy<E> |
castAs(Class<E> castAs)
Cast the result of the pick expression to this type.
|
FlexibleAggregationStrategy<E> |
completionAware(FlexibleAggregationStrategy.CompletionAwareMixin completionMixin)
Plugs in logic to execute when an aggregation batch completes.
|
FlexibleAggregationStrategy<E> |
condition(Predicate predicate)
Set a filter condition such as only results satisfying it will be aggregated.
|
FlexibleAggregationStrategy<E> |
ignoreInvalidCasts()
Ignores invalid casts instead of throwing an exception if the pick expression result cannot be casted to the
specified type.
|
void |
onCompletion(Exchange exchange)
The aggregated
Exchange has completed
Important: This method must not throw any exceptions. |
FlexibleAggregationStrategy<E> |
pick(Expression expression)
Set an expression to extract the element to be aggregated from the incoming
Exchange. |
FlexibleAggregationStrategy<E> |
storeInBody()
Store the result of this Aggregation Strategy (whether an atomic element or a Collection) in the body of the IN message.
|
FlexibleAggregationStrategy<E> |
storeInHeader(String headerName)
Store the result of this Aggregation Strategy (whether an atomic element or a Collection) in an IN message header with
the designated name.
|
FlexibleAggregationStrategy<E> |
storeInProperty(String propertyName)
Store the result of this Aggregation Strategy (whether an atomic element or a Collection) in a property with
the designated name.
|
FlexibleAggregationStrategy<E> |
storeNulls()
Enables storing null values in the resulting collection.
|
void |
timeout(Exchange oldExchange,
int index,
int total,
long timeout)
A timeout occurred.
|
FlexibleAggregationStrategy<E> |
timeoutAware(FlexibleAggregationStrategy.TimeoutAwareMixin timeoutMixin)
Plugs in logic to execute when a timeout occurs.
|
public FlexibleAggregationStrategy()
public FlexibleAggregationStrategy(Class<E> type)
castAs type.type - The castAs type.public FlexibleAggregationStrategy<E> pick(Expression expression)
Exchange.
All results are cast to the castAs type (or the type specified in the constructor).
By default, it picks the full IN message body of the incoming exchange.expression - The picking expression.public FlexibleAggregationStrategy<E> condition(Predicate predicate)
predicate - The condition.public FlexibleAggregationStrategy<E> accumulateInCollection(Class<? extends Collection> collectionType)
storeNulls() option is enabled.collectionType - The type of the Collection to aggregate into.public FlexibleAggregationStrategy<E> storeInProperty(String propertyName)
propertyName - The property name.public FlexibleAggregationStrategy<E> storeInHeader(String headerName)
headerName - The header name.public FlexibleAggregationStrategy<E> storeInBody()
public FlexibleAggregationStrategy<E> castAs(Class<E> castAs)
castAs - Type for the cast.public FlexibleAggregationStrategy<E> storeNulls()
public FlexibleAggregationStrategy<E> ignoreInvalidCasts()
public FlexibleAggregationStrategy<E> timeoutAware(FlexibleAggregationStrategy.TimeoutAwareMixin timeoutMixin)
timeoutMixin - public FlexibleAggregationStrategy<E> completionAware(FlexibleAggregationStrategy.CompletionAwareMixin completionMixin)
completionMixin - public Exchange aggregate(Exchange oldExchange, Exchange newExchange)
AggregationStrategyaggregate in interface AggregationStrategyoldExchange - the oldest exchange (is null on first aggregation as we only have the new exchange)newExchange - the newest exchange (can be null if there was no data possible to acquire)public void timeout(Exchange oldExchange, int index, int total, long timeout)
TimeoutAwareAggregationStrategytimeout in interface TimeoutAwareAggregationStrategyoldExchange - the current aggregated exchange, or the original Exchange if no aggregation
has been done before the timeout occurredindex - the index, may be -1 if not possible to determine the indextotal - the total, may be -1 if not possible to determine the totaltimeout - the timeout value in millis, may be -1 if not possible to determine the timeoutpublic void onCompletion(Exchange exchange)
CompletionAwareAggregationStrategyExchange has completed
Important: This method must not throw any exceptions.onCompletion in interface CompletionAwareAggregationStrategyexchange - the current aggregated exchange, or the original Exchange if no aggregation
has been done before the completion occurredApache Camel