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.
| Modifier and Type | Class and Description |
|---|---|
| public static enum | ConcurrentWebSocketSessionDecorator.
Enum for options of what to do when the buffer fills up. |
| Modifier and Type | Field and Description |
|---|---|
| private final Queue | |
| private final AtomicInteger | |
| private final int | |
| private volatile boolean | |
| private final Lock | |
| private final Lock | |
| private volatile boolean | |
| private static final Log | |
| private final ConcurrentWebSocketSessionDecorator. | |
| private Consumer | |
| private volatile long | |
| private final int |
| Access | Constructor and Description |
|---|---|
| public | ConcurrentWebSocketSessionDecorator(WebSocketSession
the delegate, int WebSocketSession to delegate tothe send-time limit (milliseconds) sendTimeLimit, int the buffer-size limit (number of bytes) bufferSizeLimit)Basic constructor. |
| public | ConcurrentWebSocketSessionDecorator(WebSocketSession
the delegate, int WebSocketSession to delegate tothe send-time limit (milliseconds) sendTimeLimit, int the buffer-size limit (number of bytes) bufferSizeLimit, ConcurrentWebSocketSessionDecorator.the overflow strategy to use; by default the
session is terminated. overflowStrategyConstructor that also specifies the overflow strategy to use. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | close(CloseStatus status)
Overrides org. Implements org. Close the WebSocket connection with the given close status. |
| public int | |
| public int | |
| public int | |
| public long | getTimeSinceSendStarted()
Return the time (milliseconds) since the current send started, or 0 if no send is currently in progress. |
| private void | |
| public void | sendMessage(WebSocketMessage<?> message)
Overrides org. Implements org. Send a WebSocket message: either |
| public void | setMessageCallback(Consumer<WebSocketMessage<?>>
the callback to invoke callback)Set a callback invoked after a message is added to the send buffer. |
| private boolean | |
| public String | toString()
Overrides org. Returns a string representation of the object. |
| private boolean |
| buffer | back to summary |
|---|---|
| private final Queue<WebSocketMessage<?>> buffer | |
| bufferSize | back to summary |
|---|---|
| private final AtomicInteger bufferSize | |
| bufferSizeLimit | back to summary |
|---|---|
| private final int bufferSizeLimit | |
| closeInProgress | back to summary |
|---|---|
| private volatile boolean closeInProgress | |
| closeLock | back to summary |
|---|---|
| private final Lock closeLock | |
| flushLock | back to summary |
|---|---|
| private final Lock flushLock | |
| limitExceeded | back to summary |
|---|---|
| private volatile boolean limitExceeded | |
| logger | back to summary |
|---|---|
| private static final Log logger | |
| overflowStrategy | back to summary |
|---|---|
| private final ConcurrentWebSocketSessionDecorator. | |
| preSendCallback | back to summary |
|---|---|
| private Consumer<WebSocketMessage<?>> preSendCallback
| |
| sendStartTime | back to summary |
|---|---|
| private volatile long sendStartTime | |
| sendTimeLimit | back to summary |
|---|---|
| private final int sendTimeLimit | |
| ConcurrentWebSocketSessionDecorator | back to summary |
|---|---|
| public ConcurrentWebSocketSessionDecorator(WebSocketSession delegate, int sendTimeLimit, int bufferSizeLimit) Basic constructor.
| |
| ConcurrentWebSocketSessionDecorator | back to summary |
|---|---|
| public ConcurrentWebSocketSessionDecorator(WebSocketSession delegate, int sendTimeLimit, int bufferSizeLimit, ConcurrentWebSocketSessionDecorator. Constructor that also specifies the overflow strategy to use.
| |
| checkSessionLimits | back to summary |
|---|---|
| private void checkSessionLimits() | |
| close | back to summary |
|---|---|
| public void close(CloseStatus status) throws IOException Overrides org. Implements org. Doc from org. Close the WebSocket connection with the given close status.
| |
| getBufferSize | back to summary |
|---|---|
| public int getBufferSize() Return the current buffer size (number of bytes). | |
| getBufferSizeLimit | back to summary |
|---|---|
| public int getBufferSizeLimit() Return the configured buffer-size limit (number of bytes).
| |
| getSendTimeLimit | back to summary |
|---|---|
| public int getSendTimeLimit() Return the configured send-time limit (milliseconds).
| |
| getTimeSinceSendStarted | back to summary |
|---|---|
| public long getTimeSinceSendStarted() Return the time (milliseconds) since the current send started, or 0 if no send is currently in progress. | |
| limitExceeded | back to summary |
|---|---|
| private void limitExceeded(String reason) | |
| sendMessage | back to summary |
|---|---|
| public void sendMessage(WebSocketMessage<?> message) throws IOException Overrides org. Implements org. Doc from org. Send a WebSocket message: either 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
| |
| setMessageCallback | back to summary |
|---|---|
| public void setMessageCallback(Consumer<WebSocketMessage<?>> callback) Set a callback invoked after a message is added to the send buffer.
| |
| shouldNotSend | back to summary |
|---|---|
| private boolean shouldNotSend() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides org. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| tryFlushMessageBuffer | back to summary |
|---|---|
| private boolean tryFlushMessageBuffer() throws IOException | |
| Modifier and Type | Field and Description |
|---|---|
| public static final ConcurrentWebSocketSessionDecorator. | DROP
Drop the oldest messages from the buffer. |
| public static final ConcurrentWebSocketSessionDecorator. | TERMINATE
Throw |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static ConcurrentWebSocketSessionDecorator. | |
| public static ConcurrentWebSocketSessionDecorator. |
| DROP | back to summary |
|---|---|
| public static final ConcurrentWebSocketSessionDecorator. Drop the oldest messages from the buffer. | |
| TERMINATE | back to summary |
|---|---|
| public static final ConcurrentWebSocketSessionDecorator. Throw | |
| OverflowStrategy | back to summary |
|---|---|
| private OverflowStrategy() | |
| valueOf | back to summary |
|---|---|
| public static ConcurrentWebSocketSessionDecorator. | |
| values | back to summary |
|---|---|
| public static ConcurrentWebSocketSessionDecorator. | |