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 TypeClassDescriptionclassClient connection to publish/subscribe service.static classRoom.static classMessage content to be exchangedstatic classRoom 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 TypeMethodDescriptionvoidcreateRoom(String name, boolean lg, boolean operator, boolean adm, boolean post, Class cl) Create a room with restricted accessvoidcreateRoom(String name, Class cl) Create a roomvoidcreateUserRoom(String name, String userid, Class cl) Create a room for a given useridbooleanCheck if a room existsnewClient(io.javalin.websocket.WsContext ctx) Factory method.voidPost a object to a room (JSON encoded)voidPost a object to a room (JSON encoded)voidPost a message to a room (text is prefixed with the room name)voidPost a message to a room (text is prefixed with the room name)voidremoveRoom(String name) Remove a roomprotected booleansubscribe(io.javalin.websocket.WsContext ctx, WsNotifier.Client client) Subscribe a client to the service.protected voidsubscribe(PubSub.Client c, String rid) subscribe a client to a room.protected voidunsubscribe(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, startMethods 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
-
Constructor Details
-
PubSub
-
-
Method Details
-
subscribe
Description copied from class:WsNotifierSubscribe a client to the service. Should be overridden in subclass. This may include authorization, preferences, etc..- Overrides:
subscribein 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:
createRoomin 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:
createRoomin 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.PubSubPost a message to a room (text is prefixed with the room name)- Specified by:
putTextin interfaceServerConfig.PubSub
-
put
Post a object to a room (JSON encoded)- Specified by:
putin interfaceServerConfig.PubSub
-
put
Description copied from interface:ServerConfig.PubSubPost a object to a room (JSON encoded)- Specified by:
putin interfaceServerConfig.PubSub
-
newClient
Factory method.- Specified by:
newClientin classWsNotifier
-