Package com.google.cloud.spanner.watcher
Class SpannerDatabaseTailer
- java.lang.Object
-
- com.google.api.core.AbstractApiService
-
- com.google.cloud.spanner.watcher.SpannerDatabaseTailer
-
- All Implemented Interfaces:
com.google.api.core.ApiService,SpannerDatabaseChangeWatcher
public class SpannerDatabaseTailer extends com.google.api.core.AbstractApiService implements SpannerDatabaseChangeWatcher
Implementation of theSpannerDatabaseChangeWatcherinterface that continuously polls a set of tables for changes based on commit timestamp columns in the tables.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 = SpannerDatabaseTailer.newBuilder(spanner, databaseId).allTables().build(); watcher.addCallback( new RowChangeCallback() {
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSpannerDatabaseTailer.BuilderBuilder for aSpannerDatabaseTailer.static interfaceSpannerDatabaseTailer.TableExcluderInterface for excluding specific tables from aSpannerDatabaseTailer.static interfaceSpannerDatabaseTailer.TableSelecterInterface for selecting the tables that should be monitored by aSpannerDatabaseTailer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCallback(SpannerTableChangeWatcher.RowChangeCallback callback)Adds aSpannerTableChangeWatcher.RowChangeCallbackfor thisSpannerDatabaseChangeWatcher.protected voiddoStart()protected voiddoStop()com.google.cloud.spanner.DatabaseIdgetDatabaseId()Returns the id of the database that is being monitored for changes.com.google.common.collect.ImmutableList<TableId>getTables()Returns the ids of the tables that are monitored by this watcher.static SpannerDatabaseTailer.TableSelecternewBuilder(com.google.cloud.spanner.Spanner spanner, com.google.cloud.spanner.DatabaseId databaseId)Creates a builder for aSpannerDatabaseTailer.-
Methods inherited from class com.google.api.core.AbstractApiService
addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, failureCause, isRunning, notifyFailed, notifyStarted, notifyStopped, startAsync, state, stopAsync
-
-
-
-
Method Detail
-
newBuilder
public static SpannerDatabaseTailer.TableSelecter newBuilder(com.google.cloud.spanner.Spanner spanner, com.google.cloud.spanner.DatabaseId databaseId)
Creates a builder for aSpannerDatabaseTailer.
-
addCallback
public void addCallback(SpannerTableChangeWatcher.RowChangeCallback callback)
Description copied from interface:SpannerDatabaseChangeWatcherAdds aSpannerTableChangeWatcher.RowChangeCallbackfor thisSpannerDatabaseChangeWatcher. Callbacks may only be added when theApiService.state()of thisSpannerDatabaseChangeWatcherisApiService.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.- Specified by:
addCallbackin interfaceSpannerDatabaseChangeWatcher
-
doStart
protected void doStart()
- Specified by:
doStartin classcom.google.api.core.AbstractApiService
-
doStop
protected void doStop()
- Specified by:
doStopin classcom.google.api.core.AbstractApiService
-
getDatabaseId
public com.google.cloud.spanner.DatabaseId getDatabaseId()
Description copied from interface:SpannerDatabaseChangeWatcherReturns the id of the database that is being monitored for changes.- Specified by:
getDatabaseIdin interfaceSpannerDatabaseChangeWatcher
-
getTables
public com.google.common.collect.ImmutableList<TableId> getTables()
Description copied from interface:SpannerDatabaseChangeWatcherReturns the ids of the tables that are monitored by this watcher. This call can require theSpannerDatabaseChangeWatcherto make a round-trip to the database to determine the actual tables that are being monitored.- Specified by:
getTablesin interfaceSpannerDatabaseChangeWatcher
-
-