Browse Source

Documented units for send-time limit and buffer-size limit

Issue: SPR-13753
pull/932/head
Juergen Hoeller 10 years ago
parent
commit
747863d503
  1. 12
      spring-websocket/src/main/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecorator.java
  2. 66
      spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java

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

@ -35,9 +35,9 @@ import org.springframework.web.socket.WebSocketSession;
* only one thread can send messages at a time. * only one thread can send messages at a time.
* *
* <p>If a send is slow, subsequent attempts to send more messages from a different * <p>If a send is slow, subsequent attempts to send more messages from a different
* thread will fail to acquire the flushLock and the messages will be buffered instead -- * thread will fail to acquire the flush lock and the messages will be buffered
* at that time the specified buffer size limit and send time limit will be checked * instead: At that time, the specified buffer-size limit and send-time limit will
* and the session closed if the limits are exceeded. * be checked and the session closed if the limits are exceeded.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.0.3 * @since 4.0.3
@ -69,6 +69,12 @@ public class ConcurrentWebSocketSessionDecorator extends WebSocketSessionDecorat
private final Lock closeLock = new ReentrantLock(); private final Lock closeLock = new ReentrantLock();
/**
* Create a new {@code ConcurrentWebSocketSessionDecorator}.
* @param delegate the {@code WebSocketSession} to delegate to
* @param sendTimeLimit the send-time limit (milliseconds)
* @param bufferSizeLimit the buffer-size limit (number of bytes)
*/
public ConcurrentWebSocketSessionDecorator(WebSocketSession delegate, int sendTimeLimit, int bufferSizeLimit) { public ConcurrentWebSocketSessionDecorator(WebSocketSession delegate, int sendTimeLimit, int bufferSizeLimit) {
super(delegate); super(delegate);
this.sendTimeLimit = sendTimeLimit; this.sendTimeLimit = sendTimeLimit;

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

@ -52,22 +52,20 @@ import org.springframework.web.socket.sockjs.transport.session.StreamingSockJsSe
/** /**
* An implementation of {@link WebSocketHandler} that delegates incoming WebSocket * An implementation of {@link WebSocketHandler} that delegates incoming WebSocket
* messages to a {@link SubProtocolHandler} along with a {@link MessageChannel} to * messages to a {@link SubProtocolHandler} along with a {@link MessageChannel} to which
* which the sub-protocol handler can send messages from WebSocket clients to * the sub-protocol handler can send messages from WebSocket clients to the application.
* the application. *
* <p> * <p>Also an implementation of {@link MessageHandler} that finds the WebSocket session
* Also an implementation of {@link MessageHandler} that finds the WebSocket * associated with the {@link Message} and passes it, along with the message, to the
* session associated with the {@link Message} and passes it, along with the message, * sub-protocol handler to send messages from the application back to the client.
* to the sub-protocol handler to send messages from the application back to the
* client.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Artem Bilan * @author Artem Bilan
* @since 4.0 * @since 4.0
*/ */
public class SubProtocolWebSocketHandler implements WebSocketHandler, public class SubProtocolWebSocketHandler
SubProtocolCapable, MessageHandler, SmartLifecycle { implements WebSocketHandler, SubProtocolCapable, MessageHandler, SmartLifecycle {
/** /**
* Sessions connected to this handler use a sub-protocol. Hence we expect to * Sessions connected to this handler use a sub-protocol. Hence we expect to
@ -109,9 +107,14 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
private volatile boolean running = false; private volatile boolean running = false;
/**
* Create a new {@code SubProtocolWebSocketHandler} for the given inbound and outbound channels.
* @param clientInboundChannel the inbound {@code MessageChannel}
* @param clientOutboundChannel the outbound {@code MessageChannel}
*/
public SubProtocolWebSocketHandler(MessageChannel clientInboundChannel, SubscribableChannel clientOutboundChannel) { public SubProtocolWebSocketHandler(MessageChannel clientInboundChannel, SubscribableChannel clientOutboundChannel) {
Assert.notNull(clientInboundChannel, "ClientInboundChannel must not be null"); Assert.notNull(clientInboundChannel, "Inbound MessageChannel must not be null");
Assert.notNull(clientOutboundChannel, "ClientOutboundChannel must not be null"); Assert.notNull(clientOutboundChannel, "Outbound MessageChannel must not be null");
this.clientInboundChannel = clientInboundChannel; this.clientInboundChannel = clientInboundChannel;
this.clientOutboundChannel = clientOutboundChannel; this.clientOutboundChannel = clientOutboundChannel;
} }
@ -125,7 +128,7 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
public void setProtocolHandlers(List<SubProtocolHandler> protocolHandlers) { public void setProtocolHandlers(List<SubProtocolHandler> protocolHandlers) {
this.protocolHandlerLookup.clear(); this.protocolHandlerLookup.clear();
this.protocolHandlers.clear(); this.protocolHandlers.clear();
for (SubProtocolHandler handler: protocolHandlers) { for (SubProtocolHandler handler : protocolHandlers) {
addProtocolHandler(handler); addProtocolHandler(handler);
} }
} }
@ -134,7 +137,6 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
return new ArrayList<SubProtocolHandler>(this.protocolHandlers); return new ArrayList<SubProtocolHandler>(this.protocolHandlers);
} }
/** /**
* Register a sub-protocol handler. * Register a sub-protocol handler.
*/ */
@ -174,7 +176,7 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
} }
/** /**
* @return the default sub-protocol handler to use * Return the default sub-protocol handler to use.
*/ */
public SubProtocolHandler getDefaultProtocolHandler() { public SubProtocolHandler getDefaultProtocolHandler() {
return this.defaultProtocolHandler; return this.defaultProtocolHandler;
@ -187,23 +189,44 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
return new ArrayList<String>(this.protocolHandlerLookup.keySet()); return new ArrayList<String>(this.protocolHandlerLookup.keySet());
} }
/**
* Specify the send-time limit (milliseconds).
* @see ConcurrentWebSocketSessionDecorator
*/
public void setSendTimeLimit(int sendTimeLimit) { public void setSendTimeLimit(int sendTimeLimit) {
this.sendTimeLimit = sendTimeLimit; this.sendTimeLimit = sendTimeLimit;
} }
/**
* Return the send-time limit (milliseconds).
*/
public int getSendTimeLimit() { public int getSendTimeLimit() {
return this.sendTimeLimit; return this.sendTimeLimit;
} }
/**
* Specify the buffer-size limit (number of bytes).
* @see ConcurrentWebSocketSessionDecorator
*/
public void setSendBufferSizeLimit(int sendBufferSizeLimit) { public void setSendBufferSizeLimit(int sendBufferSizeLimit) {
this.sendBufferSizeLimit = sendBufferSizeLimit; this.sendBufferSizeLimit = sendBufferSizeLimit;
} }
/**
* Return the buffer-size limit (number of bytes).
*/
public int getSendBufferSizeLimit() { public int getSendBufferSizeLimit() {
return sendBufferSizeLimit; return this.sendBufferSizeLimit;
}
/**
* Return a String describing internal state and counters.
*/
public String getStatsInfo() {
return this.stats.toString();
} }
@Override @Override
public boolean isAutoStartup() { public boolean isAutoStartup() {
return true; return true;
@ -221,14 +244,6 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
} }
} }
/**
* Return a String describing internal state and counters.
*/
public String getStatsInfo() {
return this.stats.toString();
}
@Override @Override
public final void start() { public final void start() {
Assert.isTrue(this.defaultProtocolHandler != null || !this.protocolHandlers.isEmpty(), "No handlers"); Assert.isTrue(this.defaultProtocolHandler != null || !this.protocolHandlers.isEmpty(), "No handlers");
@ -262,6 +277,7 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
} }
} }
@Override @Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception { public void afterConnectionEstablished(WebSocketSession session) throws Exception {
// WebSocketHandlerDecorator could close the session // WebSocketHandlerDecorator could close the session

Loading…
Cancel
Save