Moved dispatcher policy into channel - simplified MessageBus, DefaultMessageDispatcher, and DispatcherTask.
This commit is contained in:
@@ -26,6 +26,7 @@ import org.junit.Test;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.SimpleChannel;
|
||||
import org.springframework.integration.dispatcher.ChannelPollingMessageRetriever;
|
||||
import org.springframework.integration.dispatcher.DispatcherPolicy;
|
||||
import org.springframework.integration.dispatcher.DispatcherTask;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
@@ -70,10 +71,11 @@ public class ByteStreamTargetAdapterTests {
|
||||
@Test
|
||||
public void testMaxMessagesPerTaskSameAsMessageCount() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
MessageChannel channel = new SimpleChannel();
|
||||
ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream);
|
||||
DispatcherPolicy dispatcherPolicy = new DispatcherPolicy();
|
||||
dispatcherPolicy.setMaxMessagesPerTask(3);
|
||||
SimpleChannel channel = new SimpleChannel(dispatcherPolicy);
|
||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||
retriever.setMaxMessagesPerTask(3);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(retriever);
|
||||
dispatcherTask.addHandler(adapter);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}));
|
||||
@@ -89,10 +91,11 @@ public class ByteStreamTargetAdapterTests {
|
||||
@Test
|
||||
public void testMaxMessagesPerTaskLessThanMessageCount() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
MessageChannel channel = new SimpleChannel();
|
||||
ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream);
|
||||
DispatcherPolicy dispatcherPolicy = new DispatcherPolicy();
|
||||
dispatcherPolicy.setMaxMessagesPerTask(2);
|
||||
SimpleChannel channel = new SimpleChannel(dispatcherPolicy);
|
||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||
retriever.setMaxMessagesPerTask(2);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(retriever);
|
||||
dispatcherTask.addHandler(adapter);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}));
|
||||
@@ -107,12 +110,12 @@ public class ByteStreamTargetAdapterTests {
|
||||
@Test
|
||||
public void testMaxMessagesPerTaskExceedsMessageCount() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
MessageChannel channel = new SimpleChannel();
|
||||
ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream);
|
||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||
retriever.setMaxMessagesPerTask(5);
|
||||
retriever.setReceiveTimeout(0);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(retriever);
|
||||
DispatcherPolicy dispatcherPolicy = new DispatcherPolicy();
|
||||
dispatcherPolicy.setMaxMessagesPerTask(5);
|
||||
dispatcherPolicy.setReceiveTimeout(0);
|
||||
SimpleChannel channel = new SimpleChannel(dispatcherPolicy);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
||||
dispatcherTask.addHandler(adapter);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}));
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {4,5,6}));
|
||||
@@ -126,12 +129,12 @@ public class ByteStreamTargetAdapterTests {
|
||||
@Test
|
||||
public void testMaxMessagesLessThanMessageCountWithMultipleDispatches() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
MessageChannel channel = new SimpleChannel();
|
||||
ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream);
|
||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||
retriever.setMaxMessagesPerTask(2);
|
||||
retriever.setReceiveTimeout(0);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(retriever);
|
||||
DispatcherPolicy dispatcherPolicy = new DispatcherPolicy();
|
||||
dispatcherPolicy.setMaxMessagesPerTask(2);
|
||||
dispatcherPolicy.setReceiveTimeout(0);
|
||||
SimpleChannel channel = new SimpleChannel(dispatcherPolicy);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
||||
dispatcherTask.addHandler(adapter);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}));
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {4,5,6}));
|
||||
@@ -150,12 +153,12 @@ public class ByteStreamTargetAdapterTests {
|
||||
@Test
|
||||
public void testMaxMessagesExceedsMessageCountWithMultipleDispatches() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
MessageChannel channel = new SimpleChannel();
|
||||
ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream);
|
||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||
retriever.setMaxMessagesPerTask(5);
|
||||
retriever.setReceiveTimeout(0);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(retriever);
|
||||
DispatcherPolicy dispatcherPolicy = new DispatcherPolicy();
|
||||
dispatcherPolicy.setMaxMessagesPerTask(5);
|
||||
dispatcherPolicy.setReceiveTimeout(0);
|
||||
SimpleChannel channel = new SimpleChannel(dispatcherPolicy);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
||||
dispatcherTask.addHandler(adapter);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}));
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {4,5,6}));
|
||||
@@ -173,11 +176,12 @@ public class ByteStreamTargetAdapterTests {
|
||||
@Test
|
||||
public void testStreamResetBetweenDispatches() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
MessageChannel channel = new SimpleChannel();
|
||||
ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream);
|
||||
DispatcherPolicy dispatcherPolicy = new DispatcherPolicy();
|
||||
dispatcherPolicy.setMaxMessagesPerTask(2);
|
||||
dispatcherPolicy.setReceiveTimeout(0);
|
||||
SimpleChannel channel = new SimpleChannel(dispatcherPolicy);
|
||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||
retriever.setMaxMessagesPerTask(2);
|
||||
retriever.setReceiveTimeout(0);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(retriever);
|
||||
dispatcherTask.addHandler(adapter);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}));
|
||||
@@ -196,12 +200,12 @@ public class ByteStreamTargetAdapterTests {
|
||||
@Test
|
||||
public void testStreamWriteBetweenDispatches() throws IOException {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
MessageChannel channel = new SimpleChannel();
|
||||
ByteStreamTargetAdapter adapter = new ByteStreamTargetAdapter(stream);
|
||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||
retriever.setMaxMessagesPerTask(2);
|
||||
retriever.setReceiveTimeout(0);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(retriever);
|
||||
DispatcherPolicy dispatcherPolicy = new DispatcherPolicy();
|
||||
dispatcherPolicy.setMaxMessagesPerTask(2);
|
||||
dispatcherPolicy.setReceiveTimeout(0);
|
||||
SimpleChannel channel = new SimpleChannel(dispatcherPolicy);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
||||
dispatcherTask.addHandler(adapter);
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {1,2,3}));
|
||||
channel.send(new GenericMessage<byte[]>(new byte[] {4,5,6}));
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.SimpleChannel;
|
||||
import org.springframework.integration.dispatcher.ChannelPollingMessageRetriever;
|
||||
import org.springframework.integration.dispatcher.DispatcherPolicy;
|
||||
import org.springframework.integration.dispatcher.DispatcherTask;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
@@ -87,11 +87,11 @@ public class CharacterStreamTargetAdapterTests {
|
||||
@Test
|
||||
public void testMaxMessagesPerTaskSameAsMessageCount() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
MessageChannel channel = new SimpleChannel();
|
||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||
retriever.setMaxMessagesPerTask(2);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(retriever);
|
||||
DispatcherPolicy dispatcherPolicy = new DispatcherPolicy();
|
||||
dispatcherPolicy.setMaxMessagesPerTask(2);
|
||||
SimpleChannel channel = new SimpleChannel(dispatcherPolicy);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
||||
dispatcherTask.addHandler(adapter);
|
||||
channel.send(new StringMessage("foo"));
|
||||
channel.send(new StringMessage("bar"));
|
||||
@@ -103,13 +103,13 @@ public class CharacterStreamTargetAdapterTests {
|
||||
@Test
|
||||
public void testMaxMessagesPerTaskExceedsMessageCountWithAppendedNewLines() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
MessageChannel channel = new SimpleChannel();
|
||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
||||
DispatcherPolicy dispatcherPolicy = new DispatcherPolicy();
|
||||
dispatcherPolicy.setMaxMessagesPerTask(10);
|
||||
dispatcherPolicy.setReceiveTimeout(0);
|
||||
SimpleChannel channel = new SimpleChannel(dispatcherPolicy);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
||||
adapter.setShouldAppendNewLine(true);
|
||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||
retriever.setReceiveTimeout(0);
|
||||
retriever.setMaxMessagesPerTask(10);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(retriever);
|
||||
dispatcherTask.addHandler(adapter);
|
||||
channel.send(new StringMessage("foo"));
|
||||
channel.send(new StringMessage("bar"));
|
||||
@@ -137,12 +137,12 @@ public class CharacterStreamTargetAdapterTests {
|
||||
@Test
|
||||
public void testTwoNonStringObjectWithOutNewLines() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
MessageChannel channel = new SimpleChannel();
|
||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||
retriever.setReceiveTimeout(0);
|
||||
retriever.setMaxMessagesPerTask(2);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(retriever);
|
||||
DispatcherPolicy dispatcherPolicy = new DispatcherPolicy();
|
||||
dispatcherPolicy.setReceiveTimeout(0);
|
||||
dispatcherPolicy.setMaxMessagesPerTask(2);
|
||||
SimpleChannel channel = new SimpleChannel(dispatcherPolicy);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
||||
dispatcherTask.addHandler(adapter);
|
||||
TestObject testObject1 = new TestObject("foo");
|
||||
TestObject testObject2 = new TestObject("bar");
|
||||
@@ -156,13 +156,13 @@ public class CharacterStreamTargetAdapterTests {
|
||||
@Test
|
||||
public void testTwoNonStringObjectWithNewLines() {
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
MessageChannel channel = new SimpleChannel();
|
||||
CharacterStreamTargetAdapter adapter = new CharacterStreamTargetAdapter(stream);
|
||||
DispatcherPolicy dispatcherPolicy = new DispatcherPolicy();
|
||||
dispatcherPolicy.setReceiveTimeout(0);
|
||||
dispatcherPolicy.setMaxMessagesPerTask(2);
|
||||
SimpleChannel channel = new SimpleChannel(dispatcherPolicy);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(channel);
|
||||
adapter.setShouldAppendNewLine(true);
|
||||
ChannelPollingMessageRetriever retriever = new ChannelPollingMessageRetriever(channel);
|
||||
retriever.setReceiveTimeout(0);
|
||||
retriever.setMaxMessagesPerTask(2);
|
||||
DispatcherTask dispatcherTask = new DispatcherTask(retriever);
|
||||
dispatcherTask.addHandler(adapter);
|
||||
TestObject testObject1 = new TestObject("foo");
|
||||
TestObject testObject2 = new TestObject("bar");
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.integration.adapter.PollingSourceAdapter;
|
||||
import org.springframework.integration.adapter.SourceAdapter;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.SimpleChannel;
|
||||
import org.springframework.integration.dispatcher.DispatcherPolicy;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.ErrorMessage;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
@@ -127,8 +128,8 @@ public class MessageBusTests {
|
||||
|
||||
@Test
|
||||
public void testBothHandlersReceivePublishSubscribeMessage() {
|
||||
SimpleChannel inputChannel = new SimpleChannel();
|
||||
inputChannel.setPublishSubscribe(true);
|
||||
DispatcherPolicy dispatcherPolicy = new DispatcherPolicy(true);
|
||||
SimpleChannel inputChannel = new SimpleChannel(dispatcherPolicy);
|
||||
SimpleChannel outputChannel1 = new SimpleChannel();
|
||||
SimpleChannel outputChannel2 = new SimpleChannel();
|
||||
MessageHandler handler1 = new MessageHandler() {
|
||||
|
||||
@@ -76,8 +76,7 @@ public class DefaultMessageDispatcherTests {
|
||||
final CountDownLatch latch = new CountDownLatch(2);
|
||||
MessageHandler handler1 = TestHandlers.countingCountDownHandler(counter1, latch);
|
||||
MessageHandler handler2 = TestHandlers.countingCountDownHandler(counter2, latch);
|
||||
SimpleChannel channel = new SimpleChannel();
|
||||
channel.setPublishSubscribe(true);
|
||||
SimpleChannel channel = new SimpleChannel(new DispatcherPolicy(true));
|
||||
channel.send(new StringMessage(1, "test"));
|
||||
DefaultMessageDispatcher dispatcher = new DefaultMessageDispatcher(channel);
|
||||
dispatcher.addHandler(new ConcurrentHandler(handler1, 1, 1));
|
||||
@@ -123,8 +122,7 @@ public class DefaultMessageDispatcherTests {
|
||||
MessageHandler handler1 = TestHandlers.countingCountDownHandler(counter1, latch);
|
||||
MessageHandler handler2 = TestHandlers.countingCountDownHandler(counter2, latch);
|
||||
MessageHandler handler3 = TestHandlers.countingCountDownHandler(counter3, latch);
|
||||
SimpleChannel channel = new SimpleChannel();
|
||||
channel.setPublishSubscribe(true);
|
||||
SimpleChannel channel = new SimpleChannel(new DispatcherPolicy(true));
|
||||
channel.send(new StringMessage(1, "test"));
|
||||
DefaultMessageDispatcher dispatcher = new DefaultMessageDispatcher(channel);
|
||||
dispatcher.addHandler(new ConcurrentHandler(handler1, 1, 1));
|
||||
@@ -158,12 +156,11 @@ public class DefaultMessageDispatcherTests {
|
||||
MessageHandler handler1 = TestHandlers.countingCountDownHandler(counter1, latch);
|
||||
MessageHandler handler2 = TestHandlers.countingCountDownHandler(counter2, latch);
|
||||
MessageHandler handler3 = TestHandlers.countingCountDownHandler(counter3, latch);
|
||||
SimpleChannel channel = new SimpleChannel();
|
||||
channel.setPublishSubscribe(true);
|
||||
SimpleChannel channel = new SimpleChannel(new DispatcherPolicy(true));
|
||||
channel.getDispatcherPolicy().setRejectionLimit(2);
|
||||
channel.getDispatcherPolicy().setRetryInterval(3);
|
||||
channel.send(new StringMessage(1, "test"));
|
||||
DefaultMessageDispatcher dispatcher = new DefaultMessageDispatcher(channel);
|
||||
dispatcher.setRejectionLimit(2);
|
||||
dispatcher.setRetryInterval(3);
|
||||
dispatcher.addHandler(new ConcurrentHandler(handler1, 1, 1));
|
||||
dispatcher.addHandler(new ConcurrentHandler(handler2, 1, 1) {
|
||||
@Override
|
||||
@@ -192,13 +189,12 @@ public class DefaultMessageDispatcherTests {
|
||||
final CountDownLatch latch = new CountDownLatch(3);
|
||||
MessageHandler handler1 = TestHandlers.countingCountDownHandler(counter1, latch);
|
||||
MessageHandler handler2 = TestHandlers.countingCountDownHandler(counter2, latch);
|
||||
SimpleChannel channel = new SimpleChannel();
|
||||
channel.setPublishSubscribe(true);
|
||||
SimpleChannel channel = new SimpleChannel(new DispatcherPolicy(true));
|
||||
channel.getDispatcherPolicy().setRejectionLimit(2);
|
||||
channel.getDispatcherPolicy().setRetryInterval(3);
|
||||
channel.getDispatcherPolicy().setShouldFailOnRejectionLimit(false);
|
||||
channel.send(new StringMessage(1, "test"));
|
||||
DefaultMessageDispatcher dispatcher = new DefaultMessageDispatcher(channel);
|
||||
dispatcher.setRejectionLimit(2);
|
||||
dispatcher.setRetryInterval(3);
|
||||
dispatcher.setShouldFailOnRejectionLimit(false);
|
||||
dispatcher.addHandler(handler1);
|
||||
dispatcher.addHandler(new MessageHandler() {
|
||||
public Message<?> handle(Message<?> message) {
|
||||
@@ -215,30 +211,16 @@ public class DefaultMessageDispatcherTests {
|
||||
|
||||
@Test
|
||||
public void testNonBroadcastingDispatcherReachesRejectionLimitAndShouldFail() throws InterruptedException {
|
||||
final AtomicInteger counter1 = new AtomicInteger();
|
||||
final AtomicInteger counter2 = new AtomicInteger();
|
||||
final CountDownLatch latch = new CountDownLatch(4);
|
||||
MessageHandler handler1 = TestHandlers.countingCountDownHandler(counter1, latch);
|
||||
MessageHandler handler2 = TestHandlers.countingCountDownHandler(counter2, latch);
|
||||
SimpleChannel channel = new SimpleChannel();
|
||||
MessageHandler handler1 = TestHandlers.rejectingCountDownHandler(latch);
|
||||
MessageHandler handler2 = TestHandlers.rejectingCountDownHandler(latch);
|
||||
SimpleChannel channel = new SimpleChannel(new DispatcherPolicy(false));
|
||||
channel.send(new StringMessage(1, "test"));
|
||||
DefaultMessageDispatcher dispatcher = new DefaultMessageDispatcher(channel);
|
||||
dispatcher.setRejectionLimit(2);
|
||||
dispatcher.setRetryInterval(3);
|
||||
dispatcher.addHandler(new ConcurrentHandler(handler1, 1, 1) {
|
||||
@Override
|
||||
public Message<?> handle(Message<?> message) {
|
||||
latch.countDown();
|
||||
throw new MessageHandlerRejectedExecutionException();
|
||||
}
|
||||
});
|
||||
dispatcher.addHandler(new ConcurrentHandler(handler2, 1, 1) {
|
||||
@Override
|
||||
public Message<?> handle(Message<?> message) {
|
||||
latch.countDown();
|
||||
throw new MessageHandlerRejectedExecutionException();
|
||||
}
|
||||
});
|
||||
channel.getDispatcherPolicy().setRejectionLimit(2);
|
||||
channel.getDispatcherPolicy().setRetryInterval(3);
|
||||
dispatcher.addHandler(handler1);
|
||||
dispatcher.addHandler(handler2);
|
||||
SimpleChannel errorChannel = new SimpleChannel();
|
||||
SimpleMessagingTaskScheduler scheduler = new SimpleMessagingTaskScheduler();
|
||||
scheduler.setErrorHandler(new MessagePublishingErrorHandler(errorChannel));
|
||||
@@ -262,11 +244,11 @@ public class DefaultMessageDispatcherTests {
|
||||
MessageHandler handler1 = TestHandlers.countingCountDownHandler(counter1, latch);
|
||||
MessageHandler handler2 = TestHandlers.countingCountDownHandler(counter2, latch);
|
||||
SimpleChannel channel = new SimpleChannel();
|
||||
channel.getDispatcherPolicy().setRejectionLimit(2);
|
||||
channel.getDispatcherPolicy().setRetryInterval(3);
|
||||
channel.getDispatcherPolicy().setShouldFailOnRejectionLimit(false);
|
||||
channel.send(new StringMessage(1, "test"));
|
||||
DefaultMessageDispatcher dispatcher = new DefaultMessageDispatcher(channel);
|
||||
dispatcher.setRejectionLimit(2);
|
||||
dispatcher.setRetryInterval(3);
|
||||
dispatcher.setShouldFailOnRejectionLimit(false);
|
||||
dispatcher.addHandler(new ConcurrentHandler(handler1, 1, 1) {
|
||||
@Override
|
||||
public Message<?> handle(Message<?> message) {
|
||||
@@ -304,12 +286,13 @@ public class DefaultMessageDispatcherTests {
|
||||
MessageHandler handler1 = TestHandlers.countingCountDownHandler(counter1, latch);
|
||||
MessageHandler handler2 = TestHandlers.countingCountDownHandler(counter2, latch);
|
||||
MessageHandler handler3 = TestHandlers.countingCountDownHandler(counter3, latch);
|
||||
SimpleChannel channel = new SimpleChannel();
|
||||
DispatcherPolicy dispatcherPolicy = new DispatcherPolicy();
|
||||
dispatcherPolicy.setRejectionLimit(2);
|
||||
dispatcherPolicy.setRetryInterval(3);
|
||||
dispatcherPolicy.setShouldFailOnRejectionLimit(false);
|
||||
SimpleChannel channel = new SimpleChannel(dispatcherPolicy);
|
||||
channel.send(new StringMessage(1, "test"));
|
||||
DefaultMessageDispatcher dispatcher = new DefaultMessageDispatcher(channel);
|
||||
dispatcher.setRejectionLimit(2);
|
||||
dispatcher.setRetryInterval(3);
|
||||
dispatcher.setShouldFailOnRejectionLimit(false);
|
||||
dispatcher.addHandler(new ConcurrentHandler(handler1, 1, 1) {
|
||||
@Override
|
||||
public Message<?> handle(Message<?> message) {
|
||||
@@ -357,13 +340,13 @@ public class DefaultMessageDispatcherTests {
|
||||
final CountDownLatch latch = new CountDownLatch(8);
|
||||
MessageHandler handler1 = TestHandlers.countingCountDownHandler(counter1, latch);
|
||||
MessageHandler handler2 = TestHandlers.countingCountDownHandler(counter2, latch);
|
||||
SimpleChannel channel = new SimpleChannel();
|
||||
channel.setPublishSubscribe(true);
|
||||
DispatcherPolicy dispatcherPolicy = new DispatcherPolicy(true);
|
||||
dispatcherPolicy.setRejectionLimit(5);
|
||||
dispatcherPolicy.setRetryInterval(3);
|
||||
dispatcherPolicy.setShouldFailOnRejectionLimit(false);
|
||||
SimpleChannel channel = new SimpleChannel(dispatcherPolicy);
|
||||
channel.send(new StringMessage(1, "test"));
|
||||
DefaultMessageDispatcher dispatcher = new DefaultMessageDispatcher(channel);
|
||||
dispatcher.setRejectionLimit(5);
|
||||
dispatcher.setRetryInterval(3);
|
||||
dispatcher.setShouldFailOnRejectionLimit(false);
|
||||
dispatcher.addHandler(new ConcurrentHandler(handler1, 1, 1) {
|
||||
@Override
|
||||
public Message<?> handle(Message<?> message) {
|
||||
@@ -471,8 +454,7 @@ public class DefaultMessageDispatcherTests {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
MessageHandler handler1 = TestHandlers.countingCountDownHandler(counter1, latch);
|
||||
MessageHandler handler2 = TestHandlers.countingCountDownHandler(counter2, latch);
|
||||
SimpleChannel channel = new SimpleChannel();
|
||||
channel.setPublishSubscribe(true);
|
||||
SimpleChannel channel = new SimpleChannel(new DispatcherPolicy(true));
|
||||
channel.send(new StringMessage(1, "test"));
|
||||
DefaultMessageDispatcher dispatcher = new DefaultMessageDispatcher(channel);
|
||||
DefaultMessageEndpoint endpoint1 = new DefaultMessageEndpoint();
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.integration.handler;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.springframework.integration.dispatcher.MessageHandlerRejectedExecutionException;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
/**
|
||||
@@ -40,6 +41,30 @@ public abstract class TestHandlers {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link MessageHandler} that throws a {@link MessageHandlerRejectedExecutionException}.
|
||||
*/
|
||||
public final static MessageHandler rejectingHandler() {
|
||||
return new MessageHandler() {
|
||||
public Message<?> handle(Message<?> message) {
|
||||
throw new MessageHandlerRejectedExecutionException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link MessageHandler} that counts down on the provided latch and
|
||||
* then throws a {@link MessageHandlerRejectedExecutionException}.
|
||||
*/
|
||||
public final static MessageHandler rejectingCountDownHandler(final CountDownLatch latch) {
|
||||
return new MessageHandler() {
|
||||
public Message<?> handle(Message<?> message) {
|
||||
latch.countDown();
|
||||
throw new MessageHandlerRejectedExecutionException();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link MessageHandler} that increments the provided counter.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user