public class TableServer extends Object implements AutoCloseable
Clients may subscribe only to tables "exported" by the server via TableServer.exportTable(String name, DynamicTable table)
.
The server may "unexport" a table at any time via TableServer.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).
Modifier and Type | Field and Description |
---|---|
static boolean |
DEFAULT_ALLOCATE_DIRECT
Whether to allocate message buffers directly (off-heap).
|
static int |
DEFAULT_MSG_BUFFER_SIZE
Maximum size (in bytes) per message.
|
static int |
DEFAULT_MSG_QUEUE_SIZE
Maximum number of messages to enqueue per client.
|
static int |
DEFAULT_SEND_WAIT_TIME_MILLIS
Maximum time to wait for a free buffer when client queue is full.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the table server, including any open client connections.
|
void |
exportTable(String name,
DynamicTable table)
Make a table available for subscription by clients.
|
static TableServer |
start(int bindPort)
Start a table server bound on the given port.
|
static TableServer |
start(int bindPort,
int msgQueueSize,
int msgBufferSize)
Start a table server bound on the given port.
|
static TableServer |
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.
|
static TableServer |
start(int bindPort,
com.fishlib.io.logger.Logger logger)
Start a table server bound on the given port.
|
void |
unexportTable(String name)
Remove a table from the set available for subscription by clients.
|
public static final int DEFAULT_MSG_QUEUE_SIZE
public static final int DEFAULT_MSG_BUFFER_SIZE
public static final int DEFAULT_SEND_WAIT_TIME_MILLIS
public static final boolean DEFAULT_ALLOCATE_DIRECT
public static TableServer start(int bindPort) throws IOException
The default process logger will be used for logging.
bindPort
- TCP port on which to wait for client connectionsIOException
- If there is an error binding on the given portpublic static TableServer start(int bindPort, com.fishlib.io.logger.Logger logger) throws IOException
bindPort
- TCP port on which to wait for client connectionslogger
- Logger used for reporting client connections, disconnections and errorsIOException
- If there is an error binding on the given portpublic static TableServer start(int bindPort, int msgQueueSize, int msgBufferSize) throws IOException
bindPort
- TCP port on which to wait for client connectionsmsgQueueSize
- Maximum number of messages to enqueue per clientmsgBufferSize
- Maximum size in bytes of each outgoing messageIOException
- If there is an error binding on the given portpublic static TableServer start(int bindPort, int msgQueueSize, int msgBufferSize, int sendWaitTimeMillis, boolean allocateDirect, com.fishlib.io.logger.Logger logger) throws IOException
bindPort
- TCP port on which to wait for client connectionsmsgQueueSize
- Maximum number of messages to enqueue per clientmsgBufferSize
- Maximum size in bytes of each outgoing messagesendWaitTimeMillis
- Maximum time to wait for a free message buffer when queue is fullallocateDirect
- If true, use direct buffers for message buffers (off-heap)logger
- Logger used for reporting client connections, disconnections and errorsIOException
- If there is an error binding on the given portpublic void close() throws IOException, InterruptedException
close
in interface AutoCloseable
IOException
- If there is an error closing the server socket or a client connectionInterruptedException
- If interrupted while waiting for the server to diepublic void exportTable(String name, DynamicTable table)
name
- Unique name for the sametable
- The table to export (must be DynamicTable)public void unexportTable(String name)
name
- Name of the table to remove (used when exportTable was called)