Package javax.websocket
Interface Session
- 
- All Superinterfaces:
- java.lang.AutoCloseable,- java.io.Closeable
 
 public interface Session extends java.io.Closeable
- 
- 
Method SummaryAll Methods Instance Methods Abstract Methods Modifier and Type Method Description <T> voidaddMessageHandler(java.lang.Class<T> clazz, MessageHandler.Partial<T> handler)Registers aMessageHandlerfor partial incoming messages.<T> voidaddMessageHandler(java.lang.Class<T> clazz, MessageHandler.Whole<T> handler)Registers aMessageHandlerfor whole incoming messages.voidaddMessageHandler(MessageHandler handler)Registers aMessageHandlerfor incoming messages.voidclose()Close the connection to the remote end point using the codeCloseReason.CloseCodes.NORMAL_CLOSUREand an empty reason phrase.voidclose(CloseReason closeReason)Close the connection to the remote end point using the specified code and reason phrase.RemoteEndpoint.AsyncgetAsyncRemote()RemoteEndpoint.BasicgetBasicRemote()WebSocketContainergetContainer()Get the container that created this session.java.lang.StringgetId()Provides a unique identifier for the session.intgetMaxBinaryMessageBufferSize()Get the current maximum buffer size for binary messages.longgetMaxIdleTimeout()Get the idle timeout for this session.intgetMaxTextMessageBufferSize()Get the maximum buffer size for text messages.java.util.Set<MessageHandler>getMessageHandlers()java.util.List<Extension>getNegotiatedExtensions()java.lang.StringgetNegotiatedSubprotocol()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()java.lang.StringgetProtocolVersion()java.lang.StringgetQueryString()java.util.Map<java.lang.String,java.util.List<java.lang.String>>getRequestParameterMap()java.net.URIgetRequestURI()java.security.PrincipalgetUserPrincipal()java.util.Map<java.lang.String,java.lang.Object>getUserProperties()booleanisOpen()booleanisSecure()voidremoveMessageHandler(MessageHandler listener)voidsetMaxBinaryMessageBufferSize(int max)Set the current maximum buffer size for binary messages.voidsetMaxIdleTimeout(long timeout)Set the idle timeout for this session.voidsetMaxTextMessageBufferSize(int max)Set the maximum buffer size for text messages.
 
- 
- 
- 
Method Detail- 
getContainerWebSocketContainer getContainer() Get the container that created this session.- Returns:
- the container that created this session.
 
 - 
addMessageHandlervoid addMessageHandler(MessageHandler handler) throws java.lang.IllegalStateException Registers aMessageHandlerfor incoming messages. Only oneMessageHandlermay be registered for each message type (text, binary, pong). The message type will be derived at runtime from the providedMessageHandlerinstance. It is not always possible to do this so it is better to useaddMessageHandler(Class, javax.websocket.MessageHandler.Partial)oraddMessageHandler(Class, javax.websocket.MessageHandler.Whole).- Parameters:
- handler- The message handler for a incoming message
- Throws:
- java.lang.IllegalStateException- If a message handler has already been registered for the associated message type
 
 - 
getMessageHandlersjava.util.Set<MessageHandler> getMessageHandlers() 
 - 
removeMessageHandlervoid removeMessageHandler(MessageHandler listener) 
 - 
getProtocolVersionjava.lang.String getProtocolVersion() 
 - 
getNegotiatedSubprotocoljava.lang.String getNegotiatedSubprotocol() 
 - 
getNegotiatedExtensionsjava.util.List<Extension> getNegotiatedExtensions() 
 - 
isSecureboolean isSecure() 
 - 
isOpenboolean isOpen() 
 - 
getMaxIdleTimeoutlong getMaxIdleTimeout() Get the idle timeout for this session.- Returns:
- The current idle timeout for this session in milliseconds. Zero or negative values indicate an infinite timeout.
 
 - 
