类 AbstractWebSocketSession<T>
- java.lang.Object
- org.springframework.web.socket.adapter.AbstractWebSocketSession<T>
- 所有已实现的接口:
Closeable
,AutoCloseable
,NativeWebSocketSession
,WebSocketSession
public abstract class AbstractWebSocketSession<T> extends Object implements NativeWebSocketSession
An abstract base class for implementations ofWebSocketSession
.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev
构造器概要
构造器 构造器 说明 AbstractWebSocketSession(Map<String,Object> attributes)
Create a new instance and associate the given attributes with it.
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected void
checkNativeSessionInitialized()
void
close()
Close the WebSocket connection with status 1000, i.e. equivalent to:void
close(CloseStatus status)
Close the WebSocket connection with the given close status.protected abstract void
closeInternal(CloseStatus status)
Map<String,Object>
getAttributes()
Return the map with attributes associated with the WebSocket session.T
getNativeSession()
Return the underlying native WebSocketSession.<R> R
getNativeSession(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: eitherTextMessage
orBinaryMessage
.protected abstract void
sendPingMessage(PingMessage message)
protected abstract void
sendPongMessage(PongMessage message)
protected abstract void
sendTextMessage(TextMessage message)
String
toString()
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
从接口继承的方法 org.springframework.web.socket.WebSocketSession
getAcceptedProtocol, getBinaryMessageSizeLimit, getExtensions, getHandshakeHeaders, getId, getLocalAddress, getPrincipal, getRemoteAddress, getTextMessageSizeLimit, getUri, isOpen, setBinaryMessageSizeLimit, setTextMessageSizeLimit
构造器详细资料
AbstractWebSocketSession
public AbstractWebSocketSession(Map<String,Object> attributes)
Create a new instance and associate the given attributes with it.- 参数:
attributes
- attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.
方法详细资料
getAttributes
public Map<String,Object> getAttributes()
从接口复制的说明:WebSocketSession
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 viaWebSocketClient
handshake methods.- 指定者:
getAttributes
在接口中WebSocketSession
- 返回:
- a Map with the session attributes (never
null
)
getNativeSession
public T getNativeSession()
从接口复制的说明:NativeWebSocketSession
Return the underlying native WebSocketSession.- 指定者:
getNativeSession
在接口中NativeWebSocketSession
getNativeSession
public <R> R getNativeSession(Class<R> requiredType)
从接口复制的说明:NativeWebSocketSession
Return the underlying native WebSocketSession, if available.- 指定者:
getNativeSession
在接口中NativeWebSocketSession
- 参数:
requiredType
- the required type of the session- 返回:
- the native session of the required type, or
null
if not available
initializeNativeSession
public void initializeNativeSession(T session)
checkNativeSessionInitialized
protected final void checkNativeSessionInitialized()
sendMessage
public final void sendMessage(WebSocketMessage<?> message) throws IOException
从接口复制的说明:WebSocketSession
Send a WebSocket message: eitherTextMessage
orBinaryMessage
.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 theConcurrentWebSocketSessionDecorator
.
sendTextMessage
protected abstract void sendTextMessage(TextMessage message) throws IOException
- 抛出:
IOException
sendBinaryMessage
protected abstract void sendBinaryMessage(BinaryMessage message) throws IOException
- 抛出:
IOException
sendPingMessage
protected abstract void sendPingMessage(PingMessage message) throws IOException
- 抛出:
IOException
sendPongMessage
protected abstract void sendPongMessage(PongMessage message) throws IOException
- 抛出:
IOException
close
public final void close() throws IOException
从接口复制的说明:WebSocketSession
Close the WebSocket connection with status 1000, i.e. equivalent to:session.close(CloseStatus.NORMAL);
- 指定者:
close
在接口中AutoCloseable
- 指定者:
close
在接口中Closeable
- 指定者:
close
在接口中WebSocketSession
- 抛出:
IOException
close
public final void close(CloseStatus status) throws IOException
从接口复制的说明:WebSocketSession
Close the WebSocket connection with the given close status.- 指定者:
close
在接口中WebSocketSession
- 抛出:
IOException
closeInternal
protected abstract void closeInternal(CloseStatus status) throws IOException
- 抛出:
IOException