Added MessageSelectorChain and modified TargetEndpoint to provide a 'setMessageSelector' method rather than managing a list of selectors with the 'addMessageSelector' method. Also modified the endpoint parser so that the configuration of a selector chain is more consistent with that of MessageHandlerChain. Now, the XML for endpoints uses a "selector" attribute instead of 0..n <selector/> sub-elements (INT-159).
This commit is contained in:
@@ -369,8 +369,8 @@ public class SubscriptionManagerTests {
|
||||
SubscriptionManager manager = new SubscriptionManager(channel, scheduler);
|
||||
HandlerEndpoint endpoint1 = new HandlerEndpoint(handler1);
|
||||
HandlerEndpoint endpoint2 = new HandlerEndpoint(handler2);
|
||||
endpoint1.addMessageSelector(new PayloadTypeSelector(Integer.class));
|
||||
endpoint2.addMessageSelector(new PayloadTypeSelector(String.class));
|
||||
endpoint1.setMessageSelector(new PayloadTypeSelector(Integer.class));
|
||||
endpoint2.setMessageSelector(new PayloadTypeSelector(String.class));
|
||||
manager.addTarget(endpoint1);
|
||||
manager.addTarget(endpoint2);
|
||||
manager.start();
|
||||
@@ -395,7 +395,7 @@ public class SubscriptionManagerTests {
|
||||
SubscriptionManager manager = new SubscriptionManager(channel, scheduler);
|
||||
final HandlerEndpoint endpoint1 = new HandlerEndpoint(handler1);
|
||||
final HandlerEndpoint endpoint2 = new HandlerEndpoint(handler2);
|
||||
endpoint1.addMessageSelector(new PayloadTypeSelector(Integer.class) {
|
||||
endpoint1.setMessageSelector(new PayloadTypeSelector(Integer.class) {
|
||||
@Override
|
||||
public boolean accept(Message<?> message) {
|
||||
selectorCounter1.incrementAndGet();
|
||||
@@ -403,7 +403,7 @@ public class SubscriptionManagerTests {
|
||||
return super.accept(message);
|
||||
}
|
||||
});
|
||||
endpoint2.addMessageSelector(new PayloadTypeSelector(Integer.class) {
|
||||
endpoint2.setMessageSelector(new PayloadTypeSelector(Integer.class) {
|
||||
@Override
|
||||
public boolean accept(Message<?> message) {
|
||||
selectorCounter2.incrementAndGet();
|
||||
@@ -437,8 +437,8 @@ public class SubscriptionManagerTests {
|
||||
endpoint1.setConcurrencyPolicy(new ConcurrencyPolicy(1, 1));
|
||||
HandlerEndpoint endpoint2 = new HandlerEndpoint(handler2);
|
||||
endpoint2.setConcurrencyPolicy(new ConcurrencyPolicy(1, 1));
|
||||
endpoint1.addMessageSelector(new PayloadTypeSelector(Integer.class));
|
||||
endpoint2.addMessageSelector(new PayloadTypeSelector(String.class));
|
||||
endpoint1.setMessageSelector(new PayloadTypeSelector(Integer.class));
|
||||
endpoint2.setMessageSelector(new PayloadTypeSelector(String.class));
|
||||
manager.addTarget(endpoint1);
|
||||
manager.addTarget(endpoint2);
|
||||
manager.start();
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -107,13 +108,13 @@ public class EndpointParserTests {
|
||||
@Test
|
||||
public void testEndpointWithSelectorAccepts() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"endpointWithSelectors.xml", this.getClass());
|
||||
"endpointWithSelector.xml", this.getClass());
|
||||
Target endpoint = (Target) context.getBean("endpoint");
|
||||
((Lifecycle) endpoint).start();
|
||||
Message<?> message = new StringMessage("test");
|
||||
MessageChannel replyChannel = new QueueChannel();
|
||||
message.getHeader().setReturnAddress(replyChannel);
|
||||
endpoint.send(message);
|
||||
assertTrue(endpoint.send(message));
|
||||
Message<?> reply = replyChannel.receive(500);
|
||||
assertNotNull(reply);
|
||||
assertEquals("foo", reply.getPayload());
|
||||
@@ -122,10 +123,13 @@ public class EndpointParserTests {
|
||||
@Test
|
||||
public void testEndpointWithSelectorRejects() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"endpointWithSelectors.xml", this.getClass());
|
||||
"endpointWithSelector.xml", this.getClass());
|
||||
Target endpoint = (Target) context.getBean("endpoint");
|
||||
((Lifecycle) endpoint).start();
|
||||
assertFalse(endpoint.send(new GenericMessage<Integer>(123)));
|
||||
Message<?> message = new GenericMessage<Integer>(123);
|
||||
MessageChannel replyChannel = new QueueChannel();
|
||||
message.getHeader().setReturnAddress(replyChannel);
|
||||
assertFalse(endpoint.send(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -48,7 +48,7 @@ public class TestHandler implements MessageHandler {
|
||||
}
|
||||
|
||||
public Message handle(Message message) {
|
||||
this.messageString = (String) message.getPayload();
|
||||
this.messageString = message.getPayload().toString();
|
||||
this.latch.countDown();
|
||||
return (this.replyMessageText != null) ? new StringMessage(this.replyMessageText) : null;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
|
||||
<queue-channel id="testChannel" capacity="50"/>
|
||||
|
||||
<handler-endpoint id="endpoint" input-channel="testChannel" handler="testHandler">
|
||||
<handler-endpoint id="endpoint" input-channel="testChannel"
|
||||
handler="testHandler" selector="typeSelector">
|
||||
<schedule period="100"/>
|
||||
<selector ref="typeSelector"/>
|
||||
</handler-endpoint>
|
||||
|
||||
<beans:bean id="typeSelector" class="org.springframework.integration.message.selector.PayloadTypeSelector">
|
||||
@@ -39,6 +39,7 @@ import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
import org.springframework.integration.message.selector.MessageSelectorChain;
|
||||
import org.springframework.integration.util.ErrorHandler;
|
||||
|
||||
/**
|
||||
@@ -338,7 +339,7 @@ public class HandlerEndpointTests {
|
||||
@Test
|
||||
public void testEndpointWithSelectorRejecting() {
|
||||
HandlerEndpoint endpoint = new HandlerEndpoint(TestHandlers.nullHandler());
|
||||
endpoint.addMessageSelector(new MessageSelector() {
|
||||
endpoint.setMessageSelector(new MessageSelector() {
|
||||
public boolean accept(Message<?> message) {
|
||||
return false;
|
||||
}
|
||||
@@ -351,7 +352,7 @@ public class HandlerEndpointTests {
|
||||
public void testEndpointWithSelectorAccepting() throws InterruptedException {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
HandlerEndpoint endpoint = new HandlerEndpoint(TestHandlers.countDownHandler(latch));
|
||||
endpoint.addMessageSelector(new MessageSelector() {
|
||||
endpoint.setMessageSelector(new MessageSelector() {
|
||||
public boolean accept(Message<?> message) {
|
||||
return true;
|
||||
}
|
||||
@@ -367,18 +368,20 @@ public class HandlerEndpointTests {
|
||||
public void testEndpointWithMultipleSelectorsAndFirstRejects() {
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
HandlerEndpoint endpoint = new HandlerEndpoint(TestHandlers.countingHandler(counter));
|
||||
endpoint.addMessageSelector(new MessageSelector() {
|
||||
MessageSelectorChain selectorChain = new MessageSelectorChain();
|
||||
selectorChain.add(new MessageSelector() {
|
||||
public boolean accept(Message<?> message) {
|
||||
counter.incrementAndGet();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
endpoint.addMessageSelector(new MessageSelector() {
|
||||
selectorChain.add(new MessageSelector() {
|
||||
public boolean accept(Message<?> message) {
|
||||
counter.incrementAndGet();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
endpoint.setMessageSelector(selectorChain);
|
||||
endpoint.start();
|
||||
assertFalse(endpoint.send(new StringMessage("test")));
|
||||
assertEquals("only the first selector should have been invoked", 1, counter.get());
|
||||
@@ -390,18 +393,20 @@ public class HandlerEndpointTests {
|
||||
final AtomicInteger selectorCounter = new AtomicInteger();
|
||||
AtomicInteger handlerCounter = new AtomicInteger();
|
||||
HandlerEndpoint endpoint = new HandlerEndpoint(TestHandlers.countingHandler(handlerCounter));
|
||||
endpoint.addMessageSelector(new MessageSelector() {
|
||||
MessageSelectorChain selectorChain = new MessageSelectorChain();
|
||||
selectorChain.add(new MessageSelector() {
|
||||
public boolean accept(Message<?> message) {
|
||||
selectorCounter.incrementAndGet();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
endpoint.addMessageSelector(new MessageSelector() {
|
||||
selectorChain.add(new MessageSelector() {
|
||||
public boolean accept(Message<?> message) {
|
||||
selectorCounter.incrementAndGet();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
endpoint.setMessageSelector(selectorChain);
|
||||
endpoint.start();
|
||||
assertFalse(endpoint.send(new StringMessage("test")));
|
||||
assertEquals("both selectors should have been invoked", 2, selectorCounter.get());
|
||||
@@ -413,18 +418,20 @@ public class HandlerEndpointTests {
|
||||
public void testEndpointWithMultipleSelectorsAndBothAccept() {
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
HandlerEndpoint endpoint = new HandlerEndpoint(TestHandlers.countingHandler(counter));
|
||||
endpoint.addMessageSelector(new MessageSelector() {
|
||||
MessageSelectorChain selectorChain = new MessageSelectorChain();
|
||||
selectorChain.add(new MessageSelector() {
|
||||
public boolean accept(Message<?> message) {
|
||||
counter.incrementAndGet();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
endpoint.addMessageSelector(new MessageSelector() {
|
||||
selectorChain.add(new MessageSelector() {
|
||||
public boolean accept(Message<?> message) {
|
||||
counter.incrementAndGet();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
endpoint.setMessageSelector(selectorChain);
|
||||
endpoint.start();
|
||||
assertTrue(endpoint.send(new StringMessage("test")));
|
||||
assertEquals("both selectors and handler should have been invoked", 3, counter.get());
|
||||
|
||||
Reference in New Issue
Block a user