setMaxIdleTimeoutvoid setMaxIdleTimeout(long timeout) Set the idle timeout for this session.- Parameters:
- timeout- The new idle timeout for this session in milliseconds. Zero or negative values indicate an infinite timeout.
 
 - 
setMaxBinaryMessageBufferSizevoid setMaxBinaryMessageBufferSize(int max) Set the current maximum buffer size for binary messages.- Parameters:
- max- The new maximum buffer size in bytes
 
 - 
getMaxBinaryMessageBufferSizeint getMaxBinaryMessageBufferSize() Get the current maximum buffer size for binary messages.- Returns:
- The current maximum buffer size in bytes
 
 - 
setMaxTextMessageBufferSizevoid setMaxTextMessageBufferSize(int max) Set the maximum buffer size for text messages.- Parameters:
- max- The new maximum buffer size in characters.
 
 - 
getMaxTextMessageBufferSizeint getMaxTextMessageBufferSize() Get the maximum buffer size for text messages.- Returns:
- The maximum buffer size in characters.
 
 - 
getAsyncRemoteRemoteEndpoint.Async getAsyncRemote() 
 - 
getBasicRemoteRemoteEndpoint.Basic getBasicRemote() 
 - 
getIdjava.lang.String getId() Provides a unique identifier for the session. This identifier should not be relied upon to be generated from a secure random source.- Returns:
- A unique identifier for the session.
 
 - 
closevoid close() throws java.io.IOExceptionClose the connection to the remote end point using the codeCloseReason.CloseCodes.NORMAL_CLOSUREand an empty reason phrase.- Specified by:
- closein interface- java.lang.AutoCloseable
- Specified by:
- closein interface- java.io.Closeable
- Throws:
- java.io.IOException- if an I/O error occurs while the WebSocket session is being closed.
 
 - 
closevoid close(CloseReason closeReason) throws java.io.IOException Close the connection to the remote end point using the specified code and reason phrase.- Parameters:
- closeReason- The reason the WebSocket session is being closed.
- Throws:
- java.io.IOException- if an I/O error occurs while the WebSocket session is being closed.
 
 - 
getRequestURIjava.net.URI getRequestURI() 
 - 
getRequestParameterMapjava.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestParameterMap() 
 - 
getQueryStringjava.lang.String getQueryString() 
 - 
getPathParametersjava.util.Map<java.lang.String,java.lang.String> getPathParameters() 
 - 
getUserPropertiesjava.util.Map<java.lang.String,java.lang.Object> getUserProperties() 
 - 
getUserPrincipaljava.security.Principal getUserPrincipal() 
 - 
getOpenSessionsjava.util.Set<Session> getOpenSessions() Obtain the set of open sessions associated with the same local endpoint as this session.- Returns:
- The set of currently open sessions for the local endpoint that this session is associated with.
 
 - 
addMessageHandler<T> void addMessageHandler(java.lang.Class<T> clazz, MessageHandler.Partial<T> handler) throws java.lang.IllegalStateExceptionRegisters aMessageHandlerfor partial incoming messages. Only oneMessageHandlermay be registered for each message type (text or binary, pong messages are never presented as partial messages).- Type Parameters:
- T- The type of message that the given handler is intended for
- Parameters:
- clazz- The Class that implements T
- handler- The message handler for a incoming message
- Throws:
- java.lang.IllegalStateException- If a message handler has already been registered for the associated message type
- Since:
- WebSocket 1.1
 
 - 
addMessageHandler<T> void addMessageHandler(java.lang.Class<T> clazz, MessageHandler.Whole<T> handler) throws java.lang.IllegalStateExceptionRegisters aMessageHandlerfor whole incoming messages. Only oneMessageHandlermay be registered for each message type (text, binary, pong).- Type Parameters:
- T- The type of message that the given handler is intended for
- Parameters:
- clazz- The Class that implements T
- handler- The message handler for a incoming message
- Throws:
- java.lang.IllegalStateException- If a message handler has already been registered for the associated message type
- Since:
- WebSocket 1.1
 
 
- 
 
-