28
28
import org .apache .commons .logging .LogFactory ;
29
29
30
30
import org .springframework .beans .factory .DisposableBean ;
31
+ import org .springframework .lang .NonNull ;
31
32
import org .springframework .util .Assert ;
32
33
import org .springframework .util .ReflectionUtils ;
33
34
import org .springframework .web .socket .CloseStatus ;
@@ -67,6 +68,9 @@ public abstract class IntegrationWebSocketContainer implements DisposableBean {
67
68
68
69
public static final int DEFAULT_SEND_BUFFER_SIZE = 512 * 1024 ;
69
70
71
+ public static final ConcurrentWebSocketSessionDecorator .OverflowStrategy DEFAULT_SEND_BUFFER_OVERFLOW_STRATEGY =
72
+ ConcurrentWebSocketSessionDecorator .OverflowStrategy .TERMINATE ;
73
+
70
74
protected final Log logger = LogFactory .getLog (getClass ()); // NOSONAR
71
75
72
76
protected final Lock lock = new ReentrantLock ();
@@ -83,6 +87,10 @@ public abstract class IntegrationWebSocketContainer implements DisposableBean {
83
87
84
88
private int sendBufferSizeLimit = DEFAULT_SEND_BUFFER_SIZE ;
85
89
90
+ @ NonNull
91
+ private ConcurrentWebSocketSessionDecorator .OverflowStrategy sendBufferOverflowStrategy =
92
+ DEFAULT_SEND_BUFFER_OVERFLOW_STRATEGY ;
93
+
86
94
public void setSendTimeLimit (int sendTimeLimit ) {
87
95
this .sendTimeLimit = sendTimeLimit ;
88
96
}
@@ -91,6 +99,24 @@ public void setSendBufferSizeLimit(int sendBufferSizeLimit) {
91
99
this .sendBufferSizeLimit = sendBufferSizeLimit ;
92
100
}
93
101
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
+
94
120
public void setMessageListener (WebSocketListener messageListener ) {
95
121
Assert .state (this .messageListener == null || this .messageListener .equals (messageListener ),
96
122
"'messageListener' is already configured" );
@@ -190,7 +216,8 @@ public void afterConnectionEstablished(WebSocketSession sessionToDecorate)
190
216
WebSocketSession session =
191
217
new ConcurrentWebSocketSessionDecorator (sessionToDecorate ,
192
218
IntegrationWebSocketContainer .this .sendTimeLimit ,
193
- IntegrationWebSocketContainer .this .sendBufferSizeLimit );
219
+ IntegrationWebSocketContainer .this .sendBufferSizeLimit ,
220
+ IntegrationWebSocketContainer .this .sendBufferOverflowStrategy );
194
221
195
222
IntegrationWebSocketContainer .this .sessions .put (session .getId (), session );
196
223
if (IntegrationWebSocketContainer .this .logger .isDebugEnabled ()) {
0 commit comments