Skip to content

Commit 0d8e89c

Browse files
committed
spring-projectsGH-8678: Make buffer overflow strategy configurable in IntegrationWebSocketContainer
1 parent 20d5f62 commit 0d8e89c

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

spring-integration-websocket/src/main/java/org/springframework/integration/websocket/IntegrationWebSocketContainer.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.commons.logging.LogFactory;
2929

3030
import org.springframework.beans.factory.DisposableBean;
31+
import org.springframework.lang.NonNull;
3132
import org.springframework.util.Assert;
3233
import org.springframework.util.ReflectionUtils;
3334
import org.springframework.web.socket.CloseStatus;
@@ -67,6 +68,9 @@ public abstract class IntegrationWebSocketContainer implements DisposableBean {
6768

6869
public static final int DEFAULT_SEND_BUFFER_SIZE = 512 * 1024;
6970

71+
public static final ConcurrentWebSocketSessionDecorator.OverflowStrategy DEFAULT_SEND_BUFFER_OVERFLOW_STRATEGY =
72+
ConcurrentWebSocketSessionDecorator.OverflowStrategy.TERMINATE;
73+
7074
protected final Log logger = LogFactory.getLog(getClass()); // NOSONAR
7175

7276
protected final Lock lock = new ReentrantLock();
@@ -83,6 +87,10 @@ public abstract class IntegrationWebSocketContainer implements DisposableBean {
8387

8488
private int sendBufferSizeLimit = DEFAULT_SEND_BUFFER_SIZE;
8589

90+
@NonNull
91+
private ConcurrentWebSocketSessionDecorator.OverflowStrategy sendBufferOverflowStrategy =
92+
DEFAULT_SEND_BUFFER_OVERFLOW_STRATEGY;
93+
8694
public void setSendTimeLimit(int sendTimeLimit) {
8795
this.sendTimeLimit = sendTimeLimit;
8896
}
@@ -91,6 +99,24 @@ public void setSendBufferSizeLimit(int sendBufferSizeLimit) {
9199
this.sendBufferSizeLimit = sendBufferSizeLimit;
92100
}
93101

102+
/**
103+
* Set the send buffer overflow strategy.
104+
* <p>
105+
* Concurrently generated outbound messages are buffered if sending is slow.
106+
* This strategy determines the behavior when the buffer has reached the limit
107+
* configured with {@link #setSendBufferSizeLimit}.
108+
* <p>
109+
* By default, the session associated with the culpable message is terminated.
110+
*
111+
* @param overflowStrategy The overflow strategy to use (see {@link ConcurrentWebSocketSessionDecorator.OverflowStrategy}).
112+
*
113+
* @see ConcurrentWebSocketSessionDecorator
114+
*/
115+
public void setSendBufferOverflowStrategy(@NonNull ConcurrentWebSocketSessionDecorator.OverflowStrategy overflowStrategy) {
116+
Assert.notNull(overflowStrategy, "Overflow strategy must not be null");
117+
this.sendBufferOverflowStrategy = overflowStrategy;
118+
}
119+
94120
public void setMessageListener(WebSocketListener messageListener) {
95121
Assert.state(this.messageListener == null || this.messageListener.equals(messageListener),
96122
"'messageListener' is already configured");
@@ -190,7 +216,8 @@ public void afterConnectionEstablished(WebSocketSession sessionToDecorate)
190216
WebSocketSession session =
191217
new ConcurrentWebSocketSessionDecorator(sessionToDecorate,
192218
IntegrationWebSocketContainer.this.sendTimeLimit,
193-
IntegrationWebSocketContainer.this.sendBufferSizeLimit);
219+
IntegrationWebSocketContainer.this.sendBufferSizeLimit,
220+
IntegrationWebSocketContainer.this.sendBufferOverflowStrategy);
194221

195222
IntegrationWebSocketContainer.this.sessions.put(session.getId(), session);
196223
if (IntegrationWebSocketContainer.this.logger.isDebugEnabled()) {

0 commit comments

Comments
 (0)