Package org.apache.camel.builder
Class FlexibleAggregationStrategy<E>
java.lang.Object
org.apache.camel.builder.FlexibleAggregationStrategy<E>
- All Implemented Interfaces:
org.apache.camel.AggregationStrategy
public class FlexibleAggregationStrategy<E>
extends Object
implements org.apache.camel.AggregationStrategy
The Flexible Aggregation Strategy is a highly customizable, fluently configurable aggregation strategy. It allows you
to quickly whip up an
AggregationStrategy that is capable of performing the most typical aggregation duties,
with zero Java code.
It can perform the following logic:
- Filtering results based on a defined
Predicatewritten in any language, such as XPath, OGNL, Groovy, Simple, etc. - Picking specific data elements for aggregation.
- Accumulating results in any designated
Collectiontype, e.g. in a HashSet, LinkedList, ArrayList, etc. - Storing the output in a specific place in the Exchange: a property, a header or in the body.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interface -
Constructor Summary
ConstructorsConstructorDescriptionInitializes a new instance withObjectas thecastAstype.FlexibleAggregationStrategy(Class<E> type) Initializes a new instance with the specified type as thecastAstype. -
Method Summary
Modifier and TypeMethodDescriptionaccumulateInCollection(Class<? extends Collection> collectionType) Accumulate the result of the pick expression in a collection of the designated type.org.apache.camel.Exchangeaggregate(org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange) Cast the result of the pick expression to this type.completionAware(FlexibleAggregationStrategy.CompletionAwareMixin completionMixin) Plugs in logic to execute when an aggregation batch completes.condition(org.apache.camel.Predicate predicate) Set a filter condition such as only results satisfying it will be aggregated.Ignores invalid casts instead of throwing an exception if the pick expression result cannot be casted to the specified type.voidonCompletion(org.apache.camel.Exchange exchange) pick(org.apache.camel.Expression expression) Set an expression to extract the element to be aggregated from the incomingExchange.Store the result of this Aggregation Strategy (whether an atomic element or a Collection) in the body of the IN message.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.storeInProperty(String propertyName) Store the result of this Aggregation Strategy (whether an atomic element or a Collection) in a property with the designated name.Enables storing null values in the resulting collection.voidtimeout(org.apache.camel.Exchange oldExchange, int index, int total, long timeout) timeoutAware(FlexibleAggregationStrategy.TimeoutAwareMixin timeoutMixin) Plugs in logic to execute when a timeout occurs.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.camel.AggregationStrategy
aggregate, canPreComplete, onCompletion, onOptimisticLockFailure, preComplete
-
Constructor Details
-
FlexibleAggregationStrategy
public FlexibleAggregationStrategy()Initializes a new instance withObjectas thecastAstype. -
FlexibleAggregationStrategy
Initializes a new instance with the specified type as thecastAstype.- Parameters:
type- The castAs type.
-
-
Method Details
-
pick
Set an expression to extract the element to be aggregated from the incomingExchange. All results are cast to thecastAstype (or the type specified in the constructor). By default, it picks the full IN message body of the incoming exchange.- Parameters:
expression- The picking expression.- Returns:
- This instance.
-
condition
Set a filter condition such as only results satisfying it will be aggregated. By default, all picked values will be processed.- Parameters:
predicate- The condition.- Returns:
- This instance.
-
accumulateInCollection
public FlexibleAggregationStrategy<E> accumulateInCollection(Class<? extends Collection> collectionType) Accumulate the result of the pick expression in a collection of the designated type. No nulls will stored unless thestoreNulls()option is enabled.- Parameters:
collectionType- The type of the Collection to aggregate into.- Returns:
- This instance.
-
storeInProperty
Store the result of this Aggregation Strategy (whether an atomic element or a Collection) in a property with the designated name.- Parameters:
propertyName- The property name.- Returns:
- This instance.
-
storeInHeader
Store the result of this Aggregation Strategy (whether an atomic element or a Collection) in an IN message header with the designated name.- Parameters:
headerName- The header name.- Returns:
- This instance.
-
storeInBody
Store the result of this Aggregation Strategy (whether an atomic element or a Collection) in the body of the IN message.- Returns:
- This instance.
-
castAs
Cast the result of the pick expression to this type.- Parameters:
castAs- Type for the cast.- Returns:
- This instance.
-
storeNulls
Enables storing null values in the resulting collection. By default, this aggregation strategy will drop null values.- Returns:
- This instance.
-
ignoreInvalidCasts
Ignores invalid casts instead of throwing an exception if the pick expression result cannot be casted to the specified type. By default, this aggregation strategy will throw an exception if an invalid cast occurs.- Returns:
- This instance.
-
timeoutAware
public FlexibleAggregationStrategy<E> timeoutAware(FlexibleAggregationStrategy.TimeoutAwareMixin timeoutMixin) Plugs in logic to execute when a timeout occurs.- Parameters:
timeoutMixin- custom logic on timeout- Returns:
- This instance.
-
completionAware
public FlexibleAggregationStrategy<E> completionAware(FlexibleAggregationStrategy.CompletionAwareMixin completionMixin) Plugs in logic to execute when an aggregation batch completes.- Parameters:
completionMixin- custom logic on completion- Returns:
- This instance.
-
aggregate
public org.apache.camel.Exchange aggregate(org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange) - Specified by:
aggregatein interfaceorg.apache.camel.AggregationStrategy
-
timeout
public void timeout(org.apache.camel.Exchange oldExchange, int index, int total, long timeout) - Specified by:
timeoutin interfaceorg.apache.camel.AggregationStrategy
-
onCompletion
public void onCompletion(org.apache.camel.Exchange exchange) - Specified by:
onCompletionin interfaceorg.apache.camel.AggregationStrategy
-