Merge pull request #503 from sdeleuze/SPR-11623
This commit is contained in:
commit
ea762b2c74
|
|
@ -176,10 +176,15 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
|
|||
ParserContext parserCxt, Object source) {
|
||||
|
||||
RootBeanDefinition executorDef = null;
|
||||
|
||||
if (channelElement != null) {
|
||||
if (channelElement == null) {
|
||||
executorDef = getDefaultExecutorBeanDefinition(channelName);
|
||||
}
|
||||
else {
|
||||
Element executor = DomUtils.getChildElementByTagName(channelElement, "executor");
|
||||
if (executor != null) {
|
||||
if (executor == null) {
|
||||
executorDef = getDefaultExecutorBeanDefinition(channelName);
|
||||
}
|
||||
else {
|
||||
executorDef = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
|
||||
String attrValue = executor.getAttribute("core-pool-size");
|
||||
if (!StringUtils.isEmpty(attrValue)) {
|
||||
|
|
@ -199,22 +204,16 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (!channelName.equals("brokerChannel")) {
|
||||
executorDef = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
|
||||
executorDef.getPropertyValues().add("corePoolSize", Runtime.getRuntime().availableProcessors() * 2);
|
||||
executorDef.getPropertyValues().add("maxPoolSize", Integer.MAX_VALUE);
|
||||
executorDef.getPropertyValues().add("queueCapacity", Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
ConstructorArgumentValues values = new ConstructorArgumentValues();
|
||||
ConstructorArgumentValues argValues = new ConstructorArgumentValues();
|
||||
if (executorDef != null) {
|
||||
executorDef.getPropertyValues().add("threadNamePrefix", channelName + "-");
|
||||
String executorName = channelName + "Executor";
|
||||
registerBeanDefByName(executorName, executorDef, parserCxt, source);
|
||||
values.addIndexedArgumentValue(0, new RuntimeBeanReference(executorName));
|
||||
argValues.addIndexedArgumentValue(0, new RuntimeBeanReference(executorName));
|
||||
}
|
||||
|
||||
RootBeanDefinition channelDef = new RootBeanDefinition(ExecutorSubscribableChannel.class, values, null);
|
||||
RootBeanDefinition channelDef = new RootBeanDefinition(ExecutorSubscribableChannel.class, argValues, null);
|
||||
|
||||
if (channelElement != null) {
|
||||
Element interceptorsElement = DomUtils.getChildElementByTagName(channelElement, "interceptors");
|
||||
|
|
@ -226,6 +225,17 @@ class MessageBrokerBeanDefinitionParser implements BeanDefinitionParser {
|
|||
return new RuntimeBeanReference(channelName);
|
||||
}
|
||||
|
||||
private RootBeanDefinition getDefaultExecutorBeanDefinition(String channelName) {
|
||||
if (channelName.equals("brokerChannel")) {
|
||||
return null;
|
||||
}
|
||||
RootBeanDefinition executorDef = new RootBeanDefinition(ThreadPoolTaskExecutor.class);
|
||||
executorDef.getPropertyValues().add("corePoolSize", Runtime.getRuntime().availableProcessors() * 2);
|
||||
executorDef.getPropertyValues().add("maxPoolSize", Integer.MAX_VALUE);
|
||||
executorDef.getPropertyValues().add("queueCapacity", Integer.MAX_VALUE);
|
||||
return executorDef;
|
||||
}
|
||||
|
||||
private RuntimeBeanReference registerSubProtocolWebSocketHandler(Element element,
|
||||
RuntimeBeanReference clientInChannel, RuntimeBeanReference clientOutChannel,
|
||||
RuntimeBeanReference userSessionRegistry, ParserContext parserCxt, Object source) {
|
||||
|
|
|
|||
|
|
@ -293,6 +293,17 @@ public class MessageBrokerBeanDefinitionParserTests {
|
|||
testExecutor("brokerChannel", 102, 202, 602);
|
||||
}
|
||||
|
||||
// SPR-11623
|
||||
|
||||
@Test
|
||||
public void customChannelsWithDefaultExecutor() {
|
||||
loadBeanDefinitions("websocket-config-broker-customchannels-default-executor.xml");
|
||||
|
||||
testExecutor("clientInboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60);
|
||||
testExecutor("clientOutboundChannel", Runtime.getRuntime().availableProcessors() * 2, Integer.MAX_VALUE, 60);
|
||||
assertFalse(this.appContext.containsBean("brokerChannelExecutor"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void messageConverters() {
|
||||
loadBeanDefinitions("websocket-config-broker-converters.xml");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:websocket="http://www.springframework.org/schema/websocket"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket-4.0.xsd">
|
||||
|
||||
<websocket:message-broker>
|
||||
<websocket:stomp-endpoint path="/foo"/>
|
||||
<websocket:simple-broker prefix="/topic"/>
|
||||
<websocket:client-inbound-channel>
|
||||
<websocket:interceptors>
|
||||
<ref bean="myInterceptor"/>
|
||||
</websocket:interceptors>
|
||||
</websocket:client-inbound-channel>
|
||||
<websocket:client-outbound-channel>
|
||||
<websocket:interceptors>
|
||||
<ref bean="myInterceptor"/>
|
||||
</websocket:interceptors>
|
||||
</websocket:client-outbound-channel>
|
||||
<websocket:broker-channel>
|
||||
<websocket:interceptors>
|
||||
<ref bean="myInterceptor"/>
|
||||
</websocket:interceptors>
|
||||
</websocket:broker-channel>
|
||||
</websocket:message-broker>
|
||||
|
||||
<bean id="myInterceptor" class="org.springframework.web.socket.config.TestChannelInterceptor"/>
|
||||
|
||||
</beans>
|
||||
Loading…
Reference in New Issue