public class SpannerTableChangeSetPoller extends com.google.api.core.AbstractApiService implements SpannerTableChangeWatcher
SpannerTableChangeWatcher interface that continuously polls a
change set table for new rows, and then polls an actual data table for any changes that was part
of the last seen change set. This requires all client applications to insert a new row to a
CHANGE_SETS table for each read/write transaction that is executed. While this does add an extra
write operation to each read/write transaction, it has two advantages:
Usage:
{@code
String instance = "my-instance";
String database = "my-database";
String table = "MY_TABLE";
Spanner spanner = SpannerOptions.getDefaultInstance().getService();
TableId tableId =
TableId.of(DatabaseId.of(SpannerOptions.getDefaultProjectId(), instance, database), table);
SpannerTableChangeSetPoller watcher = SpannerTableChangeSetPoller.newBuilder(spanner, tableId).build();
watcher.addCallback(
new RowChangeCallback() {| Modifier and Type | Class and Description |
|---|---|
static class |
SpannerTableChangeSetPoller.Builder
Builder for a
SpannerTableChangeSetPoller. |
SpannerTableChangeWatcher.Row, SpannerTableChangeWatcher.RowChangeCallback| Modifier and Type | Method and Description |
|---|---|
void |
addCallback(SpannerTableChangeWatcher.RowChangeCallback callback)
Adds a
SpannerTableChangeWatcher.RowChangeCallback for this SpannerTableChangeWatcher. |
protected void |
doStart() |
protected void |
doStop() |
TableId |
getTable()
Returns the id of the table that is monitored by this watcher.
|
static SpannerTableChangeSetPoller.Builder |
newBuilder(com.google.cloud.spanner.Spanner spanner,
TableId table)
Creates a new
SpannerTableChangeSetPoller.Builder for the given table. |
static SpannerTableChangeSetPoller.Builder |
newBuilder(com.google.cloud.spanner.Spanner spanner,
TableId changeSetTable,
TableId table)
Creates a new
SpannerTableChangeSetPoller.Builder for the given table and using the
specified change set table. |
addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, failureCause, isRunning, notifyFailed, notifyStarted, notifyStopped, startAsync, state, stopAsyncpublic static SpannerTableChangeSetPoller.Builder newBuilder(com.google.cloud.spanner.Spanner spanner, TableId table)
SpannerTableChangeSetPoller.Builder for the given table. The poller will
assume that all change sets are stored in a table called CHANGE_SETS.public static SpannerTableChangeSetPoller.Builder newBuilder(com.google.cloud.spanner.Spanner spanner, TableId changeSetTable, TableId table)
SpannerTableChangeSetPoller.Builder for the given table and using the
specified change set table.public TableId getTable()
SpannerTableChangeWatchergetTable in interface SpannerTableChangeWatcherpublic void addCallback(SpannerTableChangeWatcher.RowChangeCallback callback)
SpannerTableChangeWatcherSpannerTableChangeWatcher.RowChangeCallback for this SpannerTableChangeWatcher. Callbacks may only
be added when the ApiService.state() of this SpannerTableChangeWatcher is State#NEW. Callbacks should be lightweight and non-blocking. The callback should hand off any
heavy computations or blocking operations to a non-blocking executor or buffer.
The SpannerTableChangeWatcher guarantees that at most one SpannerTableChangeWatcher.RowChangeCallback
will be active at any given time, and all callbacks will receive all changes in order of commit
timestamp. There is no guarantee as to the order of which callback is called first if a SpannerTableChangeWatcher has registered multiple callbacks.
addCallback in interface SpannerTableChangeWatcherprotected void doStart()
doStart in class com.google.api.core.AbstractApiServiceprotected void doStop()
doStop in class com.google.api.core.AbstractApiServiceCopyright © 2022 Google LLC. All rights reserved.