public class SpannerDatabaseChangeSetPoller extends com.google.api.core.AbstractApiService implements SpannerDatabaseChangeWatcher
SpannerDatabaseChangeWatcher interface that continuously polls a
change set table for new rows, and then polls the actual data tables 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:
Example usage for watching all tables in a database:
{@code
String instance = "my-instance";
String database = "my-database";
Spanner spanner = SpannerOptions.getDefaultInstance().getService();
DatabaseId databaseId = DatabaseId.of(SpannerOptions.getDefaultProjectId(), instance, database);
SpannerDatabaseChangeWatcher watcher =
SpannerDatabaseChangeSetPoller.newBuilder(spanner, databaseId).allTables().build();
watcher.addCallback(
new RowChangeCallback() {| Modifier and Type | Class and Description |
|---|---|
static interface |
SpannerDatabaseChangeSetPoller.Builder
Builder for a
SpannerDatabaseChangeSetPoller. |
| Modifier and Type | Method and Description |
|---|---|
void |
addCallback(SpannerTableChangeWatcher.RowChangeCallback callback)
Adds a
SpannerTableChangeWatcher.RowChangeCallback for this SpannerDatabaseChangeWatcher. |
protected void |
doStart() |
protected void |
doStop() |
com.google.cloud.spanner.DatabaseId |
getDatabaseId()
Returns the id of the database that is being monitored for changes.
|
List<TableId> |
getTables()
Returns the ids of the tables that are monitored by this watcher.
|
static SpannerDatabaseChangeSetPoller.Builder.TableSelecter |
newBuilder(com.google.cloud.spanner.Spanner spanner,
com.google.cloud.spanner.DatabaseId databaseId)
Creates a builder for a
SpannerDatabaseChangeSetPoller. |
static SpannerDatabaseChangeSetPoller.Builder.TableSelecter |
newBuilder(com.google.cloud.spanner.Spanner spanner,
com.google.cloud.spanner.DatabaseId databaseId,
TableId changeSetTable)
Creates a builder for a
SpannerDatabaseChangeSetPoller. |
addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, failureCause, isRunning, notifyFailed, notifyStarted, notifyStopped, startAsync, state, stopAsyncpublic static SpannerDatabaseChangeSetPoller.Builder.TableSelecter newBuilder(com.google.cloud.spanner.Spanner spanner, com.google.cloud.spanner.DatabaseId databaseId)
SpannerDatabaseChangeSetPoller.public static SpannerDatabaseChangeSetPoller.Builder.TableSelecter newBuilder(com.google.cloud.spanner.Spanner spanner, com.google.cloud.spanner.DatabaseId databaseId, TableId changeSetTable)
SpannerDatabaseChangeSetPoller.public void addCallback(SpannerTableChangeWatcher.RowChangeCallback callback)
SpannerDatabaseChangeWatcherSpannerTableChangeWatcher.RowChangeCallback for this SpannerDatabaseChangeWatcher. Callbacks may
only be added when the ApiService.state() of this SpannerDatabaseChangeWatcher is ApiService.State.NEW. Callbacks for one table will always be in order of commit timestamp, and only one
callback will be active at any time for a table. Callbacks for different tables may be called
in parallel, and there is no guarantee to the ordering of callbacks over multiple tables.addCallback in interface SpannerDatabaseChangeWatcherprotected void doStart()
doStart in class com.google.api.core.AbstractApiServiceprotected void doStop()
doStop in class com.google.api.core.AbstractApiServicepublic com.google.cloud.spanner.DatabaseId getDatabaseId()
SpannerDatabaseChangeWatchergetDatabaseId in interface SpannerDatabaseChangeWatcherpublic List<TableId> getTables()
SpannerDatabaseChangeWatcherSpannerDatabaseChangeWatcher to make a round-trip to the database to determine the
actual tables that are being monitored.getTables in interface SpannerDatabaseChangeWatcherCopyright © 2022 Google LLC. All rights reserved.