Search in sources :

Example 31 with SynchronizationAdapter

use of org.apache.camel.support.SynchronizationAdapter in project camel by apache.

the class SedaInOutChainedWithOnCompletionTest method createRouteBuilder.

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

        @Override
        public void configure() throws Exception {
            from("seda:a").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    // should come in last
                    exchange.addOnCompletion(new SynchronizationAdapter() {

                        @Override
                        public void onDone(Exchange exchange) {
                            template.sendBody("mock:c", "onCustomCompletion");
                        }
                    });
                }
            }).to("mock:a").transform(simple("${body}-a")).to("seda:b");
            from("seda:b").to("mock:b").transform(simple("${body}-b")).to("seda:c");
            from("seda:c").to("mock:c").transform(simple("${body}-c"));
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) SynchronizationAdapter(org.apache.camel.support.SynchronizationAdapter)

Example 32 with SynchronizationAdapter

use of org.apache.camel.support.SynchronizationAdapter in project camel by apache.

the class SedaWaitForTaskCompleteOnCompletionTest method createRouteBuilder.

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

        @Override
        public void configure() throws Exception {
            errorHandler(defaultErrorHandler().maximumRedeliveries(3).redeliveryDelay(0));
            from("direct:start").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    exchange.addOnCompletion(new SynchronizationAdapter() {

                        @Override
                        public void onDone(Exchange exchange) {
                            done = done + "A";
                        }
                    });
                }
            }).to("seda:foo?waitForTaskToComplete=Always").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    done = done + "B";
                }
            }).to("mock:result");
            from("seda:foo").errorHandler(noErrorHandler()).process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    done = done + "C";
                }
            }).throwException(new IllegalArgumentException("Forced"));
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) SynchronizationAdapter(org.apache.camel.support.SynchronizationAdapter)

Aggregations

Exchange (org.apache.camel.Exchange)32 SynchronizationAdapter (org.apache.camel.support.SynchronizationAdapter)32 CountDownLatch (java.util.concurrent.CountDownLatch)13 Processor (org.apache.camel.Processor)13 RouteBuilder (org.apache.camel.builder.RouteBuilder)10 ExchangeTimedOutException (org.apache.camel.ExchangeTimedOutException)3 RuntimeCamelException (org.apache.camel.RuntimeCamelException)3 WaitForTaskToComplete (org.apache.camel.WaitForTaskToComplete)3 Message (org.apache.camel.Message)2 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 ChannelHandler (io.netty.channel.ChannelHandler)1 EpollDatagramChannel (io.netty.channel.epoll.EpollDatagramChannel)1 EpollSocketChannel (io.netty.channel.epoll.EpollSocketChannel)1 NioDatagramChannel (io.netty.channel.socket.nio.NioDatagramChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 ReadTimeoutHandler (io.netty.handler.timeout.ReadTimeoutHandler)1 IOException (java.io.IOException)1