Search in sources :

Example 1 with DelegateAsyncProcessor

use of org.apache.camel.processor.DelegateAsyncProcessor in project camel by apache.

the class ProcessDefinition method createProcessor.

@Override
public Processor createProcessor(RouteContext routeContext) {
    Processor answer = processor;
    if (processor == null) {
        ObjectHelper.notNull(ref, "ref", this);
        answer = routeContext.mandatoryLookup(getRef(), Processor.class);
    }
    // (a Processor must be a Service to be enlisted in JMX)
    if (!(answer instanceof Service)) {
        if (answer instanceof AsyncProcessor) {
            // the processor is async by nature so use the async delegate
            answer = new DelegateAsyncProcessor(answer);
        } else {
            // the processor is sync by nature so use the sync delegate
            answer = new DelegateSyncProcessor(answer);
        }
    }
    return answer;
}
Also used : DelegateSyncProcessor(org.apache.camel.processor.DelegateSyncProcessor) DelegateSyncProcessor(org.apache.camel.processor.DelegateSyncProcessor) DelegateAsyncProcessor(org.apache.camel.processor.DelegateAsyncProcessor) Processor(org.apache.camel.Processor) AsyncProcessor(org.apache.camel.AsyncProcessor) DelegateAsyncProcessor(org.apache.camel.processor.DelegateAsyncProcessor) AsyncProcessor(org.apache.camel.AsyncProcessor) Service(org.apache.camel.Service) DelegateAsyncProcessor(org.apache.camel.processor.DelegateAsyncProcessor)

Example 2 with DelegateAsyncProcessor

use of org.apache.camel.processor.DelegateAsyncProcessor in project camel by apache.

the class Debug method wrapProcessorInInterceptors.

public Processor wrapProcessorInInterceptors(final CamelContext context, final ProcessorDefinition<?> definition, final Processor target, final Processor nextTarget) throws Exception {
    return new DelegateAsyncProcessor(target) {

        @Override
        public boolean process(final Exchange exchange, final AsyncCallback callback) {
            debugger.beforeProcess(exchange, target, definition);
            final StopWatch watch = new StopWatch();
            return processor.process(exchange, new AsyncCallback() {

                public void done(boolean doneSync) {
                    long diff = watch.stop();
                    debugger.afterProcess(exchange, processor, definition, diff);
                    // must notify original callback
                    callback.done(doneSync);
                }
            });
        }

        @Override
        public String toString() {
            return "Debug[" + target + "]";
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) AsyncCallback(org.apache.camel.AsyncCallback) DelegateAsyncProcessor(org.apache.camel.processor.DelegateAsyncProcessor) StopWatch(org.apache.camel.util.StopWatch)

Aggregations

DelegateAsyncProcessor (org.apache.camel.processor.DelegateAsyncProcessor)2 AsyncCallback (org.apache.camel.AsyncCallback)1 AsyncProcessor (org.apache.camel.AsyncProcessor)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 Service (org.apache.camel.Service)1 DelegateSyncProcessor (org.apache.camel.processor.DelegateSyncProcessor)1 StopWatch (org.apache.camel.util.StopWatch)1