public class SpannerTableTailer extends com.google.api.core.AbstractApiService implements SpannerTableChangeWatcher
SpannerTableChangeWatcher interface 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() {| Modifier and Type | Class and Description |
|---|---|
static class |
SpannerTableTailer.Builder
Builder for a
SpannerTableTailer. |
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() |
com.google.cloud.spanner.Statement |
getLastPollStatement()
Returns the last poll statement of this tailer.
|
TableId |
getTable()
Returns the id of the table that is monitored by this watcher.
|
boolean |
isLastPollReturnedChanges()
Returns true if the last poll for changes actually returned changes.
|
static SpannerTableTailer.Builder |
newBuilder(com.google.cloud.spanner.Spanner spanner,
TableId table) |
protected void |
notifyFailed(Throwable cause) |
addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, failureCause, isRunning, notifyStarted, notifyStopped, startAsync, state, stopAsyncpublic static SpannerTableTailer.Builder newBuilder(com.google.cloud.spanner.Spanner spanner, TableId table)
public 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 SpannerTableChangeWatcherpublic TableId getTable()
SpannerTableChangeWatchergetTable in interface SpannerTableChangeWatcherpublic com.google.cloud.spanner.Statement getLastPollStatement()
public boolean isLastPollReturnedChanges()
protected void doStart()
doStart in class com.google.api.core.AbstractApiServiceprotected void notifyFailed(Throwable cause)
notifyFailed in class com.google.api.core.AbstractApiServiceprotected void doStop()
doStop in class com.google.api.core.AbstractApiServiceCopyright © 2022 Google LLC. All rights reserved.