Search in sources :

Example 1 with ExpressionEvaluatingSelector

use of org.springframework.integration.filter.ExpressionEvaluatingSelector in project spring-integration by spring-projects.

the class RecipientListRouterSpec method recipient.

/**
 * Adds a recipient channel that will be selected if the the expression evaluates to 'true'.
 * @param channelName the channel name.
 * @param expression the expression.
 * @return the router spec.
 */
public RecipientListRouterSpec recipient(String channelName, Expression expression) {
    ExpressionEvaluatingSelector selector = new ExpressionEvaluatingSelector(expression);
    this.handler.addRecipient(channelName, selector);
    this.componentsToRegister.put(selector, null);
    return _this();
}
Also used : ExpressionEvaluatingSelector(org.springframework.integration.filter.ExpressionEvaluatingSelector)

Example 2 with ExpressionEvaluatingSelector

use of org.springframework.integration.filter.ExpressionEvaluatingSelector in project spring-integration by spring-projects.

the class RecipientListRouter method removeRecipient.

@Override
@ManagedOperation
public int removeRecipient(String channelName, String selectorExpression) {
    int counter = 0;
    MessageChannel targetChannel = getChannelResolver().resolveDestination(channelName);
    for (Iterator<Recipient> it = this.recipients.iterator(); it.hasNext(); ) {
        Recipient next = it.next();
        MessageSelector selector = next.getSelector();
        MessageChannel channel = next.getChannel();
        if (selector instanceof ExpressionEvaluatingSelector && channel == targetChannel && ((ExpressionEvaluatingSelector) selector).getExpressionString().equals(selectorExpression)) {
            it.remove();
            counter++;
        }
    }
    return counter;
}
Also used : ExpressionEvaluatingSelector(org.springframework.integration.filter.ExpressionEvaluatingSelector) MessageChannel(org.springframework.messaging.MessageChannel) MessageSelector(org.springframework.integration.core.MessageSelector) ManagedOperation(org.springframework.jmx.export.annotation.ManagedOperation)

Example 3 with ExpressionEvaluatingSelector

use of org.springframework.integration.filter.ExpressionEvaluatingSelector in project spring-integration by spring-projects.

the class RecipientListRouter method addRecipient.

private void addRecipient(String channelName, String selectorExpression, Queue<Recipient> recipients) {
    Assert.hasText(channelName, "'channelName' must not be empty.");
    Assert.hasText(selectorExpression, "'selectorExpression' must not be empty.");
    ExpressionEvaluatingSelector expressionEvaluatingSelector = new ExpressionEvaluatingSelector(selectorExpression);
    expressionEvaluatingSelector.setBeanFactory(getBeanFactory());
    Recipient recipient = new Recipient(channelName, expressionEvaluatingSelector);
    if (getBeanFactory() != null) {
        recipient.setChannelResolver(getChannelResolver());
    }
    recipients.add(recipient);
}
Also used : ExpressionEvaluatingSelector(org.springframework.integration.filter.ExpressionEvaluatingSelector)

Example 4 with ExpressionEvaluatingSelector

use of org.springframework.integration.filter.ExpressionEvaluatingSelector in project spring-integration by spring-projects.

the class RecipientListRouterSpec method recipient.

/**
 * Adds a recipient channel that will be selected if the the expression evaluates to 'true'.
 * @param channel the recipient channel.
 * @param expression the expression.
 * @return the router spec.
 */
public RecipientListRouterSpec recipient(MessageChannel channel, Expression expression) {
    if (expression != null) {
        ExpressionEvaluatingSelector selector = new ExpressionEvaluatingSelector(expression);
        this.handler.addRecipient(channel, selector);
        this.componentsToRegister.put(selector, null);
    } else {
        this.handler.addRecipient(channel);
    }
    return _this();
}
Also used : ExpressionEvaluatingSelector(org.springframework.integration.filter.ExpressionEvaluatingSelector)

Aggregations

ExpressionEvaluatingSelector (org.springframework.integration.filter.ExpressionEvaluatingSelector)4 MessageSelector (org.springframework.integration.core.MessageSelector)1 ManagedOperation (org.springframework.jmx.export.annotation.ManagedOperation)1 MessageChannel (org.springframework.messaging.MessageChannel)1