Package no.polaric.core.httpd
Class WsNotifier
java.lang.Object
no.polaric.core.httpd.ServerBase
no.polaric.core.httpd.WsNotifier
- All Implemented Interfaces:
SesNotifier
Abstract base class for websocket services.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface no.polaric.core.httpd.SesNotifier
SesNotifier.SHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<io.javalin.websocket.WsContext, WsNotifier.Client> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionauthenticate(String qstring) Do authentication based on URL query-string.clients()Return collection of clientsprotected voidcloseSes(io.javalin.websocket.WsContext ctx) Close the client session.intnClients()Return number of clients.abstract WsNotifier.ClientnewClient(io.javalin.websocket.WsContext ctx) Factory methodintReturn number of logged-in userslongnLogins()Return number of loginslongnVisits()Return number of visitsvoidRegister a callback for close-session eventsvoidRegister a callback for open-session eventsvoidpostText(String txt, Predicate<WsNotifier.Client> pred) Distribute a text to the clients for which the predicate evaluates to true.voidpostText(Function<WsNotifier.Client, String> txt, Predicate<WsNotifier.Client> pred) Distribute a text to the clients for which the predicate evaluates to true.static StringsesId(io.javalin.websocket.WsContext ctx) Return session id.voidStart the websocket serviceprotected booleansubscribe(io.javalin.websocket.WsContext ctx, WsNotifier.Client client) Subscribe a client to the service.Methods inherited from class no.polaric.core.httpd.ServerBase
addSubtype, cleanPath, clientIpAddr, conf, deserializeJson, fixText, fromJson, getAuthInfo, icon, metaTag, protect, protect, roundDeg, serializeJson, systemNotification, toJson, urlDecode, wServer
-
Field Details
-
_clients
-
-
Constructor Details
-
WsNotifier
-
-
Method Details
-
newClient
Factory method -
nClients
public int nClients()Return number of clients. -
nVisits
public long nVisits()Return number of visits -
nLogins
public long nLogins()Return number of logins -
nLoggedIn
public int nLoggedIn()Return number of logged-in users -
clients
Return collection of clients -
authenticate
Do authentication based on URL query-string. Return an AuthInfo object if success. Return null if failure. The query string have 3 or 4 parameters: (1) userid, (2) nonce, (3) hmac, (4) role (optional). When computing the hmac the data field is empty. -
closeSes
protected void closeSes(io.javalin.websocket.WsContext ctx) Close the client session. -
onOpenSes
Register a callback for open-session events- Specified by:
onOpenSesin interfaceSesNotifier
-
onCloseSes
Register a callback for close-session events- Specified by:
onCloseSesin interfaceSesNotifier
-
subscribe
Subscribe a client to the service. Should be overridden in subclass. This may include authorization, preferences, etc..- Returns:
- true if subscription is accepted. False if rejected.
-
postText
Distribute a text to the clients for which the predicate evaluates to true. Text is generated by the given function. -
postText
Distribute a text to the clients for which the predicate evaluates to true. -
sesId
Return session id. The id is the last 8 digits of the session-id @ hostname -
start
Start the websocket service
-