Class AbstractWebSocketSession<T>
java.lang.Object
org.springframework.web.socket.adapter.AbstractWebSocketSession<T>
- Type Parameters:
- T- the native session type
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- NativeWebSocketSession,- WebSocketSession
- Direct Known Subclasses:
- JettyWebSocketSession,- StandardWebSocketSession
An abstract base class for implementations of 
WebSocketSession.- Since:
- 4.0
- Author:
- Rossen Stoyanchev
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionAbstractWebSocketSession(Map<String, Object> attributes) Create a new instance and associate the given attributes with it.
- 
Method SummaryModifier and TypeMethodDescriptionprotected final voidfinal voidclose()Close the WebSocket connection with status 1000, i.e.final voidclose(CloseStatus status) Close the WebSocket connection with the given close status.protected abstract voidcloseInternal(CloseStatus status) Return the map with attributes associated with the WebSocket session.Return the underlying native WebSocketSession.<R> RgetNativeSession(Class<R> requiredType) Return the underlying native WebSocketSession, if available.voidinitializeNativeSession(T session) protected abstract voidsendBinaryMessage(BinaryMessage message) final voidsendMessage(WebSocketMessage<?> message) Send a WebSocket message: eitherTextMessageorBinaryMessage.protected abstract voidsendPingMessage(PingMessage message) protected abstract voidsendPongMessage(PongMessage message) protected abstract voidsendTextMessage(TextMessage message) toString()Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.web.socket.WebSocketSessiongetAcceptedProtocol, getBinaryMessageSizeLimit, getExtensions, getHandshakeHeaders, getId, getLocalAddress, getPrincipal, getRemoteAddress, getTextMessageSizeLimit, getUri, isOpen, setBinaryMessageSizeLimit, setTextMessageSizeLimit
- 
Field Details- 
idGenerator
- 
logger
 
- 
- 
Constructor Details- 
AbstractWebSocketSessionCreate a new instance and associate the given attributes with it.- Parameters:
- attributes- the attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.
 
 
- 
- 
Method Details- 
getAttributesDescription copied from interface:WebSocketSessionReturn the map with attributes associated with the WebSocket session.On the server side the map can be populated initially through a HandshakeInterceptor. On the client side the map can be populated viaWebSocketClienthandshake methods.- Specified by:
- getAttributesin interface- WebSocketSession
- Returns:
- a Map with the session attributes (never null)
 
- 
getNativeSessionDescription copied from interface:NativeWebSocketSessionReturn the underlying native WebSocketSession.- Specified by:
- getNativeSessionin interface- NativeWebSocketSession
 
- 
getNativeSessionDescription copied from interface:NativeWebSocketSessionReturn the underlying native WebSocketSession, if available.- Specified by:
- getNativeSessionin interface- NativeWebSocketSession
- Parameters:
- requiredType- the required type of the session
- Returns:
- the native session of the required type,
 or nullif not available
 
- 
initializeNativeSession
- 
checkNativeSessionInitializedprotected final void checkNativeSessionInitialized()
- 
sendMessageDescription copied from interface:WebSocketSessionSend a WebSocket message: eitherTextMessageorBinaryMessage.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 WebSocketSessionwith theConcurrentWebSocketSessionDecorator.- Specified by:
- sendMessagein interface- WebSocketSession
- Throws:
- IOException
- See Also:
 
- 
sendTextMessage- Throws:
- IOException
 
- 
sendBinaryMessage- Throws:
- IOException
 
- 
sendPingMessage- Throws:
- IOException
 
- 
sendPongMessage- Throws:
- IOException
 
- 
closeDescription copied from interface:WebSocketSessionClose the WebSocket connection with status 1000, i.e. equivalent to:session.close(CloseStatus.NORMAL); - Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Specified by:
- closein interface- WebSocketSession
- Throws:
- IOException
 
- 
closeDescription copied from interface:WebSocketSessionClose the WebSocket connection with the given close status.- Specified by:
- closein interface- WebSocketSession
- Throws:
- IOException
 
- 
closeInternal- Throws:
- IOException
 
- 
toString
 
-