public class WsSessions extends Object
Sessions currently connected with the server.
The choice of the key for the map is up to the caller.
A sessionId of a UI client's Session or a feed's 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
newSession 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)
newSession under the given key.
If there is already a session associated with the given key, the given newSession 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.
When adding a session, that new session's websocket session listeners will be told via
WsSessionListener.sessionAdded().
key - the key (feedId or sessionId) that will be associated with 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.
A listener-producer is just a bi-function that takes a key string (like a UI client session ID or a feed ID)
and a websocket Session and produces a websocket session listener. A websocket session listener
has the job of performing tasks when a websocket client connects and disconnects (for example, when a
websocket client connects and its websocket session is created, a websocket session listener will then need to
add bus listeners so the websocket client's messages can be processed properly).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.
When removing a known session, that doomed session's websocket session listeners will be told via
WsSessionListener.sessionRemoved().
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 © 2014–2017 Red Hat, Inc.. All rights reserved.