public class TyrusSession extends Object implements Session, DistributedSession
Session.| Modifier and Type | Method and Description |
|---|---|
<T> void |
addMessageHandler(Class<T> clazz,
MessageHandler.Partial<T> handler)
Register to handle to incoming messages in this conversation.
|
<T> void |
addMessageHandler(Class<T> clazz,
MessageHandler.Whole<T> handler)
Register to handle to incoming messages in this conversation.
|
void |
addMessageHandler(MessageHandler handler)
|
Map<Session,Future<?>> |
broadcast(ByteBuffer message)
Broadcasts binary message to all connected clients, including remote sessions (if any).
|
Map<Session,Future<?>> |
broadcast(String message)
Broadcasts text message to all connected clients.
|
void |
close()
Close the current conversation with a normal status code and no reason phrase.
|
void |
close(CloseReason closeReason)
Close the current conversation, giving a reason for the closure.
|
Set<DistributedSession> |
getAllSessions()
Get set of all sessions opened to the same endpoint.
|
RemoteEndpoint.Async |
getAsyncRemote()
Return a reference a RemoteEndpoint object representing the peer of this conversation
that is able to send messages asynchronously to the peer.
|
RemoteEndpoint.Basic |
getBasicRemote()
Return a reference a RemoteEndpoint object representing the peer of this conversation
that is able to send messages synchronously to the peer.
|
WebSocketContainer |
getContainer()
Return the container that this session is part of.
|
Map<String,Object> |
getDistributedProperties()
Get distributed properties.
|
long |
getHeartbeatInterval()
Return an interval in milliseconds between scheduled periodic Pong messages.
|
String |
getId()
Returns a string containing the unique identifier assigned to this session.
|
int |
getMaxBinaryMessageBufferSize()
The maximum length of incoming binary messages that this Session can buffer.
|
long |
getMaxIdleTimeout()
Return the number of milliseconds before this conversation may be closed by the
container if it is inactive, i.e.
|
int |
getMaxTextMessageBufferSize()
The maximum length of incoming text messages that this Session can buffer.
|
Set<MessageHandler> |
getMessageHandlers()
Return an unmodifiable copy of the set of MessageHandlers for this Session.
|
List<Extension> |
getNegotiatedExtensions()
Return the list of extensions currently in use for this conversation.
|
String |
getNegotiatedSubprotocol()
Return the sub protocol agreed during the websocket handshake for this conversation.
|
Set<Session> |
getOpenSessions()
Return a copy of the Set of all the open web socket sessions that represent
connections to the same endpoint to which this session represents a connection.
|
Map<String,String> |
getPathParameters()
Return a map of the path parameter names and values used associated with the
request this session was opened under.
|
String |
getProtocolVersion()
Returns the version of the websocket protocol currently being used.
|
String |
getQueryString()
Return the query string associated with the request this session
was opened under.
|
String |
getRemoteAddr()
Get the Internet Protocol (IP) address of the client or last proxy that sent the request.
|
Set<RemoteSession> |
getRemoteSessions()
Get set of remote sessions.
|
Map<String,List<String>> |
getRequestParameterMap()
Return the request parameters associated with the request this session
was opened under.
|
URI |
getRequestURI()
Return the URI under which this session was opened, including
the query string if there is one.
|
Principal |
getUserPrincipal()
Return the authenticated user for this Session or
null if no user is authenticated for this session. |
Map<String,Object> |
getUserProperties()
While the session is open, this method returns a Map that the developer may
use to store application specific information relating to this session
instance.
|
boolean |
isOpen()
Return true if and only if the underlying socket is open.
|
boolean |
isSecure()
Return true if and only if the underlying socket is using a secure transport.
|
void |
removeMessageHandler(MessageHandler handler)
Remove the given MessageHandler from the set belonging to this session.
|
void |
setHeartbeatInterval(long heartbeatInterval)
Set an interval in milliseconds between scheduled periodic Pong messages.
|
void |
setMaxBinaryMessageBufferSize(int maxBinaryMessageBufferSize)
Sets the maximum length of incoming binary messages that this Session can buffer.
|
void |
setMaxIdleTimeout(long maxIdleTimeout)
Set the non-zero number of milliseconds before this session will be closed by the
container if it is inactive, ie no messages are either sent or received.
|
void |
setMaxTextMessageBufferSize(int maxTextMessageBufferSize)
Sets the maximum length of incoming text messages that this Session can buffer.
|
String |
toString() |
public String getProtocolVersion()
SessiongetProtocolVersion in interface Sessionpublic String getNegotiatedSubprotocol()
SessiongetNegotiatedSubprotocol in interface Sessionpublic RemoteEndpoint.Async getAsyncRemote()
SessiongetAsyncRemote in interface Sessionpublic RemoteEndpoint.Basic getBasicRemote()
SessiongetBasicRemote in interface Sessionpublic boolean isOpen()
Sessionpublic void close()
throws IOException
Sessionclose in interface Closeableclose in interface AutoCloseableclose in interface SessionIOException - if there was a connection error closing the connection.public void close(CloseReason closeReason) throws IOException
SessionCloseReason.CloseCodes.NO_STATUS_CODE.close in interface SessioncloseReason - the reason for the closure.IOException - if there was a connection error closing the connectionpublic int getMaxBinaryMessageBufferSize()
SessionCloseReason.CloseCodes.TOO_BIG.getMaxBinaryMessageBufferSize in interface Sessionpublic void setMaxBinaryMessageBufferSize(int maxBinaryMessageBufferSize)
SessionsetMaxBinaryMessageBufferSize in interface SessionmaxBinaryMessageBufferSize - the maximum length.public int getMaxTextMessageBufferSize()
SessionCloseReason.CloseCodes.TOO_BIG.getMaxTextMessageBufferSize in interface Sessionpublic void setMaxTextMessageBufferSize(int maxTextMessageBufferSize)
SessionsetMaxTextMessageBufferSize in interface SessionmaxTextMessageBufferSize - the maximum length.public Set<Session> getOpenSessions()
SessiongetOpenSessions in interface Sessionpublic Set<RemoteSession> getRemoteSessions()
Remote sessions are websocket sessions which are bound to another node in the cluster.
public Set<DistributedSession> getAllSessions()
Set returned from this method contains all "local" and remote sessions (if any).
RemoteSessionpublic List<Extension> getNegotiatedExtensions()
SessiongetNegotiatedExtensions in interface Sessionpublic long getMaxIdleTimeout()
SessiongetMaxIdleTimeout in interface Sessionpublic void setMaxIdleTimeout(long maxIdleTimeout)
SessionsetMaxIdleTimeout in interface SessionmaxIdleTimeout - the number of milliseconds.public boolean isSecure()
Sessionpublic WebSocketContainer getContainer()
SessiongetContainer in interface Sessionpublic void addMessageHandler(MessageHandler handler)
addMessageHandler(Class, javax.websocket.MessageHandler.Whole) or addMessageHandler(Class, javax.websocket.MessageHandler.Partial)MessageHandler.Whole and MessageHandler.Partial.
Adding more than one of any one type will result in a runtime exception.
This method is not safe to use unless you are providing an anonymous class derived directly
from MessageHandler.Whole or MessageHandler.Partial.
In all other cases (Lambda Expressions, more complex inheritance or generic type arrangements),
one of the following methods have to be used:
Session.addMessageHandler(Class, javax.websocket.MessageHandler.Whole) or
Session.addMessageHandler(Class, javax.websocket.MessageHandler.Partial).
addMessageHandler in interface Sessionhandler - the MessageHandler to be added.public <T> void addMessageHandler(Class<T> clazz, MessageHandler.Whole<T> handler)
MessageHandler.Whole and MessageHandler.Partial.
Adding more than one of any one type will result in a runtime exception.
See Endpoint for a usage example.
addMessageHandler in interface Sessionclazz - type of the message processed by message handler to be registered.handler - the MessageHandler to be added.IllegalStateException - if there is already a MessageHandler registered for the same native
websocket message type as this handler.public <T> void addMessageHandler(Class<T> clazz, MessageHandler.Partial<T> handler)
MessageHandler.Whole and MessageHandler.Partial.
Adding more than one of any one type will result in a runtime exception.
See Endpoint for a usage example.
addMessageHandler in interface Sessionclazz - type of the message processed by message handler to be registered.handler - the MessageHandler to be added.IllegalStateException - if there is already a MessageHandler registered for the same native
websocket message type as this handler.public Set<MessageHandler> getMessageHandlers()
SessiongetMessageHandlers in interface Sessionpublic void removeMessageHandler(MessageHandler handler)
SessionremoveMessageHandler in interface Sessionhandler - the handler to be removed.public URI getRequestURI()
SessiongetRequestURI in interface Sessionpublic Map<String,List<String>> getRequestParameterMap()
SessiongetRequestParameterMap in interface Sessionpublic Map<String,String> getPathParameters()
SessiongetPathParameters in interface Sessionpublic Map<String,Object> getUserProperties()
SessiongetUserProperties in interface Sessionpublic Map<String,Object> getDistributedProperties()
DistributedSession
Values put into this map must be Serializable or serializable by other, implementation-dependent
alternative.
Content of this map is synchronized among all cluster nodes, so putting an entry on any of the nodes will be
visible on all other nodes which have reference to current session (in form of TyrusSession or RemoteSession).
Please note that when not running in the distributed environment, this map behaves similarly to Session.getUserProperties(), so no serialization or deserialization is performed when values are read from or stored to
the returned map.
getDistributedProperties in interface DistributedSessionTyrusSession,
RemoteSessionpublic String getQueryString()
SessiongetQueryString in interface Sessionpublic String getId()
Sessionpublic Principal getUserPrincipal()
Sessionnull if no user is authenticated for this session.getUserPrincipal in interface Sessionpublic Map<Session,Future<?>> broadcast(String message)
The broadcast can be executed in parallel, which can be enabled by setting
TyrusWebSocketEngine.PARALLEL_BROADCAST_ENABLED
to true in server properties.
message - message to be broadcasted.public Map<Session,Future<?>> broadcast(ByteBuffer message)
The broadcast can be executed in parallel, which can be enabled by setting
TyrusWebSocketEngine.PARALLEL_BROADCAST_ENABLED
to true in server properties.
message - message to be broadcasted.public long getHeartbeatInterval()
public void setHeartbeatInterval(long heartbeatInterval)
heartbeatInterval - interval between periodic Pong messages in milliseconds.Copyright © 2012-2017, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.