Search in sources :

Example 1 with MessageSelector

use of org.springframework.integration.core.MessageSelector in project spring-integration by spring-projects.

the class TopLevelSelectorParserTests method topLevelSelector.

@Test
public void topLevelSelector() {
    MessageSelector selector = (MessageSelector) context.getBean("selector");
    assertTrue(selector.accept(new GenericMessage<String>("test")));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageSelector(org.springframework.integration.core.MessageSelector) Test(org.junit.Test)

Example 2 with MessageSelector

use of org.springframework.integration.core.MessageSelector in project spring-integration by spring-projects.

the class RecipientListRouterSpec method recipient.

/**
 * Adds a recipient channel that will be selected if the the selector's accept method returns 'true'.
 * @param channel the recipient channel.
 * @param selector the selector.
 * @param <P> the selector source type.
 * @return the router spec.
 */
public <P> RecipientListRouterSpec recipient(MessageChannel channel, GenericSelector<P> selector) {
    MessageSelector messageSelector;
    if (selector instanceof MessageSelector) {
        messageSelector = (MessageSelector) selector;
    } else {
        messageSelector = isLambda(selector) ? new MethodInvokingSelector(new LambdaMessageProcessor(selector, null)) : new MethodInvokingSelector(selector);
    }
    this.handler.addRecipient(channel, messageSelector);
    return _this();
}
Also used : LambdaMessageProcessor(org.springframework.integration.handler.LambdaMessageProcessor) MessageSelector(org.springframework.integration.core.MessageSelector) MethodInvokingSelector(org.springframework.integration.filter.MethodInvokingSelector)

Example 3 with MessageSelector

use of org.springframework.integration.core.MessageSelector in project spring-integration by spring-projects.

the class RecipientListRouterSpec method recipient.

/**
 * Adds a recipient channel that will be selected if the the selector's accept method returns 'true'.
 * @param channelName the channel name.
 * @param selector the selector.
 * @param <P> the selector source type.
 * @return the router spec.
 */
public <P> RecipientListRouterSpec recipient(String channelName, GenericSelector<P> selector) {
    MessageSelector messageSelector;
    if (selector instanceof MessageSelector) {
        messageSelector = (MessageSelector) selector;
    } else {
        messageSelector = isLambda(selector) ? new MethodInvokingSelector(new LambdaMessageProcessor(selector, null)) : new MethodInvokingSelector(selector);
    }
    this.handler.addRecipient(channelName, messageSelector);
    return _this();
}
Also used : LambdaMessageProcessor(org.springframework.integration.handler.LambdaMessageProcessor) MessageSelector(org.springframework.integration.core.MessageSelector) MethodInvokingSelector(org.springframework.integration.filter.MethodInvokingSelector)

Example 4 with MessageSelector

use of org.springframework.integration.core.MessageSelector in project spring-integration by spring-projects.

the class MessageSelectorChain method accept.

/**
 * Pass the message through the selector chain. Whether the Message is
 * {@link #accept(Message) accepted} is based upon the tallied results of
 * the individual selectors' responses in accordance with this chain's
 * {@link VotingStrategy}.
 */
@Override
public final boolean accept(Message<?> message) {
    int count = 0;
    int accepted = 0;
    for (MessageSelector next : this.selectors) {
        count++;
        if (next.accept(message)) {
            if (this.votingStrategy.equals(VotingStrategy.ANY)) {
                return true;
            }
            accepted++;
        } else if (this.votingStrategy.equals(VotingStrategy.ALL)) {
            return false;
        }
    }
    return this.decide(accepted, count);
}
Also used : MessageSelector(org.springframework.integration.core.MessageSelector)

Example 5 with MessageSelector

use of org.springframework.integration.core.MessageSelector in project spring-integration by spring-projects.

the class MessageSelectingInterceptorTests method testSingleSelectorRejects.

@Test(expected = MessageDeliveryException.class)
public void testSingleSelectorRejects() {
    final AtomicInteger counter = new AtomicInteger();
    MessageSelector selector = new TestMessageSelector(false, counter);
    MessageSelectingInterceptor interceptor = new MessageSelectingInterceptor(selector);
    QueueChannel channel = new QueueChannel();
    channel.addInterceptor(interceptor);
    channel.send(new GenericMessage<String>("test1"));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MessageSelector(org.springframework.integration.core.MessageSelector) Test(org.junit.Test)

Aggregations

MessageSelector (org.springframework.integration.core.MessageSelector)15 Test (org.junit.Test)9 GenericMessage (org.springframework.messaging.support.GenericMessage)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4 MethodInvokingSelector (org.springframework.integration.filter.MethodInvokingSelector)4 MessageFilter (org.springframework.integration.filter.MessageFilter)3 LambdaMessageProcessor (org.springframework.integration.handler.LambdaMessageProcessor)3 MessageSelectorChain (org.springframework.integration.selector.MessageSelectorChain)2 List (java.util.List)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 Bean (org.springframework.context.annotation.Bean)1 ExpressionEvaluatingSelector (org.springframework.integration.filter.ExpressionEvaluatingSelector)1 GroovyScriptExecutingMessageProcessor (org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor)1 MessageProcessor (org.springframework.integration.handler.MessageProcessor)1 ManagedOperation (org.springframework.jmx.export.annotation.ManagedOperation)1 MessageChannel (org.springframework.messaging.MessageChannel)1 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)1