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
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
Modifier and TypeClassDescriptionstatic interface
static interface
-
Constructor Summary
ConstructorDescriptionInitializes a new instance withObject
as thecastAs
type.FlexibleAggregationStrategy
(Class<E> type) Initializes a new instance with the specified type as thecastAs
type. -
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.Exchange
aggregate
(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.void
onCompletion
(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.void
timeout
(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, wait
Methods inherited from interface org.apache.camel.AggregationStrategy
aggregate, canPreComplete, onCompletion, onOptimisticLockFailure, preComplete
-
Constructor Details
-
FlexibleAggregationStrategy
public FlexibleAggregationStrategy()Initializes a new instance withObject
as thecastAs
type. -
FlexibleAggregationStrategy
Initializes a new instance with the specified type as thecastAs
type.- 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 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
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:
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
-