Class PubSub

All Implemented Interfaces:
SesNotifier, ServerConfig.PubSub

public class PubSub extends WsNotifier implements 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)
  • Constructor Details

  • Method Details

    • subscribe

      protected boolean subscribe(io.javalin.websocket.WsContext ctx, WsNotifier.Client client)
      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 class WsNotifier
      Returns:
      true if subscription is accepted. False if rejected.
    • subscribe

      protected void subscribe(PubSub.Client c, String rid)
      subscribe a client to a room.
    • unsubscribe

      protected void unsubscribe(PubSub.Client c, String rid)
      unsubscribe a client from a room.
    • createRoom

      public void createRoom(String name, Class cl)
      Create a room
      Specified by:
      createRoom in interface ServerConfig.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 interface ServerConfig.PubSub
    • createUserRoom

      public void createUserRoom(String name, String userid, Class cl)
      Create a room for a given userid
    • removeRoom

      public void removeRoom(String name)
      Remove a room
    • hasRoom

      public boolean hasRoom(String name)
      Check if a room exists
    • putText

      public void putText(String rid, String msg, String uname)
      Post a message to a room (text is prefixed with the room name)
    • putText

      public void putText(String rid, String msg)
      Description copied from interface: ServerConfig.PubSub
      Post a message to a room (text is prefixed with the room name)
      Specified by:
      putText in interface ServerConfig.PubSub
    • put

      public void put(String rid, Object obj, String uname)
      Post a object to a room (JSON encoded)
      Specified by:
      put in interface ServerConfig.PubSub
    • put

      public void put(String rid, Object obj)
      Description copied from interface: ServerConfig.PubSub
      Post a object to a room (JSON encoded)
      Specified by:
      put in interface ServerConfig.PubSub
    • newClient

      public WsNotifier.Client newClient(io.javalin.websocket.WsContext ctx)
      Factory method.
      Specified by:
      newClient in class WsNotifier