public class WsSessions extends Object
Sessions currently connected with the server. The choice of the key fro the map is up to
the caller. A sessionId of a Session or a feedId are the most prominent candidates for keys.
A thread safety note: this class uses a ReadWriteLock internally, hence its public methods can be safely
called from multiple threads.
| Constructor and Description |
|---|
WsSessions(String endpoint) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addSession(String key,
javax.websocket.Session newSession)
Stores the given
session under the given key. |
void |
addWsSessionListenerProducer(BiFunction<String,javax.websocket.Session,WsSessionListener> wsSessionListenerProducer)
Add the given
wsSessionListenerProducers to the internal list of WsSessionListener producers. |
void |
destroy() |
javax.websocket.Session |
getSession(String key)
Returns the
Session stored under the given key or null if there is no such session. |
void |
removeSession(String key,
javax.websocket.Session doomedSession)
Removes the session associated with the given
key. |
void |
removeWsSessionListenerProducer(BiFunction<String,javax.websocket.Session,WsSessionListener> wsSessionListenerProducer)
Remove the given
wsSessionListenerProducers from the internal list of WsSessionListener
producers. |
public WsSessions(String endpoint)
public boolean addSession(String key, javax.websocket.Session newSession)
session under the given key. If there is already a session associated with the
given key, the given session is closed, it is not added or associated with the given key and an
error will be logged. The original session remains associated with the key.key - the key (feedId or sessionId) that will be associated wit the new sessionnewSession - the new session to addtrue if the session was added; false otherwise.public void addWsSessionListenerProducer(BiFunction<String,javax.websocket.Session,WsSessionListener> wsSessionListenerProducer)
wsSessionListenerProducers to the internal list of WsSessionListener producers.wsSessionListenerProducer - a function that produces WsSessionListener for a given pair of
sessionKey and Session.public javax.websocket.Session getSession(String key)
Session stored under the given key or null if there is no such session.key - the key to look forSession stored under the given key or null if there is no such session.public void removeSession(String key, javax.websocket.Session doomedSession)
key. If doomedSession is not null, the
session matching the given key in sessions will only be removed if that session has the same ID
as the given doomedSession.key - identifies the session to be removeddoomedSession - if not null, ensures that only this session will be removedpublic void destroy()
public void removeWsSessionListenerProducer(BiFunction<String,javax.websocket.Session,WsSessionListener> wsSessionListenerProducer)
wsSessionListenerProducers from the internal list of WsSessionListener
producers.wsSessionListenerProducer - a function that produces WsSessionListener for a given pair of
sessionKey and Session.Copyright © 2015 Red Hat. All rights reserved.