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.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
TableClient.Receiver
-
Field Summary
Fields Modifier and Type Field Description protected boolean
allocateDirect
protected boolean
isAlive
protected MessageHeaderEncoder
messageHeaderEncoder
protected TableClient.Receiver
receiver
protected Thread
receiverThread
protected static int
SEND_MSG_BUFFER_SIZE
protected ByteBuffer
sendByteBuffer
protected org.agrona.concurrent.UnsafeBuffer
sendDirectBuffer
protected SocketChannel
socketChannel
protected TableSubscribeEncoder
subscribeEncoder
protected TableUnsubscribeEncoder
unsubscribeEncoder
-
Constructor Summary
Constructors Constructor Description TableClient(String host, int port, MessageHandler messageHandler)
Start a new table client, connecting to the given host and port.TableClient(String host, int port, MessageHandler messageHandler, boolean allocateDirect)
Start a new table client, connecting to the given host and port. -
Method Summary
Modifier and Type Method Description void
close()
Close the table client.boolean
isAlive()
Return if the client is still alive and processing incoming messages.void
subscribe(int subscriptionId, SubscribeMode subscribeMode, String name)
Subscribe to an exported table.void
subscribe(int subscriptionId, SubscribeMode subscribeMode, String name, List<String> columnNames)
Subscribe to an exported table.void
subscribe(int subscriptionId, SubscribeMode subscribeMode, String name, List<String> columnNames, String filter)
Subscribe to updates on the given columns for the table identified by the given name.void
unsubscribe(int subscriptionId)
Unsubscribe from updates for the given subscription id.
-
Field Details
-
socketChannel
-
SEND_MSG_BUFFER_SIZE
protected static final int SEND_MSG_BUFFER_SIZE- See Also:
- Constant Field Values
-
allocateDirect
protected final boolean allocateDirect -
sendByteBuffer
-
sendDirectBuffer
protected final org.agrona.concurrent.UnsafeBuffer sendDirectBuffer -
messageHeaderEncoder
-
subscribeEncoder
-
unsubscribeEncoder
-
isAlive
protected volatile boolean isAlive -
receiverThread
-
receiver
-
-
Constructor Details
-
TableClient
public TableClient(String host, int port, MessageHandler messageHandler, boolean allocateDirect) throws IOExceptionStart 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 runningport
- Port on which the TableServer is boundmessageHandler
- Object which handles incoming messages from the serverallocateDirect
- If true, use direct (off-heap) buffers to allocate message buffers- Throws:
IOException
- If there is an error while connecting to the server
-
TableClient
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 (seeTableClient(String, int, MessageHandler, boolean)
- Parameters:
host
- Host on which the TableServer is runningport
- Port on which the TableServer is boundmessageHandler
- 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 theclose()
method.- Returns:
- true if the client is still connected, false otherwise
-
close
Close the table client. This closes the socket connection and waits for the receive thread to die.- Specified by:
close
in interfaceAutoCloseable
- Throws:
InterruptedException
- If interrupted while waiting for receive thread to dieIOException
- If an error occurs while closing the socket
-
subscribe
public void subscribe(int subscriptionId, SubscribeMode subscribeMode, String name, List<String> columnNames) throws IOExceptionSubscribe 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 subscriptionsubscribeMode
- Specifies whether the client is requesting an initial snapshot, update stream, or bothname
- 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 IOExceptionSubscribe 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 subscriptionsubscribeMode
- Specifies whether the client is requesting an initial snapshot, update stream, or bothname
- 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 IOExceptionSubscribe 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 subscriptionsubscribeMode
- Specifies whether the client is requesting an initial snapshot, update stream, or bothname
- 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
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
-