public abstract class AbstractWebSocketSession<T> extends java.lang.Object implements NativeWebSocketSession
WebSocketSession
.Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.String,java.lang.Object> |
attributes |
protected Log |
logger |
private T |
nativeSession |
Constructor and Description |
---|
AbstractWebSocketSession(java.util.Map<java.lang.String,java.lang.Object> attributes)
Create a new instance and associate the given attributes with it.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkNativeSessionInitialized() |
void |
close()
Close the WebSocket connection with status 1000, i.e.
|
void |
close(CloseStatus status)
Close the WebSocket connection with the given close status.
|
protected abstract void |
closeInternal(CloseStatus status) |
java.util.Map<java.lang.String,java.lang.Object> |
getAttributes()
Return the map with attributes associated with the WebSocket session.
|
T |
getNativeSession()
Return the underlying native WebSocketSession, if available.
|
<R> R |
getNativeSession(java.lang.Class<R> requiredType)
Return the underlying native WebSocketSession, if available.
|
void |
initializeNativeSession(T session) |
protected abstract void |
sendBinaryMessage(BinaryMessage message) |
void |
sendMessage(WebSocketMessage<?> message)
Send a WebSocket message either
TextMessage or
BinaryMessage . |
protected abstract void |
sendPingMessage(PingMessage message) |
protected abstract void |
sendPongMessage(PongMessage message) |
protected abstract void |
sendTextMessage(TextMessage message) |
java.lang.String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getAcceptedProtocol, getBinaryMessageSizeLimit, getExtensions, getHandshakeHeaders, getId, getLocalAddress, getPrincipal, getRemoteAddress, getTextMessageSizeLimit, getUri, isOpen, setBinaryMessageSizeLimit, setTextMessageSizeLimit
protected final Log logger
private T nativeSession
private final java.util.Map<java.lang.String,java.lang.Object> attributes
public AbstractWebSocketSession(java.util.Map<java.lang.String,java.lang.Object> attributes)
attributes
- attributes from the HTTP handshake to associate with the WebSocket
session; the provided attributes are copied, the original map is not used.public java.util.Map<java.lang.String,java.lang.Object> getAttributes()
WebSocketSession
When the WebSocketSession is created, on the server side, the map can be
through a HandshakeInterceptor
.
On the client side, the map can be populated by passing attributes to the
WebSocketClient
handshake
methods.
getAttributes
in interface WebSocketSession
public T getNativeSession()
NativeWebSocketSession
getNativeSession
in interface NativeWebSocketSession
null
public <R> R getNativeSession(java.lang.Class<R> requiredType)
NativeWebSocketSession
getNativeSession
in interface NativeWebSocketSession
requiredType
- the required type of the sessionnull
public void initializeNativeSession(T session)
protected final void checkNativeSessionInitialized()
public final void sendMessage(WebSocketMessage<?> message) throws java.io.IOException
WebSocketSession
TextMessage
or
BinaryMessage
.sendMessage
in interface WebSocketSession
java.io.IOException
protected abstract void sendTextMessage(TextMessage message) throws java.io.IOException
java.io.IOException
protected abstract void sendBinaryMessage(BinaryMessage message) throws java.io.IOException
java.io.IOException
protected abstract void sendPingMessage(PingMessage message) throws java.io.IOException
java.io.IOException
protected abstract void sendPongMessage(PongMessage message) throws java.io.IOException
java.io.IOException
public final void close() throws java.io.IOException
WebSocketSession
session.close(CloseStatus.NORMAL);
close
in interface WebSocketSession
java.io.IOException
public final void close(CloseStatus status) throws java.io.IOException
WebSocketSession
close
in interface WebSocketSession
java.io.IOException
protected abstract void closeInternal(CloseStatus status) throws java.io.IOException
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object