Class AbstractWebSocketSession<T>
- java.lang.Object
- org.springframework.web.reactive.socket.adapter.AbstractWebSocketSession<T>
- Type Parameters:
T- the native delegate type
- All Implemented Interfaces:
WebSocketSession
- Direct Known Subclasses:
AbstractListenerWebSocketSession,NettyWebSocketSessionSupport
public abstract class AbstractWebSocketSession<T> extends Object implements WebSocketSession
Convenient base class forWebSocketSessionimplementations that holds common fields and exposes accessors. Also implements theWebSocketMessagefactory methods.- Since:
- 5.0
- Author:
- Rossen Stoyanchev
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractWebSocketSession(T delegate, String id, HandshakeInfo info, DataBufferFactory bufferFactory)Create a new WebSocket session.
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description WebSocketMessagebinaryMessage(Function<DataBufferFactory,DataBuffer> payloadFactory)Factory method to create a binary WebSocketMessage using theWebSocketSession.bufferFactory()for the session.DataBufferFactorybufferFactory()Return aDataBufferFactory to create message payloads.Map<String,Object>getAttributes()Return the map with attributes associated with the WebSocket session.protected TgetDelegate()HandshakeInfogetHandshakeInfo()Return information from the handshake request.StringgetId()Return the id for the session.protected StringgetLogPrefix()WebSocketMessagepingMessage(Function<DataBufferFactory,DataBuffer> payloadFactory)Factory method to create a ping WebSocketMessage using theWebSocketSession.bufferFactory()for the session.WebSocketMessagepongMessage(Function<DataBufferFactory,DataBuffer> payloadFactory)Factory method to create a pong WebSocketMessage using theWebSocketSession.bufferFactory()for the session.abstract reactor.core.publisher.Flux<WebSocketMessage>receive()Provides access to the stream of inbound messages.abstract reactor.core.publisher.Mono<Void>send(org.reactivestreams.Publisher<WebSocketMessage> messages)Give a source of outgoing messages, write the messages and return aMono<Void>that completes when the source completes and writing is done.WebSocketMessagetextMessage(String payload)Factory method to create a textWebSocketMessageusing theWebSocketSession.bufferFactory()for the session.StringtoString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.web.reactive.socket.WebSocketSession
close, close
Constructor Detail
AbstractWebSocketSession
protected AbstractWebSocketSession(T delegate, String id, HandshakeInfo info, DataBufferFactory bufferFactory)
Create a new WebSocket session.
Method Detail
getDelegate
protected T getDelegate()
getId
public String getId()
Description copied from interface:WebSocketSessionReturn the id for the session.- Specified by:
getIdin interfaceWebSocketSession
getHandshakeInfo
public HandshakeInfo getHandshakeInfo()
Description copied from interface:WebSocketSessionReturn information from the handshake request.- Specified by:
getHandshakeInfoin interfaceWebSocketSession
bufferFactory
public DataBufferFactory bufferFactory()
Description copied from interface:WebSocketSessionReturn aDataBufferFactory to create message payloads.- Specified by:
bufferFactoryin interfaceWebSocketSession- Returns:
- the buffer factory for the session
getAttributes
public Map<String,Object> getAttributes()
Description copied from interface:WebSocketSessionReturn the map with attributes associated with the WebSocket session.- Specified by:
getAttributesin interfaceWebSocketSession- Returns:
- a Map with the session attributes (never
null)
getLogPrefix
protected String getLogPrefix()
receive
public abstract reactor.core.publisher.Flux<WebSocketMessage> receive()
Description copied from interface:WebSocketSessionProvides access to the stream of inbound messages.This stream receives a completion or error signal when the connection is closed. In a typical
WebSocketHandlerimplementation this stream is composed into the overall processing flow, so that when the connection is closed, handling will end.See the class-level doc of
WebSocketHandlerand the reference for more details and examples of how to handle the session.- Specified by:
receivein interfaceWebSocketSession
send
public abstract reactor.core.publisher.Mono<Void> send(org.reactivestreams.Publisher<WebSocketMessage> messages)
Description copied from interface:WebSocketSessionGive a source of outgoing messages, write the messages and return aMono<Void>that completes when the source completes and writing is done.See the class-level doc of
WebSocketHandlerand the reference for more details and examples of how to handle the session.- Specified by:
sendin interfaceWebSocketSession
textMessage
public WebSocketMessage textMessage(String payload)
Description copied from interface:WebSocketSessionFactory method to create a textWebSocketMessageusing theWebSocketSession.bufferFactory()for the session.- Specified by:
textMessagein interfaceWebSocketSession
binaryMessage
public WebSocketMessage binaryMessage(Function<DataBufferFactory,DataBuffer> payloadFactory)
Description copied from interface:WebSocketSessionFactory method to create a binary WebSocketMessage using theWebSocketSession.bufferFactory()for the session.- Specified by:
binaryMessagein interfaceWebSocketSession
pingMessage
public WebSocketMessage pingMessage(Function<DataBufferFactory,DataBuffer> payloadFactory)
Description copied from interface:WebSocketSessionFactory method to create a ping WebSocketMessage using theWebSocketSession.bufferFactory()for the session.- Specified by:
pingMessagein interfaceWebSocketSession
pongMessage
public WebSocketMessage pongMessage(Function<DataBufferFactory,DataBuffer> payloadFactory)
Description copied from interface:WebSocketSessionFactory method to create a pong WebSocketMessage using theWebSocketSession.bufferFactory()for the session.- Specified by:
pongMessagein interfaceWebSocketSession