SimpleChannel now creates a SynchronousQueue if the capacity is less than or equal to 0. SplitterMessageHandlerAdapter exposes a configurable 'sendTimeout' property.

This commit is contained in:
Mark Fisher
2008-01-31 22:04:35 +00:00
parent e3f7bf4681
commit 1f5e7b5756
5 changed files with 55 additions and 43 deletions

View File

@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.TimeUnit;
import org.springframework.integration.dispatcher.DispatcherPolicy;
@@ -46,7 +47,12 @@ public class SimpleChannel extends AbstractMessageChannel {
*/
public SimpleChannel(int capacity, DispatcherPolicy dispatcherPolicy) {
super((dispatcherPolicy != null) ? dispatcherPolicy : new DispatcherPolicy());
this.queue = new LinkedBlockingQueue<Message<?>>(capacity);
if (capacity > 0) {
this.queue = new LinkedBlockingQueue<Message<?>>(capacity);
}
else {
this.queue = new SynchronousQueue<Message<?>>(true);
}
}
/**

View File

@@ -47,6 +47,8 @@ public class SplitterMessageHandlerAdapter extends AbstractMessageHandlerAdapter
private ChannelRegistry channelRegistry;
private long sendTimeout = -1;
public SplitterMessageHandlerAdapter(Object object, Method method, Map<String, ?> attributes) {
Assert.notNull(object, "'object' must not be null");
@@ -63,6 +65,10 @@ public class SplitterMessageHandlerAdapter extends AbstractMessageHandlerAdapter
this.channelRegistry = channelRegistry;
}
public void setSendTimeout(long sendTimeout) {
this.sendTimeout = sendTimeout;
}
@Override
protected Object doHandle(Message message, SimpleMethodInvoker invoker) {
if (method.getParameterTypes().length != 1) {
@@ -139,7 +145,7 @@ public class SplitterMessageHandlerAdapter extends AbstractMessageHandlerAdapter
if (logger.isDebugEnabled()) {
logger.debug("sending message to channel '" + channelName + "'");
}
return channel.send(message);
return (this.sendTimeout < 0) ? channel.send(message) : channel.send(message, this.sendTimeout);
}
}