Search in sources :

Example 1 with RouteboxDispatcher

use of org.apache.camel.component.routebox.strategy.RouteboxDispatcher in project camel by apache.

the class RouteboxDirectProducer method process.

public void process(Exchange exchange) throws Exception {
    Exchange result;
    if ((((RouteboxDirectEndpoint) getRouteboxEndpoint()).getConsumer() == null) && (getRouteboxEndpoint().getConfig().isSendToConsumer())) {
        throw new CamelExchangeException("No consumers available on endpoint: " + getRouteboxEndpoint(), exchange);
    } else {
        LOG.debug("Dispatching to Inner Route {}", exchange);
        RouteboxDispatcher dispatcher = new RouteboxDispatcher(producer);
        result = dispatcher.dispatchSync(getRouteboxEndpoint(), exchange);
    }
    if (getRouteboxEndpoint().getConfig().isSendToConsumer()) {
        ((RouteboxDirectEndpoint) getRouteboxEndpoint()).getConsumer().getProcessor().process(result);
    }
}
Also used : Exchange(org.apache.camel.Exchange) CamelExchangeException(org.apache.camel.CamelExchangeException) RouteboxDispatcher(org.apache.camel.component.routebox.strategy.RouteboxDispatcher)

Example 2 with RouteboxDispatcher

use of org.apache.camel.component.routebox.strategy.RouteboxDispatcher in project camel by apache.

the class RouteboxSedaConsumer method dispatchToInnerRoute.

private void dispatchToInnerRoute(BlockingQueue<Exchange> queue, final Exchange exchange) throws InterruptedException {
    Exchange result;
    if (exchange != null) {
        if (isRunAllowed()) {
            try {
                LOG.debug("Dispatching to inner route: {}", exchange);
                RouteboxDispatcher dispatcher = new RouteboxDispatcher(producer);
                result = dispatcher.dispatchAsync(getRouteboxEndpoint(), exchange);
                processor.process(result, new AsyncCallback() {

                    public void done(boolean doneSync) {
                    // noop
                    }
                });
            } catch (Exception e) {
                getExceptionHandler().handleException("Error processing exchange", exchange, e);
            }
        } else {
            if (LOG.isWarnEnabled()) {
                LOG.warn("This consumer is stopped during polling an exchange, so putting it back on the seda queue: " + exchange);
            }
            queue.put(exchange);
        }
    }
}
Also used : Exchange(org.apache.camel.Exchange) AsyncCallback(org.apache.camel.AsyncCallback) RouteboxDispatcher(org.apache.camel.component.routebox.strategy.RouteboxDispatcher)

Example 3 with RouteboxDispatcher

use of org.apache.camel.component.routebox.strategy.RouteboxDispatcher in project camel by apache.

the class RouteboxDirectProducer method process.

public boolean process(Exchange exchange, final AsyncCallback callback) {
    boolean flag = true;
    if ((((RouteboxDirectEndpoint) getRouteboxEndpoint()).getConsumer() == null) && ((getRouteboxEndpoint()).getConfig().isSendToConsumer())) {
        exchange.setException(new CamelExchangeException("No consumers available on endpoint: " + getRouteboxEndpoint(), exchange));
        callback.done(true);
        flag = true;
    } else {
        try {
            LOG.debug("Dispatching to Inner Route {}", exchange);
            RouteboxDispatcher dispatcher = new RouteboxDispatcher(producer);
            exchange = dispatcher.dispatchAsync(getRouteboxEndpoint(), exchange);
            if (getRouteboxEndpoint().getConfig().isSendToConsumer()) {
                AsyncProcessor processor = ((RouteboxDirectEndpoint) getRouteboxEndpoint()).getConsumer().getAsyncProcessor();
                flag = processor.process(exchange, callback);
            }
        } catch (Exception e) {
            getExceptionHandler().handleException("Error processing exchange", exchange, e);
        }
    }
    return flag;
}
Also used : CamelExchangeException(org.apache.camel.CamelExchangeException) AsyncProcessor(org.apache.camel.AsyncProcessor) RouteboxDispatcher(org.apache.camel.component.routebox.strategy.RouteboxDispatcher) CamelExchangeException(org.apache.camel.CamelExchangeException)

Aggregations

RouteboxDispatcher (org.apache.camel.component.routebox.strategy.RouteboxDispatcher)3 CamelExchangeException (org.apache.camel.CamelExchangeException)2 Exchange (org.apache.camel.Exchange)2 AsyncCallback (org.apache.camel.AsyncCallback)1 AsyncProcessor (org.apache.camel.AsyncProcessor)1