Class TableServer

java.lang.Object
com.illumon.iris.sbetransport.server.TableServer
All Implemented Interfaces:
AutoCloseable

public class TableServer extends Object implements AutoCloseable
A server that uses an SBE (Simple Binary Encoding) protocol to distribute table updates to clients over TCP/IP. This service uses a publish-and subscribe model in which each client is allocated a queue that contains the outgoing messages. In order to avoid excessive memory allocation at runtime, each client connection uses a fixed-size message queue composed of fixed-size buffers.

Clients may subscribe only to tables "exported" by the server via exportTable(String name, DynamicTable table). The server may "unexport" a table at any time via unexportTable(String), which will prevent future subscriptions to that table, but existing subscriptions to that table are not closed.

When updates to an exported table occur, they will be sent to each subscribed client. If an update is too large to fit into a single message, it will be split into any number of SBE messages. Each table update is bracketed by BeginTableUpdate and EndTableUpdate messages so that the client can preserve atomicity.

Each client must consume messages fast enough to avoid being disconnected when the queue fills up. In order to avoid disconnections due to large bursts of data, the server will wait a limited period of time for an entry in the queue to free up (controlled by sendWaitTimeMillis).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final boolean
    Whether to allocate message buffers directly (off-heap).
    static final int
    Maximum size (in bytes) per message.
    static final int
    Maximum number of messages to enqueue per client.
    static final int
    Maximum time to wait for a free buffer when client queue is full.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close the table server, including any open client connections.
    void
    Make a table available for subscription by clients.
    start(int bindPort)
    Start a table server bound on the given port.
    start(int bindPort, int msgQueueSize, int msgBufferSize)
    Start a table server bound on the given port.
    start(int bindPort, int msgQueueSize, int msgBufferSize, int sendWaitTimeMillis, boolean allocateDirect, com.fishlib.io.logger.Logger logger)
    Start a table server bound on the given port, with the given message parameters.
    start(int bindPort, com.fishlib.io.logger.Logger logger)
    Start a table server bound on the given port.
    void
    Remove a table from the set available for subscription by clients.

    Methods inherited from class java.lang.Object

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

    • DEFAULT_MSG_QUEUE_SIZE

      public static final int DEFAULT_MSG_QUEUE_SIZE
      Maximum number of messages to enqueue per client.
      See Also:
    • DEFAULT_MSG_BUFFER_SIZE

      public static final int DEFAULT_MSG_BUFFER_SIZE
      Maximum size (in bytes) per message. This must be at least as large as the largest single value that might occur in a table column value, plus some encoding overhead (column updates will be split if necessary but individual values are not).
      See Also:
    • DEFAULT_SEND_WAIT_TIME_MILLIS

      public static final int DEFAULT_SEND_WAIT_TIME_MILLIS
      Maximum time to wait for a free buffer when client queue is full.
      See Also:
    • DEFAULT_ALLOCATE_DIRECT

      public static final boolean DEFAULT_ALLOCATE_DIRECT
      Whether to allocate message buffers directly (off-heap).
      See Also:
  • Method Details

    • start

      public static TableServer start(int bindPort) throws IOException
      Start a table server bound on the given port. These defaults will be used for the unspecified arguments:
      Message queue size: 100
      Message buffer size: 4096
      Send wait time (millis): 5000
      Allocate direct: false

      The default process logger will be used for logging.

      Parameters:
      bindPort - TCP port on which to wait for client connections
      Returns:
      A new running table server
      Throws:
      IOException - If there is an error binding on the given port
    • start

      public static TableServer start(int bindPort, com.fishlib.io.logger.Logger logger) throws IOException
      Start a table server bound on the given port. These defaults will be used for the unspecified arguments:
      Message queue size: 100
      Message buffer size: 4096
      Send wait time (millis): 5000
      Allocate direct: false
      Parameters:
      bindPort - TCP port on which to wait for client connections
      logger - Logger used for reporting client connections, disconnections and errors
      Returns:
      A new running table server
      Throws:
      IOException - If there is an error binding on the given port
    • start

      public static TableServer start(int bindPort, int msgQueueSize, int msgBufferSize) throws IOException
      Start a table server bound on the given port. These defaults will be used for the unspecified arguments:
      Send wait time (millis): 5000
      Allocate direct: false
      Parameters:
      bindPort - TCP port on which to wait for client connections
      msgQueueSize - Maximum number of messages to enqueue per client
      msgBufferSize - Maximum size in bytes of each outgoing message
      Returns:
      A new running table server
      Throws:
      IOException - If there is an error binding on the given port
    • start

      public static TableServer start(int bindPort, int msgQueueSize, int msgBufferSize, int sendWaitTimeMillis, boolean allocateDirect, com.fishlib.io.logger.Logger logger) throws IOException
      Start a table server bound on the given port, with the given message parameters.
      Parameters:
      bindPort - TCP port on which to wait for client connections
      msgQueueSize - Maximum number of messages to enqueue per client
      msgBufferSize - Maximum size in bytes of each outgoing message
      sendWaitTimeMillis - Maximum time to wait for a free message buffer when queue is full
      allocateDirect - If true, use direct buffers for message buffers (off-heap)
      logger - Logger used for reporting client connections, disconnections and errors
      Returns:
      A new running table server
      Throws:
      IOException - If there is an error binding on the given port
    • close

      public void close() throws IOException, InterruptedException
      Close the table server, including any open client connections.
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException - If there is an error closing the server socket or a client connection
      InterruptedException - If interrupted while waiting for the server to die
    • exportTable

      public void exportTable(String name, DynamicTable table)
      Make a table available for subscription by clients. Each table exported by this server must be assigned a unique name, which the client must use to identify it when sending a subscribe message.
      Parameters:
      name - Unique name for the same
      table - The table to export (must be DynamicTable)
    • unexportTable

      public void unexportTable(String name)
      Remove a table from the set available for subscription by clients. This does not close existing subscriptions.
      Parameters:
      name - Name of the table to remove (used when exportTable was called)