类 AbstractSockJsSession
- java.lang.Object
- org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSession
- 所有已实现的接口:
Closeable
,AutoCloseable
,SockJsSession
,WebSocketSession
public abstract class AbstractSockJsSession extends Object implements SockJsSession
An abstract base class for SockJS sessions implementingSockJsSession
.- 从以下版本开始:
- 4.0
- 作者:
- Rossen Stoyanchev, Sam Brannen
字段概要
字段 修饰符和类型 字段 说明 static String
DISCONNECTED_CLIENT_LOG_CATEGORY
Log category to use on network IO exceptions after a client has gone away.protected static Log
disconnectedClientLogger
Separate logger to use on network IO failure after a client has gone away.protected Log
logger
protected Object
responseLock
构造器概要
构造器 构造器 说明 AbstractSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler handler, Map<String,Object> attributes)
Create a new instance.
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected void
cancelHeartbeat()
void
close()
Performs cleanup and notify theWebSocketHandler
.void
close(CloseStatus status)
Performs cleanup and notify theWebSocketHandler
.void
delegateConnectionClosed(CloseStatus status)
Invoked when the underlying connection is closed.void
delegateConnectionEstablished()
void
delegateError(Throwable ex)
void
delegateMessages(String... messages)
void
disableHeartbeat()
Disable the SockJS heartbeat, presumably because a higher-level protocol has heartbeats enabled for the session already.protected abstract void
disconnect(CloseStatus status)
Actually close the underlying WebSocket session or in the case of HTTP transports complete the underlying request.Map<String,Object>
getAttributes()
Return the map with attributes associated with the WebSocket session.String
getId()
Return a unique session identifier.protected SockJsMessageCodec
getMessageCodec()
SockJsServiceConfig
getSockJsServiceConfig()
long
getTimeSinceLastActive()
Return the time (in ms) since the session was last active, or otherwise if the session is new, then the time since the session was created.abstract boolean
isActive()
Polling and Streaming sessions periodically close the current HTTP request and wait for the next request to come through.boolean
isClosed()
boolean
isNew()
boolean
isOpen()
Return whether the connection is still open.protected void
scheduleHeartbeat()
protected void
sendHeartbeat()
void
sendMessage(WebSocketMessage<?> message)
Send a WebSocket message: eitherTextMessage
orBinaryMessage
.protected abstract void
sendMessageInternal(String message)
String
toString()
void
tryCloseWithSockJsTransportError(Throwable error, CloseStatus closeStatus)
Close due to error arising from SockJS transport handling.protected void
updateLastActiveTime()
Should be invoked whenever the session becomes inactive.protected void
writeFrame(SockJsFrame frame)
For internal use within a TransportHandler and the (TransportHandler-specific) session class.protected abstract void
writeFrameInternal(SockJsFrame frame)
从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
从接口继承的方法 org.springframework.web.socket.WebSocketSession
getAcceptedProtocol, getBinaryMessageSizeLimit, getExtensions, getHandshakeHeaders, getLocalAddress, getPrincipal, getRemoteAddress, getTextMessageSizeLimit, getUri, setBinaryMessageSizeLimit, setTextMessageSizeLimit
字段详细资料
DISCONNECTED_CLIENT_LOG_CATEGORY
public static final String DISCONNECTED_CLIENT_LOG_CATEGORY
Log category to use on network IO exceptions after a client has gone away.Servlet containers don't expose a client disconnected callback; see eclipse-ee4j/servlet-api#44. Therefore network IO failures may occur simply because a client has gone away, and that can fill the logs with unnecessary stack traces.
We make a best effort to identify such network failures, on a per-server basis, and log them under a separate log category. A simple one-line message is logged at DEBUG level, while a full stack trace is shown at TRACE level.
disconnectedClientLogger
protected static final Log disconnectedClientLogger
Separate logger to use on network IO failure after a client has gone away.
responseLock
protected final Object responseLock
构造器详细资料
AbstractSockJsSession
public AbstractSockJsSession(String id, SockJsServiceConfig config, WebSocketHandler handler, @Nullable Map<String,Object> attributes)
Create a new instance.- 参数:
id
- the session IDconfig
- the SockJS service configuration optionshandler
- the recipient of SockJS messagesattributes
- the attributes from the HTTP handshake to associate with the WebSocket session; the provided attributes are copied, the original map is not used.
方法详细资料
getId
public String getId()
从接口复制的说明:WebSocketSession
Return a unique session identifier.- 指定者:
getId
在接口中WebSocketSession
getMessageCodec
protected SockJsMessageCodec getMessageCodec()
getSockJsServiceConfig
public SockJsServiceConfig getSockJsServiceConfig()
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
)
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
.
sendMessageInternal
protected abstract void sendMessageInternal(String message) throws IOException
- 抛出:
IOException
isNew
public boolean isNew()
isOpen
public boolean isOpen()
从接口复制的说明:WebSocketSession
Return whether the connection is still open.- 指定者:
isOpen
在接口中WebSocketSession
isClosed
public boolean isClosed()
close
public final void close() throws IOException
Performs cleanup and notify theWebSocketHandler
.- 指定者:
close
在接口中AutoCloseable
- 指定者:
close
在接口中Closeable
- 指定者:
close
在接口中WebSocketSession
- 抛出:
IOException
close
public final void close(CloseStatus status) throws IOException
Performs cleanup and notify theWebSocketHandler
.- 指定者:
close
在接口中WebSocketSession
- 抛出:
IOException
getTimeSinceLastActive
public long getTimeSinceLastActive()
从接口复制的说明:SockJsSession
Return the time (in ms) since the session was last active, or otherwise if the session is new, then the time since the session was created.- 指定者:
getTimeSinceLastActive
在接口中SockJsSession
updateLastActiveTime
protected void updateLastActiveTime()
Should be invoked whenever the session becomes inactive.
disableHeartbeat
public void disableHeartbeat()
从接口复制的说明:SockJsSession
Disable the SockJS heartbeat, presumably because a higher-level protocol has heartbeats enabled for the session already. It is not recommended to disable this otherwise, as it helps proxies to know the connection is not hanging.- 指定者:
disableHeartbeat
在接口中SockJsSession
sendHeartbeat
protected void sendHeartbeat() throws SockJsTransportFailureException
scheduleHeartbeat
protected void scheduleHeartbeat()
cancelHeartbeat
protected void cancelHeartbeat()
isActive
public abstract boolean isActive()
Polling and Streaming sessions periodically close the current HTTP request and wait for the next request to come through. During this "downtime" the session is still open but inactive and unable to send messages and therefore has to buffer them temporarily. A WebSocket session by contrast is stateful and remain active until closed.
disconnect
protected abstract void disconnect(CloseStatus status) throws IOException
Actually close the underlying WebSocket session or in the case of HTTP transports complete the underlying request.- 抛出:
IOException
writeFrame
protected void writeFrame(SockJsFrame frame) throws SockJsTransportFailureException
For internal use within a TransportHandler and the (TransportHandler-specific) session class.
writeFrameInternal
protected abstract void writeFrameInternal(SockJsFrame frame) throws IOException
- 抛出:
IOException
delegateConnectionEstablished
public void delegateConnectionEstablished() throws Exception
- 抛出:
Exception
delegateMessages
public void delegateMessages(String... messages) throws SockJsMessageDeliveryException
delegateConnectionClosed
public final void delegateConnectionClosed(CloseStatus status) throws Exception
Invoked when the underlying connection is closed.- 抛出:
Exception
tryCloseWithSockJsTransportError
public void tryCloseWithSockJsTransportError(Throwable error, CloseStatus closeStatus)
Close due to error arising from SockJS transport handling.
delegateError
public void delegateError(Throwable ex) throws Exception
- 抛出:
Exception