public class WsSession extends Object implements Session
| Constructor and Description |
|---|
WsSession(Endpoint localEndpoint,
WsRemoteEndpointImplBase wsRemoteEndpoint,
WsWebSocketContainer wsWebSocketContainer,
URI requestUri,
Map<String,List<String>> requestParameterMap,
String queryString,
Principal userPrincipal,
String httpSessionId,
List<Extension> negotiatedExtensions,
String subProtocol,
Map<String,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(Class<T> clazz,
MessageHandler.Partial<T> handler)
Registers a
MessageHandler for partial incoming messages. |
<T> void |
addMessageHandler(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(ByteBuffer msg,
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.
|
String |
getHttpSessionId() |
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.
|
Set<MessageHandler> |
getMessageHandlers() |
List<Extension> |
getNegotiatedExtensions() |
String |
getNegotiatedSubprotocol() |
Set<Session> |
getOpenSessions()
Obtain the set of open sessions associated with the same local endpoint
as this session.
|
Map<String,String> |
getPathParameters() |
protected MessageHandler.Whole<PongMessage> |
getPongMessageHandler() |
String |
getProtocolVersion() |
String |
getQueryString() |
Map<String,List<String>> |
getRequestParameterMap() |
URI |
getRequestURI() |
protected MessageHandler |
getTextMessageHandler() |
Principal |
getUserPrincipal() |
Map<String,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, URI requestUri, Map<String,List<String>> requestParameterMap, String queryString, Principal userPrincipal, String httpSessionId, List<Extension> negotiatedExtensions, String subProtocol, Map<String,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 - wsRemoteEndpoint - negotiatedExtensions - DeploymentExceptionpublic WebSocketContainer getContainer()
javax.websocket.SessiongetContainer in interface Sessionpublic void addMessageHandler(MessageHandler listener)
javax.websocket.SessionMessageHandler 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 Sessionlistener - The message handler for a incoming messagepublic <T> void addMessageHandler(Class<T> clazz, MessageHandler.Partial<T> handler) throws IllegalStateException
javax.websocket.SessionMessageHandler 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 SessionT - The type of message that the given handler is intended
forclazz - The Class that implements Thandler - The message handler for a incoming messageIllegalStateException - If a message handler has already been
registered for the associated message typepublic <T> void addMessageHandler(Class<T> clazz, MessageHandler.Whole<T> handler) throws IllegalStateException
javax.websocket.SessionMessageHandler for whole incoming messages. Only
one MessageHandler may be registered for each message type (text,
binary, pong).addMessageHandler in interface SessionT - The type of message that the given handler is intended
forclazz - The Class that implements Thandler - The message handler for a incoming messageIllegalStateException - If a message handler has already been
registered for the associated message typepublic Set<MessageHandler> getMessageHandlers()
getMessageHandlers in interface Sessionpublic void removeMessageHandler(MessageHandler listener)
removeMessageHandler in interface Sessionpublic String getProtocolVersion()
getProtocolVersion in interface Sessionpublic String getNegotiatedSubprotocol()
getNegotiatedSubprotocol in interface Sessionpublic List<Extension> getNegotiatedExtensions()
getNegotiatedExtensions in interface Sessionpublic long getMaxIdleTimeout()
javax.websocket.SessiongetMaxIdleTimeout in interface Sessionpublic void setMaxIdleTimeout(long timeout)
javax.websocket.SessionsetMaxIdleTimeout in interface Sessiontimeout - The new idle timeout for this session in milliseconds.
Zero or negative values indicate an infinite timeout.public void setMaxBinaryMessageBufferSize(int max)
javax.websocket.SessionsetMaxBinaryMessageBufferSize in interface Sessionmax - The new maximum buffer size in bytespublic int getMaxBinaryMessageBufferSize()
javax.websocket.SessiongetMaxBinaryMessageBufferSize in interface Sessionpublic void setMaxTextMessageBufferSize(int max)
javax.websocket.SessionsetMaxTextMessageBufferSize in interface Sessionmax - The new maximum buffer size in characters.public int getMaxTextMessageBufferSize()
javax.websocket.SessiongetMaxTextMessageBufferSize in interface Sessionpublic Set<Session> getOpenSessions()
javax.websocket.SessiongetOpenSessions in interface Sessionpublic RemoteEndpoint.Async getAsyncRemote()
getAsyncRemote in interface Sessionpublic RemoteEndpoint.Basic getBasicRemote()
getBasicRemote in interface Sessionpublic void close()
throws IOException
javax.websocket.SessionCloseReason.CloseCodes.NORMAL_CLOSURE and an
empty reason phrase.close in interface Closeableclose in interface AutoCloseableclose in interface SessionIOException - if an I/O error occurs while the WebSocket session is
being closed.public void close(CloseReason closeReason) throws IOException
javax.websocket.Sessionclose in interface SessioncloseReason - The reason the WebSocket session is being closed.IOException - if an I/O error occurs while the WebSocket session is
being closed.public void doClose(CloseReason closeReasonMessage, CloseReason closeReasonLocal)
public void onClose(CloseReason closeReason)
protected static void appendCloseReasonWithTruncation(ByteBuffer msg, String reason)
protected 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.public URI getRequestURI()
getRequestURI in interface Sessionpublic Map<String,List<String>> getRequestParameterMap()
getRequestParameterMap in interface Sessionpublic String getQueryString()
getQueryString in interface Sessionpublic Principal getUserPrincipal()
getUserPrincipal in interface Sessionpublic Map<String,String> getPathParameters()
getPathParameters in interface Sessionpublic String getId()
javax.websocket.Sessionpublic Map<String,Object> getUserProperties()
getUserProperties in interface Sessionpublic Endpoint getLocal()
public String getHttpSessionId()
protected MessageHandler getTextMessageHandler()
protected MessageHandler getBinaryMessageHandler()
protected MessageHandler.Whole<PongMessage> getPongMessageHandler()
protected void updateLastActive()
protected void checkExpiration()
Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.