Class Topica

java.lang.Object
fi.iki.elonen.NanoWSD.WebSocket
me.autobot.lib.server.topica.Topica

public class Topica extends fi.iki.elonen.NanoWSD.WebSocket
Topica, a topic based server that
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Database for the Topica server, containing all of the different topics.
    static class 
    The server for the Topica protocol.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final byte
    Type code denoting a boolean.
    static final byte
    Type code denoting a byte list.
    static final byte
    A custom type that has a custom encoding.
    static final byte
    Type code denoting a double.
    static final byte
    Type code denoting a float.
    static final byte
    Type code denoting an integer.
    static final byte
    Type code denoting a long.
    static final byte
    Type code denoting a short.
    static final byte
    Type code denoting a string.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Topica(fi.iki.elonen.NanoHTTPD.IHTTPSession handshakeRequest)
    Creates a new Topica WebSocket connection.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Creates a new Topica database.
    protected static String
    Generates a nickname
    Gets the database of the Topica server.
    protected static boolean
    Returns true or false depending on if the verbose setting is on.
    protected void
    onClose(fi.iki.elonen.NanoWSD.WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote)
    Closes the Topica WebSocket connection.
    protected void
    Called when an exception occurs.
    protected void
    onMessage(fi.iki.elonen.NanoWSD.WebSocketFrame message)
    Handles a message from the Topica WebSocket connection.
    protected void
    Creates a new Topica WebSocket connection.
    protected void
    onPong(fi.iki.elonen.NanoWSD.WebSocketFrame pong)
    Called on the pong frame.
    static void
    port(int port)
    Assigns the port to a custom port.
    protected void
    Sends the data of a topic to the client.
    protected void
    setTopicData(String topic, int[] unusedPayload)
    Sets the data of a topic.
    static void
    Starts a new Topica server on the default port or the custom port.
    protected void
    subscribeToTopic(String topic, int[] unusedPayload)
    Subscribes the websocket to a topic.
    topic(String path, byte type)
    Gets or creates a topic if it does not exist.

    Methods inherited from class fi.iki.elonen.NanoWSD.WebSocket

    close, debugFrameReceived, debugFrameSent, getHandshakeRequest, getHandshakeResponse, isOpen, ping, send, send, sendFrame

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BYTE_TYPE

      public static final byte BYTE_TYPE
      Type code denoting a byte list.
      See Also:
    • SHORT_TYPE

      public static final byte SHORT_TYPE
      Type code denoting a short.
      See Also:
    • INT_TYPE

      public static final byte INT_TYPE
      Type code denoting an integer.
      See Also:
    • LONG_TYPE

      public static final byte LONG_TYPE
      Type code denoting a long.
      See Also:
    • FLOAT_TYPE

      public static final byte FLOAT_TYPE
      Type code denoting a float.
      See Also:
    • DOUBLE_TYPE

      public static final byte DOUBLE_TYPE
      Type code denoting a double.
      See Also:
    • STRING_TYPE

      public static final byte STRING_TYPE
      Type code denoting a string.
      See Also:
    • BOOLEAN_TYPE

      public static final byte BOOLEAN_TYPE
      Type code denoting a boolean.
      See Also:
    • CUSTOM_TYPE

      public static final byte CUSTOM_TYPE
      A custom type that has a custom encoding. TODO: fix.
      See Also:
  • Constructor Details

    • Topica

      public Topica(fi.iki.elonen.NanoHTTPD.IHTTPSession handshakeRequest)
      Creates a new Topica WebSocket connection.
      Parameters:
      handshakeRequest - The handshake request.
  • Method Details

    • port

      public static void port(int port)
      Assigns the port to a custom port.
      Parameters:
      port - The port to start the server on.
    • isVerbose

      protected static boolean isVerbose()
      Returns true or false depending on if the verbose setting is on.
      Returns:
      If the Topica server is verbose, using /topica/verbose.
    • topic

      public static Topica.Database.Topic topic(String path, byte type)
      Gets or creates a topic if it does not exist.
      Parameters:
      path - The path of the topic.
      type - The type of the topic.
    • createDatabase

      public static void createDatabase()
      Creates a new Topica database.
    • start

      public static void start()
      Starts a new Topica server on the default port or the custom port.
    • getDatabase

      public static Topica.Database getDatabase()
      Gets the database of the Topica server.
      Returns:
      The database of the Topica server.
    • generateNickname

      protected static String generateNickname()
      Generates a nickname
      Returns:
      the new nickname
    • onOpen

      protected void onOpen()
      Creates a new Topica WebSocket connection.
      Specified by:
      onOpen in class fi.iki.elonen.NanoWSD.WebSocket
    • onClose

      protected void onClose(fi.iki.elonen.NanoWSD.WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote)
      Closes the Topica WebSocket connection.
      Specified by:
      onClose in class fi.iki.elonen.NanoWSD.WebSocket
      Parameters:
      code - The close code.
      reason - The reason for closing.
      initiatedByRemote - Whether the connection was closed by the remote.
    • onMessage

      protected void onMessage(fi.iki.elonen.NanoWSD.WebSocketFrame message)
      Handles a message from the Topica WebSocket connection.
      Specified by:
      onMessage in class fi.iki.elonen.NanoWSD.WebSocket
      Parameters:
      message - The message from the WebSocket.
    • sendTopicData

      protected void sendTopicData(String topic)
      Sends the data of a topic to the client.
      Parameters:
      topic - The topic to send the data of.
    • setTopicData

      protected void setTopicData(String topic, int[] unusedPayload)
      Sets the data of a topic.
      Parameters:
      topic - The topic to set the data of.
      unusedPayload - The payload containing the rest of the data request.s
    • subscribeToTopic

      protected void subscribeToTopic(String topic, int[] unusedPayload)
      Subscribes the websocket to a topic.
      Parameters:
      topic - The topic to subscribe to.
      unusedPayload - The payload containing the rest of the data request.
    • onPong

      protected void onPong(fi.iki.elonen.NanoWSD.WebSocketFrame pong)
      Called on the pong frame.
      Specified by:
      onPong in class fi.iki.elonen.NanoWSD.WebSocket
      Parameters:
      pong - The pong frame.
    • onException

      protected void onException(IOException exception)
      Called when an exception occurs.
      Specified by:
      onException in class fi.iki.elonen.NanoWSD.WebSocket
      Parameters:
      exception - The exception that occurred.