public class ConcurrentWebSocketSessionDecorator extends WebSocketSessionDecorator
WebSocketSession
and guarantees
only one thread can send messages at a time.
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 -- at that time the specified buffer size limit and send time limit will be checked and the session closed if the limits are exceeded.
Modifier and Type | Field and Description |
---|---|
private java.util.Queue<WebSocketMessage<?>> |
buffer |
private java.util.concurrent.atomic.AtomicInteger |
bufferSize |
private int |
bufferSizeLimit |
private java.util.concurrent.locks.Lock |
closeLock |
private java.util.concurrent.locks.Lock |
flushLock |
private boolean |
limitExceeded |
private static Log |
logger |
private long |
sendStartTime |
private int |
sendTimeLimit |
private boolean |
shutDownInProgress |
Constructor and Description |
---|
ConcurrentWebSocketSessionDecorator(WebSocketSession delegate,
int sendTimeLimit,
int bufferSizeLimit) |
Modifier and Type | Method and Description |
---|---|
private void |
checkSessionLimits() |
void |
close(CloseStatus status)
Close the WebSocket connection with the given close status.
|
int |
getBufferSize() |
long |
getTimeSinceSendStarted() |
private boolean |
isDisabled() |
void |
sendMessage(WebSocketMessage<?> message)
Send a WebSocket message either
TextMessage or
BinaryMessage . |
private void |
sessionLimitReached(java.lang.String reason,
CloseStatus status) |
private boolean |
tryFlushMessageBuffer() |
close, getAcceptedProtocol, getAttributes, getBinaryMessageSizeLimit, getDelegate, getExtensions, getHandshakeHeaders, getId, getLastSession, getLocalAddress, getPrincipal, getRemoteAddress, getTextMessageSizeLimit, getUri, isOpen, setBinaryMessageSizeLimit, setTextMessageSizeLimit, toString, unwrap
private static Log logger
private final java.util.Queue<WebSocketMessage<?>> buffer
private final java.util.concurrent.atomic.AtomicInteger bufferSize
private final int bufferSizeLimit
private volatile long sendStartTime
private final int sendTimeLimit
private volatile boolean limitExceeded
private volatile boolean shutDownInProgress
private final java.util.concurrent.locks.Lock flushLock
private final java.util.concurrent.locks.Lock closeLock
public ConcurrentWebSocketSessionDecorator(WebSocketSession delegate, int sendTimeLimit, int bufferSizeLimit)
public int getBufferSize()
public long getTimeSinceSendStarted()
public void sendMessage(WebSocketMessage<?> message) throws java.io.IOException
WebSocketSession
TextMessage
or
BinaryMessage
.sendMessage
in interface WebSocketSession
sendMessage
in class WebSocketSessionDecorator
java.io.IOException
private boolean isDisabled()
private boolean tryFlushMessageBuffer() throws java.io.IOException
java.io.IOException
private void checkSessionLimits() throws java.io.IOException
java.io.IOException
private void sessionLimitReached(java.lang.String reason, CloseStatus status)
public void close(CloseStatus status) throws java.io.IOException
WebSocketSession
close
in interface WebSocketSession
close
in class WebSocketSessionDecorator
java.io.IOException