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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user