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 anAggregationStrategy
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
Predicate
written in any language, such as XPath, OGNL, Groovy, Simple, etc. - Picking specific data elements for aggregation.
- Accumulating results in any designated
Collection
type, 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 Classes Modifier and Type Class Description static interface
FlexibleAggregationStrategy.CompletionAwareMixin
static interface
FlexibleAggregationStrategy.TimeoutAwareMixin
-
Constructor Summary
Constructors Constructor Description FlexibleAggregationStrategy()
FlexibleAggregationStrategy(Class<E> type)
Initializes a new instance with the specified type as thecastAs
type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description FlexibleAggregationStrategy<E>
accumulateInCollection(Class<? extends Collection> collectionType)
Accumulate the result of the pick expression in a collection of the designated type.org.apache.camel.Exchange
aggregate(org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange)
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(org.apache.camel.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(org.apache.camel.Exchange exchange)
FlexibleAggregationStrategy<E>
pick(org.apache.camel.Expression expression)
Set an expression to extract the element to be aggregated from the incomingExchange
.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(org.apache.camel.Exchange oldExchange, int index, int total, long timeout)
FlexibleAggregationStrategy<E>
timeoutAware(FlexibleAggregationStrategy.TimeoutAwareMixin timeoutMixin)
Plugs in logic to execute when a timeout occurs.
-
-
-
Method Detail
-
pick
public FlexibleAggregationStrategy<E> pick(org.apache.camel.Expression expression)
Set an expression to extract the element to be aggregated from the incomingExchange
. All results are cast to thecastAs
type (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
public FlexibleAggregationStrategy<E> condition(org.apache.camel.Predicate predicate)
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
public 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.- Parameters:
propertyName
- The property name.- Returns:
- This instance.
-
storeInHeader
public 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.- Parameters:
headerName
- The header name.- Returns:
- This instance.
-
storeInBody
public FlexibleAggregationStrategy<E> 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
public FlexibleAggregationStrategy<E> castAs(Class<E> castAs)
Cast the result of the pick expression to this type.- Parameters:
castAs
- Type for the cast.- Returns:
- This instance.
-
storeNulls
public FlexibleAggregationStrategy<E> storeNulls()
Enables storing null values in the resulting collection. By default, this aggregation strategy will drop null values.- Returns:
- This instance.
-
ignoreInvalidCasts
public FlexibleAggregationStrategy<E> 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
-- Returns:
- This instance.
-
completionAware
public FlexibleAggregationStrategy<E> completionAware(FlexibleAggregationStrategy.CompletionAwareMixin completionMixin)
Plugs in logic to execute when an aggregation batch completes.- Parameters:
completionMixin
-- Returns:
- This instance.
-
aggregate
public org.apache.camel.Exchange aggregate(org.apache.camel.Exchange oldExchange, org.apache.camel.Exchange newExchange)
- Specified by:
aggregate
in interfaceorg.apache.camel.AggregationStrategy
-
timeout
public void timeout(org.apache.camel.Exchange oldExchange, int index, int total, long timeout)
- Specified by:
timeout
in interfaceorg.apache.camel.AggregationStrategy
-
onCompletion
public void onCompletion(org.apache.camel.Exchange exchange)
- Specified by:
onCompletion
in interfaceorg.apache.camel.AggregationStrategy
-
-