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

public abstract Class AbstractWebSocketSession<T>

extends Object
implements NativeWebSocketSession
Class Inheritance
All Implemented Interfaces
org.springframework.web.socket.adapter.NativeWebSocketSession, org.springframework.web.socket.WebSocketSession, java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
org.springframework.web.socket.adapter.jetty.JettyWebSocketSession, org.springframework.web.socket.adapter.standard.StandardWebSocketSession
Type Parameters
<T>
the native session type
Imports
java.io.IOException, java.util.Map, java.util.concurrent.ConcurrentHashMap, org.apache.commons.logging.Log, .LogFactory, org.springframework.lang.Nullable, org.springframework.util.AlternativeJdkIdGenerator, .Assert, .IdGenerator, org.springframework.web.socket.BinaryMessage, .CloseStatus, .PingMessage, .PongMessage, .TextMessage, .WebSocketMessage, .WebSocketSession

An abstract base class for implementations of WebSocketSession.
Author
Rossen Stoyanchev
Since
4.0

Field Summary

Modifier and TypeField and Description
private final Map<String, Object>
protected static final IdGenerator
protected static final Log
private T

Constructor Summary

AccessConstructor and Description
public
AbstractWebSocketSession(Map<String, Object>
the attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.
attributes
)

Create a new instance and associate the given attributes with it.

Method Summary

Modifier and TypeMethod and Description
protected final void
public final void
close()

Implements org.springframework.web.socket.WebSocketSession.close.

Close the WebSocket connection with status 1000, i.e. equivalent to:

session.close(CloseStatus.NORMAL);
public final void
close(CloseStatus status)

Implements org.springframework.web.socket.WebSocketSession.close.

Close the WebSocket connection with the given close status.

protected abstract void
public Map<String, Object>
getAttributes()

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

Return the map with attributes associated with the WebSocket session.

public T
public <R> R
getNativeSession(Class<R>
the required type of the session
requiredType
)

Implements org.springframework.web.socket.adapter.NativeWebSocketSession.getNativeSession.

Return the underlying native WebSocketSession, if available.

public void
protected abstract void
public final void
protected abstract void
protected abstract void
protected abstract void
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
idGeneratorback to summary
protected static final IdGenerator idGenerator
loggerback to summary
protected static final Log logger
nativeSessionback to summary
private T nativeSession
Annotations
@Nullable

Constructor Detail

AbstractWebSocketSessionback to summary
public AbstractWebSocketSession(Map<String, Object> attributes)

Create a new instance and associate the given attributes with it.

Parameters
attributes:Map<String, Object>

the attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.

Method Detail

checkNativeSessionInitializedback to summary
protected final void checkNativeSessionInitialized()
closeback to summary
public final void close() throws IOException

Implements org.springframework.web.socket.WebSocketSession.close.

Doc from org.springframework.web.socket.WebSocketSession.close.

Close the WebSocket connection with status 1000, i.e. equivalent to:

session.close(CloseStatus.NORMAL);
Annotations
@Override
Exceptions
IOException:

Doc from java.io.Closeable.close.

if an I/O error occurs

closeback to summary
public final void close(CloseStatus status) throws IOException

Implements org.springframework.web.socket.WebSocketSession.close.

Doc from org.springframework.web.socket.WebSocketSession.close.

Close the WebSocket connection with the given close status.

Annotations
@Override
closeInternalback to summary
protected abstract void closeInternal(CloseStatus status) throws IOException
getAttributesback to summary
public Map<String, Object> getAttributes()

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

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

Return 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 via WebSocketClient handshake methods.

Returns:Map<String, Object>

a Map with the session attributes (never null)

Annotations
@Override
getNativeSessionback to summary
public T getNativeSession()

Implements org.springframework.web.socket.adapter.NativeWebSocketSession.getNativeSession.

Doc from org.springframework.web.socket.adapter.NativeWebSocketSession.getNativeSession.

Return the underlying native WebSocketSession.

Annotations
@Override
getNativeSessionback to summary
public <R> R getNativeSession(Class<R> requiredType)

Implements org.springframework.web.socket.adapter.NativeWebSocketSession.getNativeSession.

Doc from org.springframework.web.socket.adapter.NativeWebSocketSession.getNativeSession.

Return the underlying native WebSocketSession, if available.

Parameters
requiredType:Class<R>

the required type of the session

Returns:R

the native session of the required type, or null if not available

Annotations
@SuppressWarnings:unchecked
@Override
@Nullable
initializeNativeSessionback to summary
public void initializeNativeSession(T session)
sendBinaryMessageback to summary
protected abstract void sendBinaryMessage(BinaryMessage message) throws IOException
sendMessageback to summary
public final void sendMessage(WebSocketMessage<?> message) throws IOException

Implements org.springframework.web.socket.WebSocketSession.sendMessage.

Doc from org.springframework.web.socket.WebSocketSession.sendMessage.

Send a WebSocket message: either TextMessage or BinaryMessage.

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 WebSocketSession with the ConcurrentWebSocketSessionDecorator.

Annotations
@Override
sendPingMessageback to summary
protected abstract void sendPingMessage(PingMessage message) throws IOException
sendPongMessageback to summary
protected abstract void sendPongMessage(PongMessage message) throws IOException
sendTextMessageback to summary
protected abstract void sendTextMessage(TextMessage message) throws IOException
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