Class NoSQLSubscriptionConfig.Builder
- Enclosing class:
- NoSQLSubscriptionConfig
-
Constructor Summary
ConstructorsConstructorDescriptionMakes a builder for NoSQLSubscriptionConfig with required parameter for single subscriber, that is, theNoSQLSubscriberId.getTotal()
is 1.Builder
(Function<NoSQLSubscriberId, String> ckptTableMapper) Makes a builder for NoSQLSubscriptionConfig with required parameter for multiple sharded subscribers, that is, theNoSQLSubscriberId.getTotal()
is greater than 1. -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds a NoSQLSubscriptionConfig instance from buildersetChangeTimeoutMs
(long changeTimeoutMs) Sets the subscription change timeout in milliseconds.setCreateNewCheckpointTable
(boolean allow) Sets if publisher is allowed to create a new checkpoint table if it does not exist.setEmptyStreamDuration
(int emptyStreamSecs) Sets the empty stream duration.setLocalWritesOnly
(boolean localWritesOnly) Sets that when subscribing multi-region tables, whether only local writes are streamed.setMaxReconnect
(long maxReconnect) Sets the max number of reconnect if stream is downsetOutputQueueSizeMB
(int sz) Sets the output queue size in megabytes.setStartStreamPosition
(StreamPosition position) Sets the start stream position.setStreamMode
(NoSQLStreamMode mode) Sets the stream mode.setSubscribedTables
(String... tables) Sets the subscribed tables under given namespace.setSubscribedTables
(Set<String> tables) Sets the subscribed tables under given namespace.Sets the subscriber id which owns the subscription.
-
Constructor Details
-
Builder
Makes a builder for NoSQLSubscriptionConfig with required parameter for single subscriber, that is, theNoSQLSubscriberId.getTotal()
is 1.The checkpoint table can be specified in one of following formats:
- tablename, e.g., "MyCkptTable". The given table should be existent or will be created in system default table space.
- namespace:tablename, e.g., "MyNameSpace:MyTable". The given table should be existent or will be created in in the given name space.
- Parameters:
ckptTableName
- the full namespace name of checkpoint table. The checkpoint table cannot be a child table.- Throws:
IllegalArgumentException
- if the checkpoint table name is null or empty
-
Builder
Makes a builder for NoSQLSubscriptionConfig with required parameter for multiple sharded subscribers, that is, theNoSQLSubscriberId.getTotal()
is greater than 1.Sets a function that maps a subscriber ID to the name of the associated checkpoint table. The checkpoint table name format should be consistent with that in
Builder(String)
.- Parameters:
ckptTableMapper
- a mapper function to build the checkpoint table name from subscriber id- Throws:
IllegalArgumentException
- if the checkpoint table name mapper function is null
-
-
Method Details
-
build
Builds a NoSQLSubscriptionConfig instance from builder- Returns:
- a NoSQLSubscriptionConfig instance
-
setSubscribedTables
Sets the subscribed tables under given namespace. Each table should be specified in one of following formats:- tablename, e.g., "MyTable". The given table should be
existent in system default table space. See
TableAPI.SYSDEFAULT_NAMESPACE_NAME
. - namespace:tablename, e.g., "MyNameSpace:MyTable". The given table should be existent in the given table space.
- Parameters:
tables
- set of table names to subscribe- Returns:
- this instance
- tablename, e.g., "MyTable". The given table should be
existent in system default table space. See
-
setSubscribedTables
Sets the subscribed tables under given namespace. Each table should be specified in one of following formats:- tablename, e.g., "MyTable". The given table should be existent in initial table space.
- namespace:tablename, e.g., "MyNameSpace:MyTable". The given table should be existent in given table space.
- Parameters:
tables
- set of table names to subscribe- Returns:
- this instance
-
setSubscriberId
Sets the subscriber id which owns the subscription. If it is not set, the subscription is considered a singleton subscription with single subscriber streaming from all shards.- Parameters:
id
- subscriber id- Returns:
- this instance
-
setStartStreamPosition
Sets the start stream position. Depending on stream mode, the start stream position has different semantics as follows.If stream mode is set to
NoSQLStreamMode.FROM_CHECKPOINT
, which is the default if stream mode is not set, the stream will start from the checkpoint persisted in the specified checkpoint table, and any specified stream position will be ignored. If the checkpoint table does not exist, the stream will create a new checkpoint table for user if allowed. If the checkpoint table is empty, or if the position specified by the checkpoint table is not available, subscription will stream from the next available position.If stream mode is set to
NoSQLStreamMode.FROM_EXACT_CHECKPOINT
, the stream will start from the checkpoint persisted in the specified checkpoint table, and any specified stream position will be ignored. If the table does not exist, the stream will create a new checkpoint table for user if allowed. If the checkpoint table is empty, subscription will to stream from the first available entry. If a checkpoint has been saved but that stream position is not available, the subscription will fail and the publisher will signalSubscriptionInsufficientLogException
to the subscriber viaNoSQLSubscriber.onError(java.lang.Throwable)
.If stream mode is set to
NoSQLStreamMode.FROM_STREAM_POSITION
the stream will start from specified stream position if set. If the start stream position is not available, the subscription will stream from the next available position. If the start stream position is not set or is set to null,IllegalArgumentException
will be raised when the configuration is created.If stream mode is set to
NoSQLStreamMode.FROM_EXACT_STREAM_POSITION
, the stream will start from specified stream position if set. If the specified position is not available, the subscription will fail and the publisher will signalSubscriptionInsufficientLogException
to the subscriber viaNoSQLSubscriber.onError(java.lang.Throwable)
. If the start stream position is not set or set to null,IllegalArgumentException
will be raised when the configuration is created.If stream mode is set to
NoSQLStreamMode.FROM_NOW
, the stream will start from the latest available stream position and any specified start stream position will be ignored.- Parameters:
position
- stream position to start stream- Returns:
- this instance
-
setCreateNewCheckpointTable
Sets if publisher is allowed to create a new checkpoint table if it does not exist. If not set, the default is that publisher would create a new checkpoint table if it does not exist.- Parameters:
allow
- true if publisher is allowed to create a new checkpoint table for user if it does not exist; false otherwise, and subscription will fail if checkpoint table does not exist.- Returns:
- this instance
-
setStreamMode
public NoSQLSubscriptionConfig.Builder setStreamMode(NoSQLStreamMode mode) throws IllegalArgumentException Sets the stream mode. If not set, the stream mode defaults toNoSQLStreamMode.FROM_CHECKPOINT
.- Parameters:
mode
- the stream mode- Returns:
- this instance
- Throws:
IllegalArgumentException
- if specified stream mode is null.
-
setEmptyStreamDuration
public NoSQLSubscriptionConfig.Builder setEmptyStreamDuration(int emptyStreamSecs) throws IllegalArgumentException Sets the empty stream duration. A stream is considered empty if all subscribed tables have been removed from the subscription. An empty stream is considered to be no longer empty when at least one subscribed table is added successfully to the empty stream. If a stream is empty, the publisher would keep the empty stream alive for a period of time specified, and the publisher would shut down the empty stream when it times out.If not set, the empty stream stream duration defaults to 60 seconds.
- Parameters:
emptyStreamSecs
- empty stream lifetime in seconds- Returns:
- this instance
- Throws:
IllegalArgumentException
- if specified empty stream lifetime is non-positive.
-
setChangeTimeoutMs
public NoSQLSubscriptionConfig.Builder setChangeTimeoutMs(long changeTimeoutMs) throws IllegalArgumentException Sets the subscription change timeout in milliseconds. When the user changes the subscription by adding or removing table, the request would be sent to kvstore and it would timeout if the kvstore does not respond the request within the time period.If not set, change timeout defaults to 30000 milliseconds.
- Parameters:
changeTimeoutMs
- change timeout in milliseconds- Returns:
- this instance
- Throws:
IllegalArgumentException
- if specified change timeout is non-positive.
-
setLocalWritesOnly
Sets that when subscribing multi-region tables, whether only local writes are streamed.- Returns:
- this instance
-
setMaxReconnect
Sets the max number of reconnect if stream is down- Returns:
- this instance
-
setOutputQueueSizeMB
Sets the output queue size in megabytes.- Parameters:
sz
- size of output queue in megabytes- Throws:
IllegalArgumentException
- if size is smaller than the default queue sizeNoSQLSubscriptionConfig.DEFAULT_OUTPUT_QUEUE_SIZE_MB
-