WebSocketHandler that delegates incoming WebSocket
messages to a SubProtocolHandler along with a MessageChannel to which
the sub-protocol handler can send messages from WebSocket clients to the application.
Also an implementation of MessageHandler that finds the WebSocket session
associated with the Message and passes it, along with the message, to the
sub-protocol handler to send messages from the application back to the client.
| Modifier and Type | Class and Description |
|---|---|
| private class | |
| public static interface | SubProtocolWebSocketHandler.
Contract for access to session counters. |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final MessageChannel | |
| private final SubscribableChannel | |
| private static final int | DEFAULT_TIME_TO_FIRST_MESSAGE
The default value for |
| private SubProtocolHandler | |
| private volatile long | |
| private final Object | |
| private final Log | |
| private Integer | |
| private final Map | |
| private final Set | |
| private volatile boolean | |
| private int | |
| private int | |
| private final Lock | |
| private final Map | |
| private final SubProtocolWebSocketHandler. | |
| private int |
| Access | Constructor and Description |
|---|---|
| public | SubProtocolWebSocketHandler(MessageChannel
the inbound clientInboundChannel, SubscribableChannel MessageChannelthe outbound clientOutboundChannel)MessageChannelCreate a new |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus)
Implements org. Invoked after the WebSocket connection has been closed by either side, or after a transport error has occurred. |
| public void | afterConnectionEstablished(WebSocketSession session)
Implements org. Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use. |
| private void | checkSessions()
A higher-level protocol can use heartbeats to detect sessions that need to be cleaned up. |
| private void | |
| protected WebSocketSession | Returns: the decoratedWebSocketSession, or potentially the given session as-isthe original session)WebSocketSessionDecorate the given |
| protected final SubProtocolHandler | findProtocolHandler(WebSocketSession
the session)WebSocketSession to find a handler forFind a |
| public SubProtocolHandler | |
| public int | getPhase()
Overrides default org. Return the phase that this lifecycle object is supposed to run in. The default implementation returns |
| public Map | |
| public List | |
| public int | |
| public int | |
| public SubProtocolWebSocketHandler. | |
| public String | |
| public List | getSubProtocols()
Implements org. Return all supported protocols. |
| public int | getTimeToFirstMessage()
Return the maximum time allowed after the WebSocket connection is established and before the first sub-protocol message. |
| public void | handleMessage(WebSocketSession session, WebSocketMessage<?> message)
Implements org. Handle an inbound message from a WebSocket client. |
| public void | handleMessage(Message<?>
the message to be handled message)Implements org. Handle an outbound Spring Message to a WebSocket client. |
| public void | handleTransportError(WebSocketSession session, Throwable exception)
Implements org. Handle an error from the underlying WebSocket message transport. |
| public final boolean | isRunning()
Implements org. Check whether this component is currently running. |
| private String | |
| public void | setDefaultProtocolHandler(SubProtocolHandler
the default handler defaultProtocolHandler)Set the |
| public void | setPhase(int phase)
Set the phase that this handler should run in. By default, this is |
| public void | setProtocolHandlers(List<SubProtocolHandler>
the sub-protocol handlers to use protocolHandlers)Configure one or more handlers to use depending on the sub-protocol requested by the client in the WebSocket handshake request. |
| public void | |
| public void | |
| public void | setTimeToFirstMessage(int
the maximum time allowed in milliseconds timeToFirstMessage)Set the maximum time allowed in milliseconds after the WebSocket connection is established and before the first sub-protocol message is received. |
| public final void | |
| public final void | stop()
Implements org. Stop this component, typically in a synchronous fashion, such that the component is fully stopped upon return of this method. |
| public final void | stop(Runnable callback)
Overrides default org. Indicates that a Lifecycle component must stop if it is currently running. |
| public boolean | supportsPartialMessages()
Implements org. Whether the WebSocketHandler handles partial messages. |
| public String |
| clientInboundChannel | back to summary |
|---|---|
| private final MessageChannel clientInboundChannel | |
| clientOutboundChannel | back to summary |
|---|---|
| private final SubscribableChannel clientOutboundChannel | |
| DEFAULT_TIME_TO_FIRST_MESSAGE | back to summary |
|---|---|
| private static final int DEFAULT_TIME_TO_FIRST_MESSAGE The default value for | |
| defaultProtocolHandler | back to summary |
|---|---|
| private SubProtocolHandler defaultProtocolHandler
| |
| lastSessionCheckTime | back to summary |
|---|---|
| private volatile long lastSessionCheckTime | |
| lifecycleMonitor | back to summary |
|---|---|
| private final Object lifecycleMonitor | |
| logger | back to summary |
|---|---|
| private final Log logger | |
| phase | back to summary |
|---|---|
| private Integer phase
| |
| protocolHandlerLookup | back to summary |
|---|---|
| private final Map<String, SubProtocolHandler> protocolHandlerLookup | |
| protocolHandlers | back to summary |
|---|---|
| private final Set<SubProtocolHandler> protocolHandlers | |
| running | back to summary |
|---|---|
| private volatile boolean running | |
| sendBufferSizeLimit | back to summary |
|---|---|
| private int sendBufferSizeLimit | |
| sendTimeLimit | back to summary |
|---|---|
| private int sendTimeLimit | |
| sessionCheckLock | back to summary |
|---|---|
| private final Lock sessionCheckLock | |
| sessions | back to summary |
|---|---|
| private final Map<String, SubProtocolWebSocketHandler. | |
| stats | back to summary |
|---|---|
| private final SubProtocolWebSocketHandler. | |
| timeToFirstMessage | back to summary |
|---|---|
| private int timeToFirstMessage | |
| SubProtocolWebSocketHandler | back to summary |
|---|---|
| public SubProtocolWebSocketHandler(MessageChannel clientInboundChannel, SubscribableChannel clientOutboundChannel) Create a new
| |
| addProtocolHandler | back to summary |
|---|---|
| public void addProtocolHandler(SubProtocolHandler handler) Register a sub-protocol handler. | |
| afterConnectionClosed | back to summary |
|---|---|
| public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus) throws Exception Implements org. Doc from org. Invoked after the WebSocket connection has been closed by either side, or after a transport error has occurred. Although the session may technically still be open, depending on the underlying implementation, sending messages at this point is discouraged and most likely will not succeed. | |
| afterConnectionEstablished | back to summary |
|---|---|
| public void afterConnectionEstablished(WebSocketSession session) throws Exception Implements org. Doc from org. Invoked after WebSocket negotiation has succeeded and the WebSocket connection is opened and ready for use. | |
| checkSessions | back to summary |
|---|---|
| private void checkSessions() A higher-level protocol can use heartbeats to detect sessions that need to be cleaned up. However, if a WebSocket session is established, but messages can't flow (e.g. due to a proxy issue), then the higher level protocol is never successfully negotiated, and without heartbeats, sessions can hang. The method checks for sessions that have not received any messages 60 seconds after the WebSocket session was established, and closes them. | |
| clearSession | back to summary |
|---|---|
| private void clearSession(WebSocketSession session, CloseStatus closeStatus) throws Exception | |
| decorateSession | back to summary |
|---|---|
| protected WebSocketSession decorateSession(WebSocketSession session) Decorate the given The default implementation builds a
| |
| findProtocolHandler | back to summary |
|---|---|
| protected final SubProtocolHandler findProtocolHandler(WebSocketSession session) Find a
| |
| getDefaultProtocolHandler | back to summary |
|---|---|
| public SubProtocolHandler getDefaultProtocolHandler() Return the default sub-protocol handler to use.
| |
| getPhase | back to summary |
|---|---|
| public int getPhase() Overrides default org. Doc from org. Return the phase that this lifecycle object is supposed to run in. The default implementation returns
| |
| getProtocolHandlerMap | back to summary |
|---|---|
| public Map Return the sub-protocols keyed by protocol name. | |
| getProtocolHandlers | back to summary |
|---|---|
| public List | |
| getSendBufferSizeLimit | back to summary |
|---|---|
| public int getSendBufferSizeLimit() Return the buffer-size limit (number of bytes). | |
| getSendTimeLimit | back to summary |
|---|---|
| public int getSendTimeLimit() Return the send-time limit (milliseconds). | |
| getStats | back to summary |
|---|---|
| public SubProtocolWebSocketHandler. Return a structured object with various session counters.
| |
| getStatsInfo | back to summary |
|---|---|
| public String getStatsInfo() Return a String describing internal state and counters.
Effectively | |
| getSubProtocols | back to summary |
|---|---|
| public List Implements org. Return all supported protocols.
| |
| getTimeToFirstMessage | back to summary |
|---|---|
| public int getTimeToFirstMessage() Return the maximum time allowed after the WebSocket connection is established and before the first sub-protocol message.
| |
| handleMessage | back to summary |
|---|---|
| public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception Implements org. Handle an inbound message from a WebSocket client.
| |
| handleMessage | back to summary |
|---|---|
| public void handleMessage(Message<?> message) throws MessagingException Implements org. Handle an outbound Spring Message to a WebSocket client.
| |
| handleTransportError | back to summary |
|---|---|
| public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception Implements org. Doc from org. Handle an error from the underlying WebSocket message transport. | |
| isRunning | back to summary |
|---|---|
| public final boolean isRunning() Implements org. Doc from org. Check whether this component is currently running. In the case of a container, this will return
| |
| resolveSessionId | back to summary |
|---|---|
private String resolveSessionId(Message<?> message)
| |
| setDefaultProtocolHandler | back to summary |
|---|---|
| public void setDefaultProtocolHandler(SubProtocolHandler defaultProtocolHandler) Set the
| |
| setPhase | back to summary |
|---|---|
| public void setPhase(int phase) Set the phase that this handler should run in. By default, this is
| |
| setProtocolHandlers | back to summary |
|---|---|
| public void setProtocolHandlers(List<SubProtocolHandler> protocolHandlers) Configure one or more handlers to use depending on the sub-protocol requested by the client in the WebSocket handshake request.
| |
| setSendBufferSizeLimit | back to summary |
|---|---|
| public void setSendBufferSizeLimit(int sendBufferSizeLimit) Specify the buffer-size limit (number of bytes).
| |
| setSendTimeLimit | back to summary |
|---|---|
| public void setSendTimeLimit(int sendTimeLimit) Specify the send-time limit (milliseconds).
| |
| setTimeToFirstMessage | back to summary |
|---|---|
| public void setTimeToFirstMessage(int timeToFirstMessage) Set the maximum time allowed in milliseconds after the WebSocket connection is established and before the first sub-protocol message is received. This handler is for WebSocket connections that use a sub-protocol. Therefore, we expect the client to send at least one sub-protocol message in the beginning, or else we assume the connection isn't doing well, e.g. proxy issue, slow network, and can be closed. By default this is set to
| |
| start | back to summary |
|---|---|
| public final void start() Implements org. Doc from org. Start this component. Should not throw an exception if the component is already running. In the case of a container, this will propagate the start signal to all components that apply.
| |
| stop | back to summary |
|---|---|
| public final void stop() Implements org. Doc from org. Stop this component, typically in a synchronous fashion, such that the component is
fully stopped upon return of this method. Consider implementing Note that this stop notification is not guaranteed to come before destruction:
On regular shutdown, Should not throw an exception if the component is not running (not started yet). In the case of a container, this will propagate the stop signal to all components that apply.
| |
| stop | back to summary |
|---|---|
| public final void stop(Runnable callback) Overrides default org. Doc from org. Indicates that a Lifecycle component must stop if it is currently running. The provided callback is used by the The The default implementation delegates to
| |
| supportsPartialMessages | back to summary |
|---|---|
| public boolean supportsPartialMessages() Implements org. Doc from org. Whether the WebSocketHandler handles partial messages. If this flag is set to
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Field and Description |
|---|---|
| private final AtomicInteger | |
| private final AtomicInteger | |
| private final AtomicInteger | |
| private final AtomicInteger | |
| private final AtomicInteger | |
| private final AtomicInteger | |
| private final AtomicInteger |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| pack-priv AtomicInteger | |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| pack-priv void | |
| pack-priv void | |
| pack-priv void | |
| pack-priv void | |
| public String |
| httpPolling | back to summary |
|---|---|
| private final AtomicInteger httpPolling | |
| httpStreaming | back to summary |
|---|---|
| private final AtomicInteger httpStreaming | |
| limitExceeded | back to summary |
|---|---|
| private final AtomicInteger limitExceeded | |
| noMessagesReceived | back to summary |
|---|---|
| private final AtomicInteger noMessagesReceived | |
| total | back to summary |
|---|---|
| private final AtomicInteger total | |
| transportError | back to summary |
|---|---|
| private final AtomicInteger transportError | |
| webSocket | back to summary |
|---|---|
| private final AtomicInteger webSocket | |
| DefaultStats | back to summary |
|---|---|
| private DefaultStats() | |
| decrementSessionCount | back to summary |
|---|---|
| pack-priv void decrementSessionCount(WebSocketSession session) | |
| getCountFor | back to summary |
|---|---|
| pack-priv AtomicInteger getCountFor(WebSocketSession session) | |
| getHttpPollingSessions | back to summary |
|---|---|
| public int getHttpPollingSessions() Implements org.
| |
| getHttpStreamingSessions | back to summary |
|---|---|
| public int getHttpStreamingSessions() Implements org.
| |
| getLimitExceededSessions | back to summary |
|---|---|
| public int getLimitExceededSessions() Implements org.
| |
| getNoMessagesReceivedSessions | back to summary |
|---|---|
| public int getNoMessagesReceivedSessions() Implements org.
| |
| getTotalSessions | back to summary |
|---|---|
| public int getTotalSessions() Implements org.
| |
| getTransportErrorSessions | back to summary |
|---|---|
| public int getTransportErrorSessions() Implements org.
| |
| getWebSocketSessions | back to summary |
|---|---|
| public int getWebSocketSessions() Implements org.
| |
| incrementLimitExceededCount | back to summary |
|---|---|
| pack-priv void incrementLimitExceededCount() | |
| incrementNoMessagesReceivedCount | back to summary |
|---|---|
| pack-priv void incrementNoMessagesReceivedCount() | |
| incrementSessionCount | back to summary |
|---|---|
| pack-priv void incrementSessionCount(WebSocketSession session) | |
| incrementTransportError | back to summary |
|---|---|
| pack-priv void incrementTransportError() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |
| Modifier and Type | Method and Description |
|---|---|
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public int | |
| public int |
| getHttpPollingSessions | back to summary |
|---|---|
| public int getHttpPollingSessions() | |
| getHttpStreamingSessions | back to summary |
|---|---|
| public int getHttpStreamingSessions() | |
| getLimitExceededSessions | back to summary |
|---|---|
| public int getLimitExceededSessions() | |
| getNoMessagesReceivedSessions | back to summary |
|---|---|
| public int getNoMessagesReceivedSessions() | |
| getTotalSessions | back to summary |
|---|---|
| public int getTotalSessions() | |
| getTransportErrorSessions | back to summary |
|---|---|
| public int getTransportErrorSessions() | |
| getWebSocketSessions | back to summary |
|---|---|
| public int getWebSocketSessions() | |
| Modifier and Type | Field and Description |
|---|---|
| private final long | |
| private volatile boolean | |
| private final WebSocketSession |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public long | |
| public WebSocketSession | |
| public boolean | |
| public void | |
| public String |
| createTime | back to summary |
|---|---|
| private final long createTime | |
| hasHandledMessages | back to summary |
|---|---|
| private volatile boolean hasHandledMessages | |
| session | back to summary |
|---|---|
| private final WebSocketSession session | |
| WebSocketSessionHolder | back to summary |
|---|---|
| public WebSocketSessionHolder(WebSocketSession session) | |
| getCreateTime | back to summary |
|---|---|
| public long getCreateTime() | |
| getSession | back to summary |
|---|---|
| public WebSocketSession getSession() | |
| hasHandledMessages | back to summary |
|---|---|
| public boolean hasHandledMessages() | |
| setHasHandledMessages | back to summary |
|---|---|
| public void setHasHandledMessages() | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non- | |