Package com.google.cloud.spanner.watcher
Class SpannerTableTailer
- java.lang.Object
-
- com.google.api.core.AbstractApiService
-
- com.google.cloud.spanner.watcher.SpannerTableTailer
-
- All Implemented Interfaces:
com.google.api.core.ApiService,SpannerTableChangeWatcher
public class SpannerTableTailer extends com.google.api.core.AbstractApiService implements SpannerTableChangeWatcher
Implementation of theSpannerTableChangeWatcherinterface that continuously polls a table for changes based on a commit timestamp column in the table.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); SpannerTableChangeWatcher watcher = SpannerTableTailer.newBuilder(spanner, tableId).build(); watcher.addCallback( new RowChangeCallback() {
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSpannerTableTailer.BuilderBuilder for aSpannerTableTailer.-
Nested classes/interfaces inherited from interface com.google.api.core.ApiService
com.google.api.core.ApiService.Listener, com.google.api.core.ApiService.State
-
Nested classes/interfaces inherited from interface com.google.cloud.spanner.watcher.SpannerTableChangeWatcher
SpannerTableChangeWatcher.Row, SpannerTableChangeWatcher.RowChangeCallback
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCallback(SpannerTableChangeWatcher.RowChangeCallback callback)Adds aSpannerTableChangeWatcher.RowChangeCallbackfor thisSpannerTableChangeWatcher.protected voiddoStart()protected voiddoStop()TableIdgetTable()Returns the id of the table that is monitored by this watcher.static SpannerTableTailer.BuildernewBuilder(com.google.cloud.spanner.Spanner spanner, TableId table)protected voidnotifyFailed(Throwable cause)-
Methods inherited from class com.google.api.core.AbstractApiService
addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, failureCause, isRunning, notifyStarted, notifyStopped, startAsync, state, stopAsync
-
-
-
-
Method Detail
-
newBuilder
public static SpannerTableTailer.Builder newBuilder(com.google.cloud.spanner.Spanner spanner, TableId table)
-
addCallback
public void addCallback(SpannerTableChangeWatcher.RowChangeCallback callback)
Description copied from interface:SpannerTableChangeWatcherAdds aSpannerTableChangeWatcher.RowChangeCallbackfor thisSpannerTableChangeWatcher. Callbacks may only be added when theApiService.state()of thisSpannerTableChangeWatcherisApiService.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
SpannerTableChangeWatcherguarantees that at most oneSpannerTableChangeWatcher.RowChangeCallbackwill 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 aSpannerTableChangeWatcherhas registered multiple callbacks.- Specified by:
addCallbackin interfaceSpannerTableChangeWatcher
-
getTable
public TableId getTable()
Description copied from interface:SpannerTableChangeWatcherReturns the id of the table that is monitored by this watcher.- Specified by:
getTablein interfaceSpannerTableChangeWatcher
-
doStart
protected void doStart()
- Specified by:
doStartin classcom.google.api.core.AbstractApiService
-
notifyFailed
protected void notifyFailed(Throwable cause)
- Overrides:
notifyFailedin classcom.google.api.core.AbstractApiService
-
doStop
protected void doStop()
- Specified by:
doStopin classcom.google.api.core.AbstractApiService
-
-