Constructor and Description |
---|
WsSession(Endpoint localEndpoint,
WsRemoteEndpointImplBase wsRemoteEndpoint,
WsWebSocketContainer wsWebSocketContainer,
java.net.URI requestUri,
java.util.Map<java.lang.String,java.util.List<java.lang.String>> requestParameterMap,
java.lang.String queryString,
java.security.Principal userPrincipal,
java.lang.String httpSessionId,
java.util.List<Extension> negotiatedExtensions,
java.lang.String subProtocol,
java.util.Map<java.lang.String,java.lang.String> pathParameters,
boolean secure,
EndpointConfig endpointConfig)
Creates a new WebSocket session for communication between the two
provided end points.
|
Modifier and Type | Method and Description |
---|---|
<T> void |
addMessageHandler(java.lang.Class<T> clazz,
MessageHandler.Partial<T> handler)
Registers a
MessageHandler for partial incoming messages. |
<T> void |
addMessageHandler(java.lang.Class<T> clazz,
MessageHandler.Whole<T> handler)
Registers a
MessageHandler for whole incoming messages. |
void |
addMessageHandler(MessageHandler listener)
Registers a
MessageHandler for incoming messages. |
protected static void |
appendCloseReasonWithTruncation(java.nio.ByteBuffer msg,
java.lang.String reason)
Use protected so unit tests can access this method directly.
|
protected void |
checkExpiration() |
void |
close()
Close the connection to the remote end point using the code
CloseReason.CloseCodes.NORMAL_CLOSURE and an
empty reason phrase. |
void |
close(CloseReason closeReason)
Close the connection to the remote end point using the specified code
and reason phrase.
|
void |
doClose(CloseReason closeReasonMessage,
CloseReason closeReasonLocal)
WebSocket 1.0.
|
RemoteEndpoint.Async |
getAsyncRemote() |
RemoteEndpoint.Basic |
getBasicRemote() |
protected MessageHandler |
getBinaryMessageHandler() |
WebSocketContainer |
getContainer()
Get the container that created this session.
|
java.lang.String |
getHttpSessionId() |
java.lang.String |
getId()
Provides a unique identifier for the session.
|
Endpoint |
getLocal() |
int |
getMaxBinaryMessageBufferSize()
Get the current maximum buffer size for binary messages.
|
long |
getMaxIdleTimeout()
Get the idle timeout for this session.
|
int |
getMaxTextMessageBufferSize()
Get the maximum buffer size for text messages.
|
java.util.Set<MessageHandler> |
getMessageHandlers() |
java.util.List<Extension> |
getNegotiatedExtensions() |
java.lang.String |
getNegotiatedSubprotocol() |
java.util.Set<Session> |
getOpenSessions()
Obtain the set of open sessions associated with the same local endpoint
as this session.
|
java.util.Map<java.lang.String,java.lang.String> |
getPathParameters() |
protected MessageHandler.Whole<PongMessage> |
getPongMessageHandler() |
java.lang.String |
getProtocolVersion() |
java.lang.String |
getQueryString() |
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getRequestParameterMap() |
java.net.URI |
getRequestURI() |
protected MessageHandler |
getTextMessageHandler() |
java.security.Principal |
getUserPrincipal() |
java.util.Map<java.lang.String,java.lang.Object> |
getUserProperties() |
boolean |
isOpen() |
boolean |
isSecure() |
void |
onClose(CloseReason closeReason)
Called when a close message is received.
|
protected void |
registerFuture(org.apache.tomcat.websocket.FutureToSendHandler f2sh)
Make the session aware of a
FutureToSendHandler that will need to
be forcibly closed if the session closes before the
FutureToSendHandler completes. |
void |
removeMessageHandler(MessageHandler listener) |
void |
setMaxBinaryMessageBufferSize(int max)
Set the current maximum buffer size for binary messages.
|
void |
setMaxIdleTimeout(long timeout)
Set the idle timeout for this session.
|
void |
setMaxTextMessageBufferSize(int max)
Set the maximum buffer size for text messages.
|
protected void |
unregisterFuture(org.apache.tomcat.websocket.FutureToSendHandler f2sh)
Remove a
FutureToSendHandler from the set of tracked instances. |
protected void |
updateLastActive() |
public WsSession(Endpoint localEndpoint, WsRemoteEndpointImplBase wsRemoteEndpoint, WsWebSocketContainer wsWebSocketContainer, java.net.URI requestUri, java.util.Map<java.lang.String,java.util.List<java.lang.String>> requestParameterMap, java.lang.String queryString, java.security.Principal userPrincipal, java.lang.String httpSessionId, java.util.List<Extension> negotiatedExtensions, java.lang.String subProtocol, java.util.Map<java.lang.String,java.lang.String> pathParameters, boolean secure, EndpointConfig endpointConfig) throws DeploymentException
Thread.getContextClassLoader()
at the time this constructor is called will be used when calling
Endpoint.onClose(Session, CloseReason)
.localEndpoint
- The end point managed by this codewsRemoteEndpoint
- The other / remote endpointwsWebSocketContainer
- The container that created this sessionrequestUri
- The URI used to connect to this endpoint or
null
is this is a client sessionrequestParameterMap
- The parameters associated with the request
that initiated this session or
null
if this is a client sessionqueryString
- The query string associated with the request
that initiated this session or
null
if this is a client sessionuserPrincipal
- The principal associated with the request
that initiated this session or
null
if this is a client sessionhttpSessionId
- The HTTP session ID associated with the
request that initiated this session or
null
if this is a client sessionnegotiatedExtensions
- The agreed extensions to use for this sessionsubProtocol
- The agreed subprotocol to use for this
sessionpathParameters
- The path parameters associated with the
request that initiated this session or
null
if this is a client sessionsecure
- Was this session initiated over a secure
connection?endpointConfig
- The configuration information for the
endpointDeploymentException
- if an invalid encode is specifiedpublic WebSocketContainer getContainer()
javax.websocket.Session
getContainer
in interface Session
public void addMessageHandler(MessageHandler listener)
javax.websocket.Session
MessageHandler
for incoming messages. Only one
MessageHandler
may be registered for each message type (text,
binary, pong). The message type will be derived at runtime from the
provided MessageHandler
instance. It is not always possible to do
this so it is better to use
Session.addMessageHandler(Class, javax.websocket.MessageHandler.Partial)
or
Session.addMessageHandler(Class, javax.websocket.MessageHandler.Whole)
.addMessageHandler
in interface Session
listener
- The message handler for a incoming messagepublic <T> void addMessageHandler(java.lang.Class<T> clazz, MessageHandler.Partial<T> handler) throws java.lang.IllegalStateException
javax.websocket.Session
MessageHandler
for partial incoming messages. Only
one MessageHandler
may be registered for each message type (text
or binary, pong messages are never presented as partial messages).addMessageHandler
in interface Session
T
- The type of message that the given handler is intended
forclazz
- The Class that implements Thandler
- The message handler for a incoming messagejava.lang.IllegalStateException
- If a message handler has already been
registered for the associated message typepublic <T> void addMessageHandler(java.lang.Class<T> clazz, MessageHandler.Whole<T> handler) throws java.lang.IllegalStateException
javax.websocket.Session
MessageHandler
for whole incoming messages. Only
one MessageHandler
may be registered for each message type (text,
binary, pong).addMessageHandler
in interface Session
T
- The type of message that the given handler is intended
forclazz
- The Class that implements Thandler
- The message handler for a incoming messagejava.lang.IllegalStateException
- If a message handler has already been
registered for the associated message typepublic java.util.Set<MessageHandler> getMessageHandlers()
getMessageHandlers
in interface Session
public void removeMessageHandler(MessageHandler listener)
removeMessageHandler
in interface Session
public java.lang.String getProtocolVersion()
getProtocolVersion
in interface Session
public java.lang.String getNegotiatedSubprotocol()
getNegotiatedSubprotocol
in interface Session
public java.util.List<Extension> getNegotiatedExtensions()
getNegotiatedExtensions
in interface Session
public long getMaxIdleTimeout()
javax.websocket.Session
getMaxIdleTimeout
in interface Session
public void setMaxIdleTimeout(long timeout)
javax.websocket.Session
setMaxIdleTimeout
in interface Session
timeout
- The new idle timeout for this session in milliseconds.
Zero or negative values indicate an infinite timeout.public void setMaxBinaryMessageBufferSize(int max)
javax.websocket.Session
setMaxBinaryMessageBufferSize
in interface Session
max
- The new maximum buffer size in bytespublic int getMaxBinaryMessageBufferSize()
javax.websocket.Session
getMaxBinaryMessageBufferSize
in interface Session
public void setMaxTextMessageBufferSize(int max)
javax.websocket.Session
setMaxTextMessageBufferSize
in interface Session
max
- The new maximum buffer size in characters.public int getMaxTextMessageBufferSize()
javax.websocket.Session
getMaxTextMessageBufferSize
in interface Session
public java.util.Set<Session> getOpenSessions()
javax.websocket.Session
getOpenSessions
in interface Session
public RemoteEndpoint.Async getAsyncRemote()
getAsyncRemote
in interface Session
public RemoteEndpoint.Basic getBasicRemote()
getBasicRemote
in interface Session
public void close() throws java.io.IOException
javax.websocket.Session
CloseReason.CloseCodes.NORMAL_CLOSURE
and an
empty reason phrase.public void close(CloseReason closeReason) throws java.io.IOException
javax.websocket.Session
public void doClose(CloseReason closeReasonMessage, CloseReason closeReasonLocal)
closeReasonMessage
- The close reason to pass to the remote endpointcloseReasonLocal
- The close reason to pass to the local endpointpublic void onClose(CloseReason closeReason)
closeReason
- The reason contained within the received close
message.protected static void appendCloseReasonWithTruncation(java.nio.ByteBuffer msg, java.lang.String reason)
msg
- The messagereason
- The reasonprotected void registerFuture(org.apache.tomcat.websocket.FutureToSendHandler f2sh)
FutureToSendHandler
that will need to
be forcibly closed if the session closes before the
FutureToSendHandler
completes.protected void unregisterFuture(org.apache.tomcat.websocket.FutureToSendHandler f2sh)
FutureToSendHandler
from the set of tracked instances.f2sh
- The handlerpublic java.net.URI getRequestURI()
getRequestURI
in interface Session
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestParameterMap()
getRequestParameterMap
in interface Session
public java.lang.String getQueryString()
getQueryString
in interface Session
public java.security.Principal getUserPrincipal()
getUserPrincipal
in interface Session
public java.util.Map<java.lang.String,java.lang.String> getPathParameters()
getPathParameters
in interface Session
public java.lang.String getId()
javax.websocket.Session
public java.util.Map<java.lang.String,java.lang.Object> getUserProperties()
getUserProperties
in interface Session
public Endpoint getLocal()
public java.lang.String getHttpSessionId()
protected MessageHandler getTextMessageHandler()
protected MessageHandler getBinaryMessageHandler()
protected MessageHandler.Whole<PongMessage> getPongMessageHandler()
protected void updateLastActive()
protected void checkExpiration()
Copyright © 2000-2018 Apache Software Foundation. All Rights Reserved.