Top Description Fields Constructors Methods
org.springframework.web.reactive.socket.adapter

public abstract Class AbstractWebSocketSession<T>

extends Object
implements WebSocketSession
Class Inheritance
All Implemented Interfaces
org.springframework.web.reactive.socket.WebSocketSession
Known Direct Subclasses
org.springframework.web.reactive.socket.adapter.Netty5WebSocketSessionSupport, org.springframework.web.reactive.socket.adapter.NettyWebSocketSessionSupport, org.springframework.web.reactive.socket.adapter.AbstractListenerWebSocketSession
Type Parameters
<T>
the native delegate type
Imports
java.nio.charset.StandardCharsets, java.util.Map, java.util.concurrent.ConcurrentHashMap, java.util.function.Function, org.apache.commons.logging.Log, .LogFactory, org.reactivestreams.Publisher, reactor.core.publisher.Flux, .Mono, org.springframework.core.io.buffer.DataBuffer, .DataBufferFactory, org.springframework.util.Assert, org.springframework.web.reactive.socket.HandshakeInfo, .WebSocketMessage, .WebSocketSession

Convenient base class for WebSocketSession implementations that holds common fields and exposes accessors. Also implements the WebSocketMessage factory methods.
Author
Rossen Stoyanchev
Since
5.0

Field Summary

Modifier and TypeField and Description
private final Map<String, Object>
private final DataBufferFactory
private final T
private final HandshakeInfo
private final String
protected final Log
private final String

Constructor Summary

AccessConstructor and Description
protected
AbstractWebSocketSession(T delegate, String id, HandshakeInfo info, DataBufferFactory bufferFactory)

Create a new WebSocket session.

Method Summary

Modifier and TypeMethod and Description
public WebSocketMessage
binaryMessage(Function<DataBufferFactory, DataBuffer> payloadFactory)

Implements org.springframework.web.reactive.socket.WebSocketSession.binaryMessage.

Factory method to create a binary WebSocketMessage using the bufferFactory() for the session.

public DataBufferFactory
bufferFactory()

Implements org.springframework.web.reactive.socket.WebSocketSession.bufferFactory.

Return a DataBuffer Factory to create message payloads.

public Map<String, Object>
getAttributes()

Implements org.springframework.web.reactive.socket.WebSocketSession.getAttributes.

Return the map with attributes associated with the WebSocket session.

protected T
public HandshakeInfo
getHandshakeInfo()

Implements org.springframework.web.reactive.socket.WebSocketSession.getHandshakeInfo.

Return information from the handshake request.

public String
getId()

Implements org.springframework.web.reactive.socket.WebSocketSession.getId.

Return the id for the session.

protected String
private static String
public WebSocketMessage
pingMessage(Function<DataBufferFactory, DataBuffer> payloadFactory)

Implements org.springframework.web.reactive.socket.WebSocketSession.pingMessage.

Factory method to create a ping WebSocketMessage using the bufferFactory() for the session.

public WebSocketMessage
pongMessage(Function<DataBufferFactory, DataBuffer> payloadFactory)

Implements org.springframework.web.reactive.socket.WebSocketSession.pongMessage.

Factory method to create a pong WebSocketMessage using the bufferFactory() for the session.

public abstract Flux<WebSocketMessage>
receive()

Redeclares org.springframework.web.reactive.socket.WebSocketSession.receive.

Provides access to the stream of inbound messages.

public abstract Mono<Void>
send(Publisher<WebSocketMessage> messages)

Redeclares org.springframework.web.reactive.socket.WebSocketSession.send.

Give a source of outgoing messages, write the messages and return a Mono<Void> that completes when the source completes and writing is done.

public WebSocketMessage
textMessage(String payload)

Implements org.springframework.web.reactive.socket.WebSocketSession.textMessage.

Factory method to create a text WebSocketMessage using the bufferFactory() for the session.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

attributesback to summary
private final Map<String, Object> attributes
bufferFactoryback to summary
private final DataBufferFactory bufferFactory
delegateback to summary
private final T delegate
handshakeInfoback to summary
private final HandshakeInfo handshakeInfo
idback to summary
private final String id
loggerback to summary
protected final Log logger
logPrefixback to summary
private final String logPrefix

