Class TableServer
- All Implemented Interfaces:
AutoCloseable
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
FieldsModifier and TypeFieldDescriptionstatic 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 TypeMethodDescriptionvoid
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.
-
Field Details
-
DEFAULT_MSG_QUEUE_SIZE
public static final int DEFAULT_MSG_QUEUE_SIZEMaximum number of messages to enqueue per client.- See Also:
-
DEFAULT_MSG_BUFFER_SIZE
public static final int DEFAULT_MSG_BUFFER_SIZEMaximum 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_MILLISMaximum time to wait for a free buffer when client queue is full.- See Also:
-
DEFAULT_ALLOCATE_DIRECT
public static final boolean DEFAULT_ALLOCATE_DIRECTWhether to allocate message buffers directly (off-heap).- See Also:
-
-
Method Details
-
start
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: falseThe 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 connectionslogger
- 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 connectionsmsgQueueSize
- Maximum number of messages to enqueue per clientmsgBufferSize
- 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 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 errors- Returns:
- A new running table server
- Throws:
IOException
- If there is an error binding on the given port
-
close
Close the table server, including any open client connections.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
- If there is an error closing the server socket or a client connectionInterruptedException
- If interrupted while waiting for the server to die
-
exportTable
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 sametable
- The table to export (must be DynamicTable)
-
unexportTable
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)
-