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;
}
Aggregations