29
29
30
30
import org .springframework .beans .factory .DisposableBean ;
31
31
import org .springframework .lang .NonNull ;
32
+ import org .springframework .lang .Nullable ;
32
33
import org .springframework .util .Assert ;
33
34
import org .springframework .util .ReflectionUtils ;
34
35
import org .springframework .web .socket .CloseStatus ;
56
57
*
57
58
* @author Artem Bilan
58
59
* @author Gary Russell
60
+ * @author Julian Koch
59
61
*
60
62
* @since 4.1
61
63
*
@@ -68,9 +70,6 @@ public abstract class IntegrationWebSocketContainer implements DisposableBean {
68
70
69
71
public static final int DEFAULT_SEND_BUFFER_SIZE = 512 * 1024 ;
70
72
71
- public static final ConcurrentWebSocketSessionDecorator .OverflowStrategy DEFAULT_SEND_BUFFER_OVERFLOW_STRATEGY =
72
- ConcurrentWebSocketSessionDecorator .OverflowStrategy .TERMINATE ;
73
-
74
73
protected final Log logger = LogFactory .getLog (getClass ()); // NOSONAR
75
74
76
75
protected final Lock lock = new ReentrantLock ();
@@ -87,9 +86,8 @@ public abstract class IntegrationWebSocketContainer implements DisposableBean {
87
86
88
87
private int sendBufferSizeLimit = DEFAULT_SEND_BUFFER_SIZE ;
89
88
90
- @ NonNull
91
- private ConcurrentWebSocketSessionDecorator .OverflowStrategy sendBufferOverflowStrategy =
92
- DEFAULT_SEND_BUFFER_OVERFLOW_STRATEGY ;
89
+ @ Nullable
90
+ private ConcurrentWebSocketSessionDecorator .OverflowStrategy sendBufferOverflowStrategy ;
93
91
94
92
public void setSendTimeLimit (int sendTimeLimit ) {
95
93
this .sendTimeLimit = sendTimeLimit ;
@@ -101,19 +99,14 @@ public void setSendBufferSizeLimit(int sendBufferSizeLimit) {
101
99
102
100
/**
103
101
* Set the send buffer overflow strategy.
104
- * <p>
105
- * Concurrently generated outbound messages are buffered if sending is slow.
102
+ * <p>Concurrently generated outbound messages are buffered if sending is slow.
106
103
* This strategy determines the behavior when the buffer has reached the limit
107
104
* 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
- *
105
+ * @param overflowStrategy The overflow strategy to use (see {@link ConcurrentWebSocketSessionDecorator.OverflowStrategy}),
106
+ * or {@code null} to use the default as specified by {@link ConcurrentWebSocketSessionDecorator}.
113
107
* @see ConcurrentWebSocketSessionDecorator
114
108
*/
115
- public void setSendBufferOverflowStrategy (@ NonNull ConcurrentWebSocketSessionDecorator .OverflowStrategy overflowStrategy ) {
116
- Assert .notNull (overflowStrategy , "Overflow strategy must not be null" );
109
+ public void setSendBufferOverflowStrategy (@ Nullable ConcurrentWebSocketSessionDecorator .OverflowStrategy overflowStrategy ) {
117
110
this .sendBufferOverflowStrategy = overflowStrategy ;
118
111
}
119
112
@@ -213,11 +206,7 @@ public List<String> getSubProtocols() {
213
206
public void afterConnectionEstablished (WebSocketSession sessionToDecorate )
214
207
throws Exception { // NOSONAR
215
208
216
- WebSocketSession session =
217
- new ConcurrentWebSocketSessionDecorator (sessionToDecorate ,
218
- IntegrationWebSocketContainer .this .sendTimeLimit ,
219
- IntegrationWebSocketContainer .this .sendBufferSizeLimit ,
220
- IntegrationWebSocketContainer .this .sendBufferOverflowStrategy );
209
+ WebSocketSession session = decorateSession (sessionToDecorate );
221
210
222
211
IntegrationWebSocketContainer .this .sessions .put (session .getId (), session );
223
212
if (IntegrationWebSocketContainer .this .logger .isDebugEnabled ()) {
@@ -267,6 +256,16 @@ public boolean supportsPartialMessages() {
267
256
return false ;
268
257
}
269
258
259
+ private WebSocketSession decorateSession (@ NonNull WebSocketSession sessionToDecorate ) {
260
+ return (IntegrationWebSocketContainer .this .sendBufferOverflowStrategy == null
261
+ ? new ConcurrentWebSocketSessionDecorator (sessionToDecorate ,
262
+ IntegrationWebSocketContainer .this .sendTimeLimit ,
263
+ IntegrationWebSocketContainer .this .sendBufferSizeLimit )
264
+ : new ConcurrentWebSocketSessionDecorator (sessionToDecorate ,
265
+ IntegrationWebSocketContainer .this .sendTimeLimit ,
266
+ IntegrationWebSocketContainer .this .sendBufferSizeLimit ,
267
+ IntegrationWebSocketContainer .this .sendBufferOverflowStrategy ));
268
+ }
270
269
}
271
270
272
271
}
0 commit comments