Class ConcurrentWebSocketSessionDecorator

java.lang.Object
org.springframework.web.socket.handler.WebSocketSessionDecorator
org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator
All Implemented Interfaces:
Closeable, AutoCloseable, WebSocketSession

public class ConcurrentWebSocketSessionDecorator extends WebSocketSessionDecorator
Wrap a WebSocketSession to guarantee only one thread can send messages at a time.

If a send is slow, subsequent attempts to send more messages from other threads will not be able to acquire the flush lock and messages will be buffered instead. At that time, the specified buffer-size limit and send-time limit will be checked and the session will be closed if the limits are exceeded.

Since:
4.0.3
Author:
Rossen Stoyanchev, Juergen Hoeller
  • Constructor Details

    • ConcurrentWebSocketSessionDecorator

      public ConcurrentWebSocketSessionDecorator(WebSocketSession delegate, int sendTimeLimit, int bufferSizeLimit)
      Basic constructor.
      Parameters:
      delegate - the WebSocketSession to delegate to
      sendTimeLimit - the send-time limit (milliseconds)
      bufferSizeLimit - the buffer-size limit (number of bytes)
    • ConcurrentWebSocketSessionDecorator

      public ConcurrentWebSocketSessionDecorator(WebSocketSession delegate, int sendTimeLimit, int bufferSizeLimit, ConcurrentWebSocketSessionDecorator.OverflowStrategy overflowStrategy)
      Constructor that also specifies the overflow strategy to use.
      Parameters:
      delegate - the WebSocketSession to delegate to
      sendTimeLimit - the send-time limit (milliseconds)
      bufferSizeLimit - the buffer-size limit (number of bytes)
      overflowStrategy - the overflow strategy to use; by default the session is terminated.
      Since:
      5.1
  • Method Details