类 ConcurrentWebSocketSessionDecorator
- java.lang.Object
- org.springframework.web.socket.handler.WebSocketSessionDecorator
- org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator
- 所有已实现的接口:
Closeable
,AutoCloseable
,WebSocketSession
public class ConcurrentWebSocketSessionDecorator extends WebSocketSessionDecorator
Wrap aWebSocketSession
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.
- 从以下版本开始:
- 4.0.3
- 作者:
- Rossen Stoyanchev, Juergen Hoeller
构造器概要
构造器 构造器 说明 ConcurrentWebSocketSessionDecorator(WebSocketSession delegate, int sendTimeLimit, int bufferSizeLimit)
Create a newConcurrentWebSocketSessionDecorator
.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
close(CloseStatus status)
Close the WebSocket connection with the given close status.int
getBufferSize()
Return the current buffer size (number of bytes).int
getBufferSizeLimit()
Return the configured buffer-size limit (number of bytes).int
getSendTimeLimit()
Return the configured send-time limit (milliseconds).long
getTimeSinceSendStarted()
Return the time (milliseconds) since the current send started, or 0 if no send is currently in progress.void
sendMessage(WebSocketMessage<?> message)
Send a WebSocket message: eitherTextMessage
orBinaryMessage
.String
toString()
从类继承的方法 org.springframework.web.socket.handler.WebSocketSessionDecorator
close, getAcceptedProtocol, getAttributes, getBinaryMessageSizeLimit, getDelegate, getExtensions, getHandshakeHeaders, getId, getLastSession, getLocalAddress, getPrincipal, getRemoteAddress, getTextMessageSizeLimit, getUri, isOpen, setBinaryMessageSizeLimit, setTextMessageSizeLimit, unwrap
构造器详细资料
ConcurrentWebSocketSessionDecorator
public ConcurrentWebSocketSessionDecorator(WebSocketSession delegate, int sendTimeLimit, int bufferSizeLimit)
Create a newConcurrentWebSocketSessionDecorator
.- 参数:
delegate
- theWebSocketSession
to delegate tosendTimeLimit
- the send-time limit (milliseconds)bufferSizeLimit
- the buffer-size limit (number of bytes)
方法详细资料
getSendTimeLimit
public int getSendTimeLimit()
Return the configured send-time limit (milliseconds).- 从以下版本开始:
- 4.3.13
getBufferSizeLimit
public int getBufferSizeLimit()
Return the configured buffer-size limit (number of bytes).- 从以下版本开始:
- 4.3.13
getBufferSize
public int getBufferSize()
Return the current buffer size (number of bytes).
getTimeSinceSendStarted
public long getTimeSinceSendStarted()
Return the time (milliseconds) since the current send started, or 0 if no send is currently in progress.
sendMessage
public void sendMessage(WebSocketMessage<?> message) throws IOException
从接口复制的说明:WebSocketSession
Send a WebSocket message: eitherTextMessage
orBinaryMessage
.Note: The underlying standard WebSocket session (JSR-356) does not allow concurrent sending. Therefore sending must be synchronized. To ensure that, one option is to wrap the
WebSocketSession
with theConcurrentWebSocketSessionDecorator
.
close
public void close(CloseStatus status) throws IOException
从接口复制的说明:WebSocketSession
Close the WebSocket connection with the given close status.- 指定者:
close
在接口中WebSocketSession
- 覆盖:
close
在类中WebSocketSessionDecorator
- 抛出:
IOException