use of org.apache.camel.Expression in project camel by apache.
the class SetPropertyDefinition method createProcessor.
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
ObjectHelper.notNull(getPropertyName(), "propertyName", this);
Expression expr = getExpression().createExpression(routeContext);
Expression nameExpr = ExpressionBuilder.parseSimpleOrFallbackToConstantExpression(getPropertyName(), routeContext.getCamelContext());
return new SetPropertyProcessor(nameExpr, expr);
}
use of org.apache.camel.Expression in project camel by apache.
the class SplitDefinition method createProcessor.
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
Processor childProcessor = this.createChildProcessor(routeContext, true);
aggregationStrategy = createAggregationStrategy(routeContext);
boolean isParallelProcessing = getParallelProcessing() != null && getParallelProcessing();
boolean isStreaming = getStreaming() != null && getStreaming();
boolean isShareUnitOfWork = getShareUnitOfWork() != null && getShareUnitOfWork();
boolean isParallelAggregate = getParallelAggregate() != null && getParallelAggregate();
boolean isStopOnAggregateException = getStopOnAggregateException() != null && getStopOnAggregateException();
boolean shutdownThreadPool = ProcessorDefinitionHelper.willCreateNewThreadPool(routeContext, this, isParallelProcessing);
ExecutorService threadPool = ProcessorDefinitionHelper.getConfiguredExecutorService(routeContext, "Split", this, isParallelProcessing);
long timeout = getTimeout() != null ? getTimeout() : 0;
if (timeout > 0 && !isParallelProcessing) {
throw new IllegalArgumentException("Timeout is used but ParallelProcessing has not been enabled.");
}
if (onPrepareRef != null) {
onPrepare = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), onPrepareRef, Processor.class);
}
Expression exp = getExpression().createExpression(routeContext);
Splitter answer = new Splitter(routeContext.getCamelContext(), exp, childProcessor, aggregationStrategy, isParallelProcessing, threadPool, shutdownThreadPool, isStreaming, isStopOnException(), timeout, onPrepare, isShareUnitOfWork, isParallelAggregate, isStopOnAggregateException);
return answer;
}
use of org.apache.camel.Expression in project camel by apache.
the class ToDynamicDefinition method createProcessor.
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
ObjectHelper.notEmpty(uri, "uri", this);
Expression exp = createExpression(routeContext);
SendDynamicProcessor processor = new SendDynamicProcessor(uri, exp);
processor.setCamelContext(routeContext.getCamelContext());
processor.setPattern(pattern);
if (cacheSize != null) {
processor.setCacheSize(cacheSize);
}
if (ignoreInvalidEndpoint != null) {
processor.setIgnoreInvalidEndpoint(ignoreInvalidEndpoint);
}
return processor;
}
use of org.apache.camel.Expression in project camel by apache.
the class IdempotentConsumerDefinition method createProcessor.
@Override
@SuppressWarnings("unchecked")
public Processor createProcessor(RouteContext routeContext) throws Exception {
Processor childProcessor = this.createChildProcessor(routeContext, true);
IdempotentRepository<String> idempotentRepository = resolveMessageIdRepository(routeContext);
ObjectHelper.notNull(idempotentRepository, "idempotentRepository", this);
Expression expression = getExpression().createExpression(routeContext);
// these boolean should be true by default
boolean eager = getEager() == null || getEager();
boolean duplicate = getSkipDuplicate() == null || getSkipDuplicate();
boolean remove = getRemoveOnFailure() == null || getRemoveOnFailure();
// these boolean should be false by default
boolean completionEager = getCompletionEager() != null && getCompletionEager();
return new IdempotentConsumer(expression, idempotentRepository, eager, completionEager, duplicate, remove, childProcessor);
}
use of org.apache.camel.Expression in project camel by apache.
the class RecipientListDefinition method createProcessor.
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
final Expression expression = getExpression().createExpression(routeContext);
boolean isParallelProcessing = getParallelProcessing() != null && getParallelProcessing();
boolean isStreaming = getStreaming() != null && getStreaming();
boolean isParallelAggregate = getParallelAggregate() != null && getParallelAggregate();
boolean isShareUnitOfWork = getShareUnitOfWork() != null && getShareUnitOfWork();
boolean isStopOnException = getStopOnException() != null && getStopOnException();
boolean isIgnoreInvalidEndpoints = getIgnoreInvalidEndpoints() != null && getIgnoreInvalidEndpoints();
boolean isStopOnAggregateException = getStopOnAggregateException() != null && getStopOnAggregateException();
RecipientList answer;
if (delimiter != null) {
answer = new RecipientList(routeContext.getCamelContext(), expression, delimiter);
} else {
answer = new RecipientList(routeContext.getCamelContext(), expression);
}
answer.setAggregationStrategy(createAggregationStrategy(routeContext));
answer.setParallelProcessing(isParallelProcessing);
answer.setParallelAggregate(isParallelAggregate);
answer.setStreaming(isStreaming);
answer.setShareUnitOfWork(isShareUnitOfWork);
answer.setStopOnException(isStopOnException);
answer.setIgnoreInvalidEndpoints(isIgnoreInvalidEndpoints);
answer.setStopOnAggregateException(isStopOnAggregateException);
if (getCacheSize() != null) {
answer.setCacheSize(getCacheSize());
}
if (onPrepareRef != null) {
onPrepare = CamelContextHelper.mandatoryLookup(routeContext.getCamelContext(), onPrepareRef, Processor.class);
}
if (onPrepare != null) {
answer.setOnPrepare(onPrepare);
}
if (getTimeout() != null) {
answer.setTimeout(getTimeout());
}
boolean shutdownThreadPool = ProcessorDefinitionHelper.willCreateNewThreadPool(routeContext, this, isParallelProcessing);
ExecutorService threadPool = ProcessorDefinitionHelper.getConfiguredExecutorService(routeContext, "RecipientList", this, isParallelProcessing);
answer.setExecutorService(threadPool);
answer.setShutdownExecutorService(shutdownThreadPool);
long timeout = getTimeout() != null ? getTimeout() : 0;
if (timeout > 0 && !isParallelProcessing) {
throw new IllegalArgumentException("Timeout is used but ParallelProcessing has not been enabled.");
}
// create a pipeline with two processors
// the first is the eval processor which evaluates the expression to use
// the second is the recipient list
List<Processor> pipe = new ArrayList<Processor>(2);
// the eval processor must be wrapped in error handler, so in case there was an
// error during evaluation, the error handler can deal with it
// the recipient list is not in error handler, as its has its own special error handling
// when sending to the recipients individually
Processor evalProcessor = new EvaluateExpressionProcessor(expression);
evalProcessor = super.wrapInErrorHandler(routeContext, evalProcessor);
pipe.add(evalProcessor);
pipe.add(answer);
// (threads definition does this as well)
return new Pipeline(routeContext.getCamelContext(), pipe) {
@Override
public String toString() {
return "RecipientList[" + expression + "]";
}
};
}
Aggregations