public abstract class AbstractSockJsSession extends java.lang.Object implements SockJsSession
SockJsSession
.Modifier and Type | Field and Description |
---|---|
static java.lang.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 java.lang.Object |
responseLock |
Constructor and Description |
---|
AbstractSockJsSession(java.lang.String id,
SockJsServiceConfig config,
WebSocketHandler handler,
java.util.Map<java.lang.String,java.lang.Object> attributes)
Create a new instance.
|
Modifier and Type | Method and Description |
---|---|
protected void |
cancelHeartbeat() |
void |
close()
Performs cleanup and notify the
WebSocketHandler . |
void |
close(CloseStatus status)
Performs cleanup and notify the
WebSocketHandler . |
void |
delegateConnectionClosed(CloseStatus status)
Invoked when the underlying connection is closed.
|
void |
delegateConnectionEstablished() |
void |
delegateError(java.lang.Throwable ex) |
void |
delegateMessages(java.lang.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.
|
java.util.Map<java.lang.String,java.lang.Object> |
getAttributes()
Return the map with attributes associated with the WebSocket session.
|
java.lang.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: either
TextMessage or BinaryMessage . |
protected abstract void |
sendMessageInternal(java.lang.String message) |
java.lang.String |
toString() |
void |
tryCloseWithSockJsTransportError(java.lang.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) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getAcceptedProtocol, getBinaryMessageSizeLimit, getExtensions, getHandshakeHeaders, getLocalAddress, getPrincipal, getRemoteAddress, getTextMessageSizeLimit, getUri, setBinaryMessageSizeLimit, setTextMessageSizeLimit
public static final java.lang.String DISCONNECTED_CLIENT_LOG_CATEGORY
Servlet containers dn't expose a 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
,
Constant Field Valuesprotected static final Log disconnectedClientLogger
DISCONNECTED_CLIENT_LOG_CATEGORY
protected final Log logger
protected final java.lang.Object responseLock
public AbstractSockJsSession(java.lang.String id, SockJsServiceConfig config, WebSocketHandler handler, @Nullable java.util.Map<java.lang.String,java.lang.Object> attributes)
id
- the session IDconfig
- the SockJS service configuration optionshandler
- the recipient of SockJS messagesattributes
- attributes from the HTTP handshake to associate with the WebSocket
session; the provided attributes are copied, the original map is not used.public java.lang.String getId()
WebSocketSession
getId
in interface WebSocketSession
protected SockJsMessageCodec getMessageCodec()
public SockJsServiceConfig getSockJsServiceConfig()
public java.util.Map<java.lang.String,java.lang.Object> getAttributes()
WebSocketSession
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.
getAttributes
in interface WebSocketSession
null
)public final void sendMessage(WebSocketMessage<?> message) throws java.io.IOException
WebSocketSession
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
.
sendMessage
in interface WebSocketSession
java.io.IOException
ConcurrentWebSocketSessionDecorator
protected abstract void sendMessageInternal(java.lang.String message) throws java.io.IOException
java.io.IOException
public boolean isNew()
public boolean isOpen()
WebSocketSession
isOpen
in interface WebSocketSession
public boolean isClosed()
public final void close() throws java.io.IOException
WebSocketHandler
.close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface WebSocketSession
java.io.IOException
public final void close(CloseStatus status) throws java.io.IOException
WebSocketHandler
.close
in interface WebSocketSession
java.io.IOException
public long getTimeSinceLastActive()
SockJsSession
getTimeSinceLastActive
in interface SockJsSession
protected void updateLastActiveTime()
public void disableHeartbeat()
SockJsSession
disableHeartbeat
in interface SockJsSession
protected void sendHeartbeat() throws SockJsTransportFailureException
SockJsTransportFailureException
protected void scheduleHeartbeat()
protected void cancelHeartbeat()
public abstract boolean isActive()
protected abstract void disconnect(CloseStatus status) throws java.io.IOException
java.io.IOException
protected void writeFrame(SockJsFrame frame) throws SockJsTransportFailureException
SockJsTransportFailureException
protected abstract void writeFrameInternal(SockJsFrame frame) throws java.io.IOException
java.io.IOException
public void delegateConnectionEstablished() throws java.lang.Exception
java.lang.Exception
public void delegateMessages(java.lang.String... messages) throws SockJsMessageDeliveryException
SockJsMessageDeliveryException
public final void delegateConnectionClosed(CloseStatus status) throws java.lang.Exception
java.lang.Exception
public void tryCloseWithSockJsTransportError(java.lang.Throwable error, CloseStatus closeStatus)
public void delegateError(java.lang.Throwable ex) throws java.lang.Exception
java.lang.Exception
public java.lang.String toString()
toString
in class java.lang.Object