Constructor Detail

AbstractWebSocketSessionback to summary
protected AbstractWebSocketSession(T delegate, String id, HandshakeInfo info, DataBufferFactory bufferFactory)

Create a new WebSocket session.

Method Detail

binaryMessageback to summary
public WebSocketMessage binaryMessage(Function<DataBufferFactory, DataBuffer> payloadFactory)

Implements org.springframework.web.reactive.socket.WebSocketSession.binaryMessage.

Doc from org.springframework.web.reactive.socket.WebSocketSession.binaryMessage.

Factory method to create a binary WebSocketMessage using the bufferFactory() for the session.

Annotations
@Override
bufferFactoryback to summary
public DataBufferFactory bufferFactory()

Implements org.springframework.web.reactive.socket.WebSocketSession.bufferFactory.

Doc from org.springframework.web.reactive.socket.WebSocketSession.bufferFactory.

Return a DataBuffer Factory to create message payloads.

Returns:DataBufferFactory

the buffer factory for the session

Annotations
@Override
getAttributesback to summary
public Map<String, Object> getAttributes()

Implements org.springframework.web.reactive.socket.WebSocketSession.getAttributes.

Doc from org.springframework.web.reactive.socket.WebSocketSession.getAttributes.

Return the map with attributes associated with the WebSocket session.

Returns:Map<String, Object>

a Map with the session attributes (never null)

Annotations
@Override
getDelegateback to summary
protected T getDelegate()
getHandshakeInfoback to summary
public HandshakeInfo getHandshakeInfo()

Implements org.springframework.web.reactive.socket.WebSocketSession.getHandshakeInfo.

Doc from org.springframework.web.reactive.socket.WebSocketSession.getHandshakeInfo.

Return information from the handshake request.

Annotations
@Override
getIdback to summary
public String getId()

Implements org.springframework.web.reactive.socket.WebSocketSession.getId.

Doc from org.springframework.web.reactive.socket.WebSocketSession.getId.

Return the id for the session.

Annotations
@Override
getLogPrefixback to summary
protected String getLogPrefix()
initLogPrefixback to summary
private static String initLogPrefix(HandshakeInfo info, String id)
pingMessageback to summary
public WebSocketMessage pingMessage(Function<DataBufferFactory, DataBuffer> payloadFactory)

Implements org.springframework.web.reactive.socket.WebSocketSession.pingMessage.

Doc from org.springframework.web.reactive.socket.WebSocketSession.pingMessage.

Factory method to create a ping WebSocketMessage using the bufferFactory() for the session.

Annotations
@Override
pongMessageback to summary
public WebSocketMessage pongMessage(Function<DataBufferFactory, DataBuffer> payloadFactory)

Implements org.springframework.web.reactive.socket.WebSocketSession.pongMessage.

Doc from org.springframework.web.reactive.socket.WebSocketSession.pongMessage.

Factory method to create a pong WebSocketMessage using the bufferFactory() for the session.

Annotations
@Override
receiveback to summary
public abstract Flux<WebSocketMessage> receive()

Redeclares org.springframework.web.reactive.socket.WebSocketSession.receive.

Doc from org.springframework.web.reactive.socket.WebSocketSession.receive.

Provides access to the stream of inbound messages.

This stream receives a completion or error signal when the connection is closed. In a typical WebSocketHandler implementation 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 WebSocketHandler and the reference for more details and examples of how to handle the session.

Annotations
@Override
sendback to summary
public abstract Mono<Void> send(Publisher<WebSocketMessage> messages)

Redeclares org.springframework.web.reactive.socket.WebSocketSession.send.

Doc from org.springframework.web.reactive.socket.WebSocketSession.send.

Give a source of outgoing messages, write the messages and return a Mono<Void> that completes when the source completes and writing is done.

See the class-level doc of WebSocketHandler and the reference for more details and examples of how to handle the session.

Annotations
@Override
textMessageback to summary
public WebSocketMessage textMessage(String payload)

Implements org.springframework.web.reactive.socket.WebSocketSession.textMessage.

Doc from org.springframework.web.reactive.socket.WebSocketSession.textMessage.

Factory method to create a text WebSocketMessage using the bufferFactory() for the session.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override