Skip to content

Commit b3eefa2

Browse files
committed
Documented units for send-time limit and buffer-size limit
Issue: SPR-13753 (cherry picked from commit 747863d)
1 parent 5ac42bf commit b3eefa2

File tree

2 files changed

+51
-29
lines changed

2 files changed

+51
-29
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecorator.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
* only one thread can send messages at a time.
3636
*
3737
* <p>If a send is slow, subsequent attempts to send more messages from a different
38-
* thread will fail to acquire the flushLock and the messages will be buffered instead --
39-
* at that time the specified buffer size limit and send time limit will be checked
40-
* and the session closed if the limits are exceeded.
38+
* thread will fail to acquire the flush lock and the messages will be buffered
39+
* instead: At that time, the specified buffer-size limit and send-time limit will
40+
* be checked and the session closed if the limits are exceeded.
4141
*
4242
* @author Rossen Stoyanchev
4343
* @since 4.0.3
@@ -69,6 +69,12 @@ public class ConcurrentWebSocketSessionDecorator extends WebSocketSessionDecorat
6969
private final Lock closeLock = new ReentrantLock();
7070

7171

72+
/**
73+
* Create a new {@code ConcurrentWebSocketSessionDecorator}.
74+
* @param delegate the {@code WebSocketSession} to delegate to
75+
* @param sendTimeLimit the send-time limit (milliseconds)
76+
* @param bufferSizeLimit the buffer-size limit (number of bytes)
77+
*/
7278
public ConcurrentWebSocketSessionDecorator(WebSocketSession delegate, int sendTimeLimit, int bufferSizeLimit) {
7379
super(delegate);
7480
this.sendTimeLimit = sendTimeLimit;

spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java

+42-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -52,22 +52,20 @@
5252

5353
/**
5454
* An implementation of {@link WebSocketHandler} that delegates incoming WebSocket
55-
* messages to a {@link SubProtocolHandler} along with a {@link MessageChannel} to
56-
* which the sub-protocol handler can send messages from WebSocket clients to
57-
* the application.
58-
* <p>
59-
* Also an implementation of {@link MessageHandler} that finds the WebSocket
60-
* session associated with the {@link Message} and passes it, along with the message,
61-
* to the sub-protocol handler to send messages from the application back to the
62-
* client.
55+
* messages to a {@link SubProtocolHandler} along with a {@link MessageChannel} to which
56+
* the sub-protocol handler can send messages from WebSocket clients to the application.
57+
*
58+
* <p>Also an implementation of {@link MessageHandler} that finds the WebSocket session
59+
* associated with the {@link Message} and passes it, along with the message, to the
60+
* sub-protocol handler to send messages from the application back to the client.
6361
*
6462
* @author Rossen Stoyanchev
6563
* @author Andy Wilkinson
6664
* @author Artem Bilan
6765
* @since 4.0
6866
*/
69-
public class SubProtocolWebSocketHandler implements WebSocketHandler,
70-
SubProtocolCapable, MessageHandler, SmartLifecycle {
67+
public class SubProtocolWebSocketHandler
68+
implements WebSocketHandler, SubProtocolCapable, MessageHandler, SmartLifecycle {
7169

7270
/**
7371
* Sessions connected to this handler use a sub-protocol. Hence we expect to
@@ -109,9 +107,14 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
109107
private volatile boolean running = false;
110108

111109

110+
/**
111+
* Create a new {@code SubProtocolWebSocketHandler} for the given inbound and outbound channels.
112+
* @param clientInboundChannel the inbound {@code MessageChannel}
113+
* @param clientOutboundChannel the outbound {@code MessageChannel}
114+
*/
112115
public SubProtocolWebSocketHandler(MessageChannel clientInboundChannel, SubscribableChannel clientOutboundChannel) {
113-
Assert.notNull(clientInboundChannel, "ClientInboundChannel must not be null");
114-
Assert.notNull(clientOutboundChannel, "ClientOutboundChannel must not be null");
116+
Assert.notNull(clientInboundChannel, "Inbound MessageChannel must not be null");
117+
Assert.notNull(clientOutboundChannel, "Outbound MessageChannel must not be null");
115118
this.clientInboundChannel = clientInboundChannel;
116119
this.clientOutboundChannel = clientOutboundChannel;
117120
}
@@ -125,7 +128,7 @@ public SubProtocolWebSocketHandler(MessageChannel clientInboundChannel, Subscrib
125128
public void setProtocolHandlers(List<SubProtocolHandler> protocolHandlers) {
126129
this.protocolHandlerLookup.clear();
127130
this.protocolHandlers.clear();
128-
for (SubProtocolHandler handler: protocolHandlers) {
131+
for (SubProtocolHandler handler : protocolHandlers) {
129132
addProtocolHandler(handler);
130133
}
131134
}
@@ -134,7 +137,6 @@ public List<SubProtocolHandler> getProtocolHandlers() {
134137
return new ArrayList<SubProtocolHandler>(this.protocolHandlers);
135138
}
136139

137-
138140
/**
139141
* Register a sub-protocol handler.
140142
*/
@@ -174,7 +176,7 @@ public void setDefaultProtocolHandler(SubProtocolHandler defaultProtocolHandler)
174176
}
175177

176178
/**
177-
* @return the default sub-protocol handler to use
179+
* Return the default sub-protocol handler to use.
178180
*/
179181
public SubProtocolHandler getDefaultProtocolHandler() {
180182
return this.defaultProtocolHandler;
@@ -187,23 +189,44 @@ public List<String> getSubProtocols() {
187189
return new ArrayList<String>(this.protocolHandlerLookup.keySet());
188190
}
189191

190-
192+
/**
193+
* Specify the send-time limit (milliseconds).
194+
* @see ConcurrentWebSocketSessionDecorator
195+
*/
191196
public void setSendTimeLimit(int sendTimeLimit) {
192197
this.sendTimeLimit = sendTimeLimit;
193198
}
194199

200+
/**
201+
* Return the send-time limit (milliseconds).
202+
*/
195203
public int getSendTimeLimit() {
196204
return this.sendTimeLimit;
197205
}
198206

207+
/**
208+
* Specify the buffer-size limit (number of bytes).
209+
* @see ConcurrentWebSocketSessionDecorator
210+
*/
199211
public void setSendBufferSizeLimit(int sendBufferSizeLimit) {
200212
this.sendBufferSizeLimit = sendBufferSizeLimit;
201213
}
202214

215+
/**
216+
* Return the buffer-size limit (number of bytes).
217+
*/
203218
public int getSendBufferSizeLimit() {
204-
return sendBufferSizeLimit;
219+
return this.sendBufferSizeLimit;
220+
}
221+
222+
/**
223+
* Return a String describing internal state and counters.
224+
*/
225+
public String getStatsInfo() {
226+
return this.stats.toString();
205227
}
206228

229+
207230
@Override
208231
public boolean isAutoStartup() {
209232
return true;
@@ -221,14 +244,6 @@ public final boolean isRunning() {
221244
}
222245
}
223246

224-
/**
225-
* Return a String describing internal state and counters.
226-
*/
227-
public String getStatsInfo() {
228-
return this.stats.toString();
229-
}
230-
231-
232247
@Override
233248
public final void start() {
234249
Assert.isTrue(this.defaultProtocolHandler != null || !this.protocolHandlers.isEmpty(), "No handlers");
@@ -262,6 +277,7 @@ public final void stop(Runnable callback) {
262277
}
263278
}
264279

280+
265281
@Override
266282
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
267283
this.stats.incrementSessionCount(session);

0 commit comments

Comments
 (0)