Class TableClient

java.lang.Object
io.deephaven.sbe.standalone.client.TableClient
All Implemented Interfaces:
AutoCloseable

public class TableClient
extends Object
implements AutoCloseable
A reference client for the Deephaven SBE table server.

This is intended as an illustration, not necessarily the most efficient way to implement a client.

Depending on the context, it may be desirable to implement an alternative to SimpleMessageHandler in a way that avoids memory allocation, decoding incoming SBE messages into existing buffers.

  • Field Details

  • Constructor Details

    • TableClient

      public TableClient​(String host, int port, MessageHandler messageHandler, boolean allocateDirect) throws IOException
      Start a new table client, connecting to the given host and port. Incoming messages will be sent to the given messageHandler object.
      Parameters:
      host - Host on which the TableServer is running
      port - Port on which the TableServer is bound
      messageHandler - Object which handles incoming messages from the server
      allocateDirect - If true, use direct (off-heap) buffers to allocate message buffers
      Throws:
      IOException - If there is an error while connecting to the server
    • TableClient

      public TableClient​(String host, int port, MessageHandler messageHandler) throws IOException
      Start a new table client, connecting to the given host and port. Incoming messages will be sent to the given messageHandler object. Message buffers will be allocated on the java heap (see TableClient(String, int, MessageHandler, boolean)
      Parameters:
      host - Host on which the TableServer is running
      port - Port on which the TableServer is bound
      messageHandler - Object which handles incoming messages from the server
      Throws:
      IOException - If there is an error while connecting to the server
  • Method Details

    • isAlive

      public boolean isAlive()
      Return if the client is still alive and processing incoming messages. Prior to death, the client should issue an handleConnectionError callback (unless death occurs through the close() method.
      Returns:
      true if the client is still connected, false otherwise
    • close

      public void close() throws InterruptedException, IOException
      Close the table client. This closes the socket connection and waits for the receive thread to die.
      Specified by:
      close in interface AutoCloseable
      Throws:
      InterruptedException - If interrupted while waiting for receive thread to die
      IOException - If an error occurs while closing the socket
    • subscribe

      public void subscribe​(int subscriptionId, SubscribeMode subscribeMode, String name, List<String> columnNames) throws IOException
      Subscribe to an exported table. The given subscriptionId must be generated by the client and must be unique for this client. It will be used in all subsequent messages to identify updates for this subscription.
      Parameters:
      subscriptionId - A client generated unique identifier for this subscription
      subscribeMode - Specifies whether the client is requesting an initial snapshot, update stream, or both
      name - Exported table name (see exportTable on TableServer)
      columnNames - List of columns for for which to receive updates (specify null for all columns)
      Throws:
      IOException - If an error occurs while sending to the server
    • subscribe

      public void subscribe​(int subscriptionId, SubscribeMode subscribeMode, String name) throws IOException
      Subscribe to an exported table. The given subscriptionId must be generated by the client and must be unique for this client. It will be used in all subsequent messages to identify updates for this subscription.
      Parameters:
      subscriptionId - A client generated unique identifier for this subscription
      subscribeMode - Specifies whether the client is requesting an initial snapshot, update stream, or both
      name - Exported table name (see exportTable on TableServer)
      Throws:
      IOException - If an error occurs while sending to the server
    • subscribe

      public void subscribe​(int subscriptionId, SubscribeMode subscribeMode, String name, List<String> columnNames, String filter) throws IOException
      Subscribe to updates on the given columns for the table identified by the given name. A client may subscribe to the same table any number of times, if unique subscription identifiers are provided for each subscription.
      Parameters:
      subscriptionId - A client generated unique identifier for this subscription
      subscribeMode - Specifies whether the client is requesting an initial snapshot, update stream, or both
      name - Exported table name (see exportTable on TableServer)
      columnNames - List of columns for for which to receive updates (specify null for all columns)
      filter - An expression to be used in a "where" clause to filter the desired table; in this way, only rows matching specified the criteria can be monitored (specify null for no filter)
      Throws:
      IOException - If an error occurs while sending to the server
    • unsubscribe

      public void unsubscribe​(int subscriptionId) throws IOException
      Unsubscribe from updates for the given subscription id.
      Parameters:
      subscriptionId - A subscription id previously used in a subscribe call
      Throws:
      IOException - If an error occurs while sending to the server