Browse Source
@EnableWebSocketMessageBroker message channel configuration can now be customized via WebSocketMessageBrokerConfigurer. It is necessary to make this easy and even required as part of the basic configuration since by default the message channels are backed by a thread pool of size 1, not suitable for production use. Issue: SPR-11023pull/422/head
Rossen Stoyanchev
11 years ago
10 changed files with 426 additions and 33 deletions
@ -0,0 +1,74 @@
@@ -0,0 +1,74 @@
|
||||
/* |
||||
* Copyright 2002-2013 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.messaging.simp.config; |
||||
|
||||
import org.springframework.messaging.support.channel.ChannelInterceptor; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* A registration class for customizing the configuration for a |
||||
* {@link org.springframework.messaging.MessageChannel}. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
* @since 4.0 |
||||
*/ |
||||
public class ChannelRegistration { |
||||
|
||||
private TaskExecutorRegistration taskExecutorRegistration; |
||||
|
||||
private List<ChannelInterceptor> interceptors = new ArrayList<ChannelInterceptor>(); |
||||
|
||||
|
||||
/** |
||||
* Configure properties of the ThreadPoolTaskExecutor backing the message channel. |
||||
*/ |
||||
public TaskExecutorRegistration taskExecutor() { |
||||
this.taskExecutorRegistration = new TaskExecutorRegistration(); |
||||
return this.taskExecutorRegistration; |
||||
} |
||||
|
||||
/** |
||||
* Configure interceptors for the message channel. |
||||
*/ |
||||
public ChannelRegistration setInterceptors(ChannelInterceptor... interceptors) { |
||||
if (interceptors != null) { |
||||
this.interceptors.addAll(Arrays.asList(interceptors)); |
||||
} |
||||
return this; |
||||
} |
||||
|
||||
|
||||
protected boolean hasTaskExecutor() { |
||||
return (this.taskExecutorRegistration != null); |
||||
} |
||||
|
||||
protected TaskExecutorRegistration getTaskExecutorRegistration() { |
||||
return this.taskExecutorRegistration; |
||||
} |
||||
|
||||
protected boolean hasInterceptors() { |
||||
return !this.interceptors.isEmpty(); |
||||
} |
||||
|
||||
protected List<ChannelInterceptor> getInterceptors() { |
||||
return this.interceptors; |
||||
} |
||||
} |
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
/* |
||||
* Copyright 2002-2013 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.messaging.simp.config; |
||||
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
||||
|
||||
/** |
||||
* A registration class for customizing the properties of {@link ThreadPoolTaskExecutor}. |
||||
* |
||||
* @author Rossen Stoyanchev |
||||
* @since 4.0 |
||||
*/ |
||||
public class TaskExecutorRegistration { |
||||
|
||||
private int corePoolSize = 1; |
||||
|
||||
private int maxPoolSize = Integer.MAX_VALUE; |
||||
|
||||
private int keepAliveSeconds = 60; |
||||
|
||||
private int queueCapacity = Integer.MAX_VALUE; |
||||
|
||||
|
||||
/** |
||||
* Set the ThreadPoolExecutor's core pool size. |
||||
* Default is 1. |
||||
*/ |
||||
public TaskExecutorRegistration corePoolSize(int corePoolSize) { |
||||
this.corePoolSize = corePoolSize; |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* Set the ThreadPoolExecutor's maximum pool size. |
||||
* Default is {@code Integer.MAX_VALUE}. |
||||
*/ |
||||
public TaskExecutorRegistration maxPoolSize(int maxPoolSize) { |
||||
this.maxPoolSize = maxPoolSize; |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* Set the ThreadPoolExecutor's keep-alive seconds. |
||||
* Default is 60. |
||||
*/ |
||||
public TaskExecutorRegistration keepAliveSeconds(int keepAliveSeconds) { |
||||
this.keepAliveSeconds = keepAliveSeconds; |
||||
return this; |
||||
} |
||||
|
||||
/** |
||||
* Set the capacity for the ThreadPoolExecutor's BlockingQueue. |
||||
* Default is {@code Integer.MAX_VALUE}. |
||||
* <p>Any positive value will lead to a LinkedBlockingQueue instance; |
||||
* any other value will lead to a SynchronousQueue instance. |
||||
* @see java.util.concurrent.LinkedBlockingQueue |
||||
* @see java.util.concurrent.SynchronousQueue |
||||
*/ |
||||
public TaskExecutorRegistration queueCapacity(int queueCapacity) { |
||||
this.queueCapacity = queueCapacity; |
||||
return this; |
||||
} |
||||
|
||||
protected ThreadPoolTaskExecutor getTaskExecutor() { |
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
||||
executor.setCorePoolSize(this.corePoolSize); |
||||
executor.setMaxPoolSize(this.maxPoolSize); |
||||
executor.setKeepAliveSeconds(this.keepAliveSeconds); |
||||
executor.setQueueCapacity(this.queueCapacity); |
||||
return executor; |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue