Search in sources :

Example 1 with AggregationStrategyBeanAdapter

use of org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter in project camel by apache.

the class AggregationStrategies method beanAllowNull.

/**
     * Creates a {@link AggregationStrategyBeanAdapter} for using a POJO as the aggregation strategy.
     */
public static AggregationStrategy beanAllowNull(Class<?> type, String methodName) {
    AggregationStrategyBeanAdapter adapter = new AggregationStrategyBeanAdapter(type, methodName);
    adapter.setAllowNullOldExchange(true);
    adapter.setAllowNullNewExchange(true);
    return adapter;
}
Also used : AggregationStrategyBeanAdapter(org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter)

Example 2 with AggregationStrategyBeanAdapter

use of org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter in project camel by apache.

the class AggregateDefinition method createAggregationStrategy.

private AggregationStrategy createAggregationStrategy(RouteContext routeContext) {
    AggregationStrategy strategy = getAggregationStrategy();
    if (strategy == null && strategyRef != null) {
        Object aggStrategy = routeContext.lookup(strategyRef, Object.class);
        if (aggStrategy instanceof AggregationStrategy) {
            strategy = (AggregationStrategy) aggStrategy;
        } else if (aggStrategy != null) {
            AggregationStrategyBeanAdapter adapter = new AggregationStrategyBeanAdapter(aggStrategy, getAggregationStrategyMethodName());
            if (getStrategyMethodAllowNull() != null) {
                adapter.setAllowNullNewExchange(getStrategyMethodAllowNull());
                adapter.setAllowNullOldExchange(getStrategyMethodAllowNull());
            }
            strategy = adapter;
        } else {
            throw new IllegalArgumentException("Cannot find AggregationStrategy in Registry with name: " + strategyRef);
        }
    }
    if (groupExchanges != null && groupExchanges) {
        if (strategy != null || strategyRef != null) {
            throw new IllegalArgumentException("Options groupExchanges and AggregationStrategy cannot be enabled at the same time");
        }
        if (eagerCheckCompletion != null && !eagerCheckCompletion) {
            throw new IllegalArgumentException("Option eagerCheckCompletion cannot be false when groupExchanges has been enabled");
        }
        // set eager check to enabled by default when using grouped exchanges
        setEagerCheckCompletion(true);
        // if grouped exchange is enabled then use special strategy for that
        strategy = new GroupedExchangeAggregationStrategy();
    }
    if (strategy == null) {
        throw new IllegalArgumentException("AggregationStrategy or AggregationStrategyRef must be set on " + this);
    }
    if (strategy instanceof CamelContextAware) {
        ((CamelContextAware) strategy).setCamelContext(routeContext.getCamelContext());
    }
    return strategy;
}
Also used : CamelContextAware(org.apache.camel.CamelContextAware) GroupedExchangeAggregationStrategy(org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy) GroupedExchangeAggregationStrategy(org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy) AggregationStrategy(org.apache.camel.processor.aggregate.AggregationStrategy) AggregationStrategyBeanAdapter(org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter)

Example 3 with AggregationStrategyBeanAdapter

use of org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter in project camel by apache.

the class AggregationStrategies method beanAllowNull.

/**
     * Creates a {@link AggregationStrategyBeanAdapter} for using a POJO as the aggregation strategy.
     */
public static AggregationStrategy beanAllowNull(Object bean, String methodName) {
    AggregationStrategyBeanAdapter adapter = new AggregationStrategyBeanAdapter(bean, methodName);
    adapter.setAllowNullOldExchange(true);
    adapter.setAllowNullNewExchange(true);
    return adapter;
}
Also used : AggregationStrategyBeanAdapter(org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter)

Example 4 with AggregationStrategyBeanAdapter

use of org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter in project camel by apache.

the class AggregationStrategyBeanAdapterAllowNullOldExchangeTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            myStrategy = new AggregationStrategyBeanAdapter(appender, "append");
            myStrategy.setAllowNullOldExchange(true);
            from("direct:start").aggregate(constant(true), myStrategy).completionSize(3).to("mock:result");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) AggregationStrategyBeanAdapter(org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter)

Example 5 with AggregationStrategyBeanAdapter

use of org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter in project camel by apache.

the class AggregationStrategyBeanAdapterPollEnrichAllowNullNewExchangeTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            myStrategy = new AggregationStrategyBeanAdapter(appender, "append");
            myStrategy.setAllowNullNewExchange(true);
            from("direct:start").pollEnrich("seda:foo", 10, myStrategy).to("mock:result");
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) AggregationStrategyBeanAdapter(org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter)

Aggregations

AggregationStrategyBeanAdapter (org.apache.camel.processor.aggregate.AggregationStrategyBeanAdapter)5 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 CamelContextAware (org.apache.camel.CamelContextAware)1 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)1 GroupedExchangeAggregationStrategy (org.apache.camel.processor.aggregate.GroupedExchangeAggregationStrategy)1