Search in sources :

Example 1 with TimeoutAwareMixin

use of org.apache.camel.util.toolbox.FlexibleAggregationStrategy.TimeoutAwareMixin in project camel by apache.

the class FlexibleAggregationStrategiesTest method createRouteBuilder.

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

        @Override
        public void configure() throws Exception {
            from("direct:start1").aggregate(AggregationStrategies.flexible(String.class).accumulateInCollection(ArrayList.class).pick(simple("${body}")).condition(simple("${body} contains 'AGGREGATE'"))).header("id").completionSize(5).to("mock:result1");
            from("direct:start2").aggregate(AggregationStrategies.flexible(String.class).accumulateInCollection(HashSet.class).pick(simple("${header.input}")).condition(simple("${header.input} contains 'AGGREGATE'")).storeInProperty("AggregationResult")).constant(true).completionSize(5).to("mock:result2");
            from("direct:start3").aggregate(AggregationStrategies.flexible(String.class).storeInHeader("AggregationResult")).constant(true).completionSize(3).to("mock:result3");
            from("direct:start4").aggregate(AggregationStrategies.flexible().accumulateInCollection(ArrayList.class)).constant(true).completionSize(3).to("mock:result4");
            from("direct:start5").aggregate(AggregationStrategies.flexible(Integer.class).accumulateInCollection(ArrayList.class)).constant(true).completionSize(3).to("mock:result5");
            from("direct:start6").aggregate(AggregationStrategies.flexible(Integer.class).ignoreInvalidCasts().storeNulls().accumulateInCollection(ArrayList.class)).constant(true).completionSize(3).to("mock:result6");
            AggregationStrategy timeoutCompletionStrategy = AggregationStrategies.flexible(String.class).condition(simple("${body} contains 'AGGREGATE'")).timeoutAware(new TimeoutAwareMixin() {

                @Override
                public void timeout(Exchange exchange, int index, int total, long timeout) {
                    exchange.setProperty("Timeout", true);
                    timeoutLatch.countDown();
                }
            }).completionAware(new CompletionAwareMixin() {

                @Override
                public void onCompletion(Exchange exchange) {
                    completionLatch.countDown();
                }
            });
            from("direct:start.timeoutAndCompletionAware").aggregate(timeoutCompletionStrategy).constant(true).completionTimeout(500).completionSize(2).to("mock:result.timeoutAndCompletionAware");
            from("direct:start.xpath1").aggregate(AggregationStrategies.flexible(Node.class).pick(xpath("//result[1]").nodeResult()).accumulateInCollection(ArrayList.class)).constant(true).completionSize(3).to("mock:result.xpath1");
            from("direct:linkedlist").log(LoggingLevel.INFO, "Before the first split the body is ${body} and has class ${body.getClass()}").split(body(), AggregationStrategies.flexible().pick(body()).accumulateInCollection(LinkedList.class)).log(LoggingLevel.INFO, "During the first split the body is ${body} and has class ${body.getClass()}").end().log(LoggingLevel.INFO, "Before the second split the body is ${body} and has class ${body.getClass()}").split(body(), AggregationStrategies.flexible().pick(body()).accumulateInCollection(LinkedList.class)).log(LoggingLevel.INFO, "During the second split the body is ${body} and has class ${body.getClass()}").end().log(LoggingLevel.INFO, "After the second split the body is ${body} and has class ${body.getClass()}");
            from("direct:hashset").log(LoggingLevel.INFO, "Before the first split the body is ${body} and has class ${body.getClass()}").split(body(), AggregationStrategies.flexible().pick(body()).accumulateInCollection(HashSet.class)).log(LoggingLevel.INFO, "During the first split the body is ${body} and has class ${body.getClass()}").end().log(LoggingLevel.INFO, "Before the second split the body is ${body} and has class ${body.getClass()}").split(body(), AggregationStrategies.flexible().pick(body()).accumulateInCollection(HashSet.class)).log(LoggingLevel.INFO, "During the second split the body is ${body} and has class ${body.getClass()}").end().log(LoggingLevel.INFO, "After the second split the body is ${body} and has class ${body.getClass()}");
        }
    };
}
Also used : TimeoutAwareMixin(org.apache.camel.util.toolbox.FlexibleAggregationStrategy.TimeoutAwareMixin) Exchange(org.apache.camel.Exchange) RouteBuilder(org.apache.camel.builder.RouteBuilder) CompletionAwareMixin(org.apache.camel.util.toolbox.FlexibleAggregationStrategy.CompletionAwareMixin) HashSet(java.util.HashSet) AggregationStrategy(org.apache.camel.processor.aggregate.AggregationStrategy)

Aggregations

HashSet (java.util.HashSet)1 Exchange (org.apache.camel.Exchange)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)1 CompletionAwareMixin (org.apache.camel.util.toolbox.FlexibleAggregationStrategy.CompletionAwareMixin)1 TimeoutAwareMixin (org.apache.camel.util.toolbox.FlexibleAggregationStrategy.TimeoutAwareMixin)1