Search in sources :

Example 1 with OnCompletionProcessor

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

the class OnCompletionDefinition method createProcessor.

@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
    // and therefore is in a better position to decide among context/route scoped OnCompletion at runtime
    if (routeScoped == null) {
        routeScoped = super.getParent() != null;
    }
    boolean isOnCompleteOnly = getOnCompleteOnly() != null && getOnCompleteOnly();
    boolean isOnFailureOnly = getOnFailureOnly() != null && getOnFailureOnly();
    boolean isParallelProcessing = getParallelProcessing() != null && getParallelProcessing();
    boolean original = getUseOriginalMessagePolicy() != null && getUseOriginalMessagePolicy();
    if (isOnCompleteOnly && isOnFailureOnly) {
        throw new IllegalArgumentException("Both onCompleteOnly and onFailureOnly cannot be true. Only one of them can be true. On node: " + this);
    }
    if (original) {
        // ensure allow original is turned on
        routeContext.setAllowUseOriginalMessage(true);
    }
    String routeId = routeContext.getRoute().idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
    Processor childProcessor = this.createChildProcessor(routeContext, true);
    // wrap the on completion route in a unit of work processor
    CamelInternalProcessor internal = new CamelInternalProcessor(childProcessor);
    internal.addAdvice(new CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeContext));
    onCompletions.put(routeId, internal);
    Predicate when = null;
    if (onWhen != null) {
        when = onWhen.getExpression().createPredicate(routeContext);
    }
    boolean shutdownThreadPool = ProcessorDefinitionHelper.willCreateNewThreadPool(routeContext, this, isParallelProcessing);
    ExecutorService threadPool = ProcessorDefinitionHelper.getConfiguredExecutorService(routeContext, "OnCompletion", this, isParallelProcessing);
    // should be after consumer by default
    boolean afterConsumer = mode == null || mode == OnCompletionMode.AfterConsumer;
    OnCompletionProcessor answer = new OnCompletionProcessor(routeContext.getCamelContext(), internal, threadPool, shutdownThreadPool, isOnCompleteOnly, isOnFailureOnly, when, original, afterConsumer);
    return answer;
}
Also used : CamelInternalProcessor(org.apache.camel.processor.CamelInternalProcessor) CamelInternalProcessor(org.apache.camel.processor.CamelInternalProcessor) Processor(org.apache.camel.Processor) OnCompletionProcessor(org.apache.camel.processor.OnCompletionProcessor) OnCompletionProcessor(org.apache.camel.processor.OnCompletionProcessor) ExecutorService(java.util.concurrent.ExecutorService) AsPredicate(org.apache.camel.spi.AsPredicate) Predicate(org.apache.camel.Predicate)

Aggregations

ExecutorService (java.util.concurrent.ExecutorService)1 Predicate (org.apache.camel.Predicate)1 Processor (org.apache.camel.Processor)1 CamelInternalProcessor (org.apache.camel.processor.CamelInternalProcessor)1 OnCompletionProcessor (org.apache.camel.processor.OnCompletionProcessor)1 AsPredicate (org.apache.camel.spi.AsPredicate)1