public abstract class AbstractSockJsSession extends Object implements ConfigurableWebSocketSession
WebSocketSession.| Constructor and Description |
|---|
AbstractSockJsSession(String sessionId,
SockJsConfiguration config,
WebSocketHandler webSocketHandler) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
cancelHeartbeat() |
void |
close()
Close the WebSocket connection with status 1000, i.e.
|
void |
close(CloseStatus status)
Close the WebSocket connection with the given close status.
|
void |
delegateConnectionClosed(CloseStatus status)
Invoked in reaction to the underlying connection being closed by the remote side
(or the WebSocket container) in order to perform cleanup and notify the
WebSocketHandler. |
void |
delegateConnectionEstablished() |
void |
delegateError(Throwable ex) |
void |
delegateMessages(String[] messages) |
protected abstract void |
disconnect(CloseStatus status) |
String |
getId()
Return a unique session identifier.
|
Principal |
getPrincipal()
Return a
Principal instance containing the name of the
authenticated user. |
String |
getRemoteAddress()
Return the IP address of the endpoint on the other end.
|
String |
getRemoteHostName()
Return the host name of the endpoint on the other end.
|
SockJsConfiguration |
getSockJsConfig() |
long |
getTimeSinceLastActive()
Return the time since the session was last active, or otherwise if the
session is new, the time since the session was created.
|
URI |
getUri()
Return the URI used to open the WebSocket connection.
|
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.
|
boolean |
isSecure()
Return whether the underlying socket is using a secure transport.
|
protected void |
scheduleHeartbeat() |
void |
sendHeartbeat() |
void |
sendMessage(WebSocketMessage message)
Send a WebSocket message either
TextMessage or
BinaryMessage. |
protected abstract void |
sendMessageInternal(String message) |
void |
setPrincipal(Principal principal) |
void |
setRemoteAddress(String remoteAddress) |
void |
setRemoteHostName(String remoteHostName) |
void |
setUri(URI uri) |
String |
toString() |
protected void |
tryCloseWithSockJsTransportError(Throwable ex,
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 sub-class.
|
protected abstract void |
writeFrameInternal(SockJsFrame frame) |
protected final Log logger
public AbstractSockJsSession(String sessionId, SockJsConfiguration config, WebSocketHandler webSocketHandler)
sessionId - the session IDconfig - the sockJS configurationwebSocketHandler - the recipient of SockJS messagespublic String getId()
WebSocketSessiongetId in interface WebSocketSessionpublic URI getUri()
WebSocketSessiongetUri in interface WebSocketSessionpublic void setUri(URI uri)
setUri in interface ConfigurableWebSocketSessionpublic boolean isSecure()
WebSocketSessionisSecure in interface WebSocketSessionpublic String getRemoteHostName()
WebSocketSessiongetRemoteHostName in interface WebSocketSessionpublic void setRemoteHostName(String remoteHostName)
setRemoteHostName in interface ConfigurableWebSocketSessionpublic String getRemoteAddress()
WebSocketSessiongetRemoteAddress in interface WebSocketSessionpublic void setRemoteAddress(String remoteAddress)
setRemoteAddress in interface ConfigurableWebSocketSessionpublic Principal getPrincipal()
WebSocketSessionPrincipal instance containing the name of the
authenticated user. If the user has not been authenticated, the method returns
null.getPrincipal in interface WebSocketSessionpublic void setPrincipal(Principal principal)
setPrincipal in interface ConfigurableWebSocketSessionpublic SockJsConfiguration getSockJsConfig()
public boolean isNew()
public boolean isOpen()
WebSocketSessionisOpen in interface WebSocketSessionpublic boolean isClosed()
public abstract boolean isActive()
public long getTimeSinceLastActive()
protected void updateLastActiveTime()
public void delegateConnectionEstablished()
throws Exception
Exceptionpublic final void delegateConnectionClosed(CloseStatus status) throws Exception
WebSocketHandler. This is in contrast to close() that pro-actively
closes the connection.Exceptionpublic final void sendMessage(WebSocketMessage message) throws IOException
WebSocketSessionTextMessage or
BinaryMessage.sendMessage in interface WebSocketSessionIOExceptionprotected abstract void sendMessageInternal(String message) throws IOException
IOExceptionpublic final void close()
throws IOException
session.close(CloseStatus.NORMAL);
Performs cleanup and notifies the WebSocketHandler.
close in interface WebSocketSessionIOExceptionpublic final void close(CloseStatus status) throws IOException
Performs cleanup and notifies the WebSocketHandler.
close in interface WebSocketSessionIOExceptionprotected abstract void disconnect(CloseStatus status) throws IOException
IOExceptionprotected void tryCloseWithSockJsTransportError(Throwable ex, CloseStatus closeStatus)
protected void writeFrame(SockJsFrame frame) throws IOException
IOExceptionprotected abstract void writeFrameInternal(SockJsFrame frame) throws Exception
Exceptionprotected void scheduleHeartbeat()
protected void cancelHeartbeat()