public abstract class AbstractSockJsSession extends java.lang.Object implements ConfigurableWebSocketSession
WebSocketSession
.Modifier and Type | Class and Description |
---|---|
private static class |
AbstractSockJsSession.State |
Modifier and Type | Field and Description |
---|---|
private WebSocketHandler |
handler |
private java.util.concurrent.ScheduledFuture<?> |
heartbeatTask |
private java.lang.String |
id |
protected Log |
logger |
private java.security.Principal |
principal |
private java.lang.String |
remoteAddress |
private java.lang.String |
remoteHostName |
private SockJsConfiguration |
sockJsConfig |
private AbstractSockJsSession.State |
state |
private long |
timeCreated |
private long |
timeLastActive |
private java.net.URI |
uri |
Constructor and Description |
---|
AbstractSockJsSession(java.lang.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(java.lang.Throwable ex) |
void |
delegateMessages(java.lang.String[] messages) |
protected abstract void |
disconnect(CloseStatus status) |
java.lang.String |
getId()
Return a unique session identifier.
|
java.security.Principal |
getPrincipal()
Return a
Principal instance containing the name of the
authenticated user. |
java.lang.String |
getRemoteAddress()
Return the IP address of the endpoint on the other end.
|
java.lang.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.
|
java.net.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(java.lang.String message) |
void |
setPrincipal(java.security.Principal principal) |
void |
setRemoteAddress(java.lang.String remoteAddress) |
void |
setRemoteHostName(java.lang.String remoteHostName) |
void |
setUri(java.net.URI uri) |
java.lang.String |
toString() |
protected void |
tryCloseWithSockJsTransportError(java.lang.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
private final java.lang.String id
private java.net.URI uri
private java.lang.String remoteHostName
private java.lang.String remoteAddress
private java.security.Principal principal
private final SockJsConfiguration sockJsConfig
private final WebSocketHandler handler
private AbstractSockJsSession.State state
private final long timeCreated
private long timeLastActive
private java.util.concurrent.ScheduledFuture<?> heartbeatTask
public AbstractSockJsSession(java.lang.String sessionId, SockJsConfiguration config, WebSocketHandler webSocketHandler)
sessionId
- the session IDconfig
- the sockJS configurationwebSocketHandler
- the recipient of SockJS messagespublic java.lang.String getId()
WebSocketSession
getId
in interface WebSocketSession
public java.net.URI getUri()
WebSocketSession
getUri
in interface WebSocketSession
public void setUri(java.net.URI uri)
setUri
in interface ConfigurableWebSocketSession
public boolean isSecure()
WebSocketSession
isSecure
in interface WebSocketSession
public java.lang.String getRemoteHostName()
WebSocketSession
getRemoteHostName
in interface WebSocketSession
public void setRemoteHostName(java.lang.String remoteHostName)
setRemoteHostName
in interface ConfigurableWebSocketSession
public java.lang.String getRemoteAddress()
WebSocketSession
getRemoteAddress
in interface WebSocketSession
public void setRemoteAddress(java.lang.String remoteAddress)
setRemoteAddress
in interface ConfigurableWebSocketSession
public java.security.Principal getPrincipal()
WebSocketSession
Principal
instance containing the name of the
authenticated user. If the user has not been authenticated, the method returns
null
.getPrincipal
in interface WebSocketSession
public void setPrincipal(java.security.Principal principal)
setPrincipal
in interface ConfigurableWebSocketSession
public SockJsConfiguration getSockJsConfig()
public boolean isNew()
public boolean isOpen()
WebSocketSession
isOpen
in interface WebSocketSession
public boolean isClosed()
public abstract boolean isActive()
public long getTimeSinceLastActive()
protected void updateLastActiveTime()
public void delegateConnectionEstablished() throws java.lang.Exception
java.lang.Exception
public void delegateMessages(java.lang.String[] messages) throws java.lang.Exception
java.lang.Exception
public final void delegateConnectionClosed(CloseStatus status) throws java.lang.Exception
WebSocketHandler
. This is in contrast to close()
that pro-actively
closes the connection.java.lang.Exception
public void delegateError(java.lang.Throwable ex) throws java.lang.Exception
java.lang.Exception
public final void sendMessage(WebSocketMessage message) throws java.io.IOException
WebSocketSession
TextMessage
or
BinaryMessage
.sendMessage
in interface WebSocketSession
java.io.IOException
protected abstract void sendMessageInternal(java.lang.String message) throws java.io.IOException
java.io.IOException
public final void close() throws java.io.IOException
session.close(CloseStatus.NORMAL);
Performs cleanup and notifies the WebSocketHandler
.
close
in interface WebSocketSession
java.io.IOException
public final void close(CloseStatus status) throws java.io.IOException
Performs cleanup and notifies the WebSocketHandler
.
close
in interface WebSocketSession
java.io.IOException
protected abstract void disconnect(CloseStatus status) throws java.io.IOException
java.io.IOException
protected void tryCloseWithSockJsTransportError(java.lang.Throwable ex, CloseStatus closeStatus)
protected void writeFrame(SockJsFrame frame) throws java.io.IOException
java.io.IOException
protected abstract void writeFrameInternal(SockJsFrame frame) throws java.lang.Exception
java.lang.Exception
public void sendHeartbeat() throws java.lang.Exception
java.lang.Exception
protected void scheduleHeartbeat()
protected void cancelHeartbeat()
public java.lang.String toString()
toString
in class java.lang.Object