Package no.polaric.core.httpd
Class PubSub
java.lang.Object
no.polaric.core.httpd.ServerBase
no.polaric.core.httpd.WsNotifier
no.polaric.core.httpd.PubSub
- All Implemented Interfaces:
SesNotifier
,ServerConfig.PubSub
Generic publish/subscribe service using websocket.
Ciients first connect to the websocket. The following commands are then available:
SUBSCRIBE,room - subscribe to a room (get messages posted to that room)
UNSUBSCRIBE,room - unsubscribe
PUT,room,message - post a message to a room - only subscribers are allowed to post.
A room must be created on the server side before being subscribed to (see createRoom methods)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
static class
Room.static class
Message content to be exchangedstatic class
Room which is only for clients having a specific username.Nested classes/interfaces inherited from interface no.polaric.core.httpd.SesNotifier
SesNotifier.SHandler
-
Field Summary
Fields inherited from class no.polaric.core.httpd.WsNotifier
_clients
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
createRoom
(String name, boolean lg, boolean operator, boolean adm, boolean post, Class cl) Create a room with restricted accessvoid
createRoom
(String name, Class cl) Create a roomvoid
createUserRoom
(String name, String userid, Class cl) Create a room for a given useridboolean
Check if a room existsnewClient
(io.javalin.websocket.WsContext ctx) Factory method.void
Post a object to a room (JSON encoded)void
Post a object to a room (JSON encoded)void
Post a message to a room (text is prefixed with the room name)void
Post a message to a room (text is prefixed with the room name)void
removeRoom
(String name) Remove a roomprotected boolean
subscribe
(io.javalin.websocket.WsContext ctx, WsNotifier.Client client) Subscribe a client to the service.protected void
subscribe
(PubSub.Client c, String rid) subscribe a client to a room.protected void
unsubscribe
(PubSub.Client c, String rid) unsubscribe a client from a room.Methods inherited from class no.polaric.core.httpd.WsNotifier
authenticate, clients, closeSes, nClients, nLoggedIn, nLogins, nVisits, onCloseSes, onOpenSes, postText, postText, sesId, start
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, wServer
-
Constructor Details
-
PubSub
-
-
Method Details
-
subscribe
Description copied from class:WsNotifier
Subscribe a client to the service. Should be overridden in subclass. This may include authorization, preferences, etc..- Overrides:
subscribe
in classWsNotifier
- Returns:
- true if subscription is accepted. False if rejected.
-
subscribe
subscribe a client to a room. -
unsubscribe
unsubscribe a client from a room. -
createRoom
Create a room- Specified by:
createRoom
in interfaceServerConfig.PubSub
-
createRoom
public void createRoom(String name, boolean lg, boolean operator, boolean adm, boolean post, Class cl) Create a room with restricted access- Specified by:
createRoom
in interfaceServerConfig.PubSub
-
createUserRoom
Create a room for a given userid -
removeRoom
Remove a room -
hasRoom
Check if a room exists -
putText
Post a message to a room (text is prefixed with the room name) -
putText
Description copied from interface:ServerConfig.PubSub
Post a message to a room (text is prefixed with the room name)- Specified by:
putText
in interfaceServerConfig.PubSub
-
put
Post a object to a room (JSON encoded)- Specified by:
put
in interfaceServerConfig.PubSub
-
put
Description copied from interface:ServerConfig.PubSub
Post a object to a room (JSON encoded)- Specified by:
put
in interfaceServerConfig.PubSub
-
newClient
Factory method.- Specified by:
newClient
in classWsNotifier
-