use of org.apache.camel.Expression in project camel by apache.
the class ResequenceDefinition method createBatchResequencer.
/**
* Creates a batch {@link Resequencer} instance applying the given <code>config</code>.
*
* @param routeContext route context.
* @param config batch resequencer configuration.
* @return the configured batch resequencer.
* @throws Exception can be thrown
*/
@SuppressWarnings("deprecation")
protected Resequencer createBatchResequencer(RouteContext routeContext, BatchResequencerConfig config) throws Exception {
Processor processor = this.createChildProcessor(routeContext, true);
Expression expression = getExpression().createExpression(routeContext);
// and wrap in unit of work
CamelInternalProcessor internal = new CamelInternalProcessor(processor);
internal.addAdvice(new CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeContext));
ObjectHelper.notNull(config, "config", this);
ObjectHelper.notNull(expression, "expression", this);
boolean isReverse = config.getReverse() != null && config.getReverse();
boolean isAllowDuplicates = config.getAllowDuplicates() != null && config.getAllowDuplicates();
Resequencer resequencer = new Resequencer(routeContext.getCamelContext(), internal, expression, isAllowDuplicates, isReverse);
resequencer.setBatchSize(config.getBatchSize());
resequencer.setBatchTimeout(config.getBatchTimeout());
resequencer.setReverse(isReverse);
resequencer.setAllowDuplicates(isAllowDuplicates);
if (config.getIgnoreInvalidExchanges() != null) {
resequencer.setIgnoreInvalidExchanges(config.getIgnoreInvalidExchanges());
}
return resequencer;
}
use of org.apache.camel.Expression in project camel by apache.
the class DynamicRouterDefinition method createProcessor.
@Override
public Processor createProcessor(RouteContext routeContext) throws Exception {
Expression expression = getExpression().createExpression(routeContext);
String delimiter = getUriDelimiter() != null ? getUriDelimiter() : DEFAULT_DELIMITER;
DynamicRouter dynamicRouter = new DynamicRouter(routeContext.getCamelContext(), expression, delimiter);
if (getIgnoreInvalidEndpoints() != null) {
dynamicRouter.setIgnoreInvalidEndpoints(getIgnoreInvalidEndpoints());
}
if (getCacheSize() != null) {
dynamicRouter.setCacheSize(getCacheSize());
}
return dynamicRouter;
}
use of org.apache.camel.Expression in project camel by apache.
the class PredicateBuilderConcurrentTest method testPredicateBuilderConcurrent.
public void testPredicateBuilderConcurrent() throws Exception {
context.start();
List<Future<Boolean>> futures = new ArrayList<Future<Boolean>>();
ExecutorService pool = Executors.newFixedThreadPool(10);
for (int i = 0; i < 1000; i++) {
final Integer num = i;
Future<Boolean> future = pool.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
Expression left = ExpressionBuilder.headerExpression("foo");
Expression right;
if (num % 2 == 0) {
right = ExpressionBuilder.constantExpression("ABC");
} else {
right = ExpressionBuilder.constantExpression("DEF");
}
Predicate predicate = PredicateBuilder.isEqualTo(left, right);
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody("Hello World");
exchange.getIn().setHeader("foo", "ABC");
return predicate.matches(exchange);
}
});
futures.add(future);
}
for (int i = 0; i < 1000; i++) {
Boolean result = futures.get(i).get(10, TimeUnit.SECONDS);
if (i % 2 == 0) {
assertEquals("Should be true for #" + i, true, result.booleanValue());
} else {
assertEquals("Should be false for #" + i, false, result.booleanValue());
}
}
pool.shutdownNow();
}
use of org.apache.camel.Expression in project camel by apache.
the class ExpressionBuilderTest method testRegexTokenize.
public void testRegexTokenize() throws Exception {
Expression expression = regexTokenizeExpression(headerExpression("location"), ",");
List<String> expected = new ArrayList<String>(Arrays.asList(new String[] { "Islington", "London", "UK" }));
assertExpression(expression, exchange, expected);
Predicate predicate = contains(regexTokenizeExpression(headerExpression("location"), ","), constantExpression("London"));
assertPredicate(predicate, exchange, true);
predicate = contains(regexTokenizeExpression(headerExpression("location"), ","), constantExpression("Manchester"));
assertPredicate(predicate, exchange, false);
}
use of org.apache.camel.Expression in project camel by apache.
the class ExpressionBuilderTest method testSortLines.
public void testSortLines() throws Exception {
Expression expression = sortExpression(body().tokenize(",").getExpression(), new SortByName());
exchange.getIn().setBody("Jonathan,Claus,James,Hadrian");
List<String> expected = new ArrayList<String>(Arrays.asList(new String[] { "Claus", "Hadrian", "James", "Jonathan" }));
assertExpression(expression, exchange, expected);
}
Aggregations