@Generated(value="by GAPIC v0.0.5") @BetaApi public class BigtableClient extends Object implements com.google.api.gax.core.BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (BigtableClient bigtableClient = BigtableClient.create()) {
TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
ByteString rowKey = ByteString.copyFromUtf8("");
List<Mutation> mutations = new ArrayList<>();
MutateRowResponse response = bigtableClient.mutateRow(tableName, rowKey, mutations);
}
Note: close() needs to be called on the bigtableClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of BigtableSettings to create(). For example:
To customize credentials:
BigtableSettings bigtableSettings =
BigtableSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
BigtableClient bigtableClient =
BigtableClient.create(bigtableSettings);
To customize the endpoint:
BigtableSettings bigtableSettings =
BigtableSettings.newBuilder().setEndpoint(myEndpoint).build();
BigtableClient bigtableClient =
BigtableClient.create(bigtableSettings);
| Modifier | Constructor and Description |
|---|---|
protected |
BigtableClient(BigtableSettings settings)
Constructs an instance of BigtableClient, using the given settings.
|
protected |
BigtableClient(BigtableStub stub) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
com.google.bigtable.v2.CheckAndMutateRowResponse |
checkAndMutateRow(com.google.bigtable.v2.CheckAndMutateRowRequest request)
Mutates a row atomically based on the output of a predicate Reader filter.
|
com.google.bigtable.v2.CheckAndMutateRowResponse |
checkAndMutateRow(com.google.bigtable.v2.TableName tableName,
com.google.protobuf.ByteString rowKey,
com.google.bigtable.v2.RowFilter predicateFilter,
List<com.google.bigtable.v2.Mutation> trueMutations,
List<com.google.bigtable.v2.Mutation> falseMutations)
Mutates a row atomically based on the output of a predicate Reader filter.
|
com.google.api.gax.rpc.UnaryCallable<com.google.bigtable.v2.CheckAndMutateRowRequest,com.google.bigtable.v2.CheckAndMutateRowResponse> |
checkAndMutateRowCallable()
Mutates a row atomically based on the output of a predicate Reader filter.
|
void |
close() |
static BigtableClient |
create()
Constructs an instance of BigtableClient with default settings.
|
static BigtableClient |
create(BigtableSettings settings)
Constructs an instance of BigtableClient, using the given settings.
|
static BigtableClient |
create(BigtableStub stub)
Constructs an instance of BigtableClient, using the given stub for making calls.
|
BigtableSettings |
getSettings() |
BigtableStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
com.google.bigtable.v2.MutateRowResponse |
mutateRow(com.google.bigtable.v2.MutateRowRequest request)
Mutates a row atomically.
|
com.google.bigtable.v2.MutateRowResponse |
mutateRow(com.google.bigtable.v2.TableName tableName,
com.google.protobuf.ByteString rowKey,
List<com.google.bigtable.v2.Mutation> mutations)
Mutates a row atomically.
|
com.google.api.gax.rpc.UnaryCallable<com.google.bigtable.v2.MutateRowRequest,com.google.bigtable.v2.MutateRowResponse> |
mutateRowCallable()
Mutates a row atomically.
|
com.google.api.gax.rpc.ServerStreamingCallable<com.google.bigtable.v2.MutateRowsRequest,com.google.bigtable.v2.MutateRowsResponse> |
mutateRowsCallable()
Mutates multiple rows in a batch.
|
com.google.bigtable.v2.ReadModifyWriteRowResponse |
readModifyWriteRow(com.google.bigtable.v2.ReadModifyWriteRowRequest request)
Modifies a row atomically.
|
com.google.bigtable.v2.ReadModifyWriteRowResponse |
readModifyWriteRow(com.google.bigtable.v2.TableName tableName,
com.google.protobuf.ByteString rowKey,
List<com.google.bigtable.v2.ReadModifyWriteRule> rules)
Modifies a row atomically.
|
com.google.api.gax.rpc.UnaryCallable<com.google.bigtable.v2.ReadModifyWriteRowRequest,com.google.bigtable.v2.ReadModifyWriteRowResponse> |
readModifyWriteRowCallable()
Modifies a row atomically.
|
com.google.api.gax.rpc.ServerStreamingCallable<com.google.bigtable.v2.ReadRowsRequest,com.google.bigtable.v2.ReadRowsResponse> |
readRowsCallable()
Streams back the contents of all requested rows in key order, optionally applying the same
Reader filter to each.
|
com.google.api.gax.rpc.ServerStreamingCallable<com.google.bigtable.v2.SampleRowKeysRequest,com.google.bigtable.v2.SampleRowKeysResponse> |
sampleRowKeysCallable()
Returns a sample of row keys in the table.
|
void |
shutdown() |
void |
shutdownNow() |
protected BigtableClient(BigtableSettings settings) throws IOException
IOException@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected BigtableClient(BigtableStub stub)
public static final BigtableClient create() throws IOException
IOExceptionpublic static final BigtableClient create(BigtableSettings settings) throws IOException
IOException@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final BigtableClient create(BigtableStub stub)
public final BigtableSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public BigtableStub getStub()
public final com.google.api.gax.rpc.ServerStreamingCallable<com.google.bigtable.v2.ReadRowsRequest,com.google.bigtable.v2.ReadRowsResponse> readRowsCallable()
Sample code:
try (BigtableClient bigtableClient = BigtableClient.create()) {
ApiStreamObserver<ReadRowsResponse> responseObserver =
new ApiStreamObserver<ReadRowsResponse>() {
@Override
public void onNext(ReadRowsResponse response) {
// Do something when receive a response
}
@Override
public void onError(Throwable t) {
// Add error-handling
}
@Override
public void onCompleted() {
// Do something when complete.
}
};
TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
ReadRowsRequest request = ReadRowsRequest.newBuilder()
.setTableNameWithTableName(tableName)
.build();
bigtableClient.readRowsCallable().serverStreamingCall(request, responseObserver));
}
public final com.google.api.gax.rpc.ServerStreamingCallable<com.google.bigtable.v2.SampleRowKeysRequest,com.google.bigtable.v2.SampleRowKeysResponse> sampleRowKeysCallable()
Sample code:
try (BigtableClient bigtableClient = BigtableClient.create()) {
ApiStreamObserver<SampleRowKeysResponse> responseObserver =
new ApiStreamObserver<SampleRowKeysResponse>() {
@Override
public void onNext(SampleRowKeysResponse response) {
// Do something when receive a response
}
@Override
public void onError(Throwable t) {
// Add error-handling
}
@Override
public void onCompleted() {
// Do something when complete.
}
};
TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
SampleRowKeysRequest request = SampleRowKeysRequest.newBuilder()
.setTableNameWithTableName(tableName)
.build();
bigtableClient.sampleRowKeysCallable().serverStreamingCall(request, responseObserver));
}
public final com.google.bigtable.v2.MutateRowResponse mutateRow(com.google.bigtable.v2.TableName tableName,
com.google.protobuf.ByteString rowKey,
List<com.google.bigtable.v2.Mutation> mutations)
Sample code:
try (BigtableClient bigtableClient = BigtableClient.create()) {
TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
ByteString rowKey = ByteString.copyFromUtf8("");
List<Mutation> mutations = new ArrayList<>();
MutateRowResponse response = bigtableClient.mutateRow(tableName, rowKey, mutations);
}
tableName - The unique name of the table to which the mutation should be applied. Values
are of the form `projects/<project>/instances/<instance>/tables/<table>`.rowKey - The key of the row to which the mutation should be applied.mutations - Changes to be atomically applied to the specified row. Entries are applied in
order, meaning that earlier mutations can be masked by later ones. Must contain at least
one entry and at most 100000.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.bigtable.v2.MutateRowResponse mutateRow(com.google.bigtable.v2.MutateRowRequest request)
Sample code:
try (BigtableClient bigtableClient = BigtableClient.create()) {
TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
ByteString rowKey = ByteString.copyFromUtf8("");
List<Mutation> mutations = new ArrayList<>();
MutateRowRequest request = MutateRowRequest.newBuilder()
.setTableNameWithTableName(tableName)
.setRowKey(rowKey)
.addAllMutations(mutations)
.build();
MutateRowResponse response = bigtableClient.mutateRow(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<com.google.bigtable.v2.MutateRowRequest,com.google.bigtable.v2.MutateRowResponse> mutateRowCallable()
Sample code:
try (BigtableClient bigtableClient = BigtableClient.create()) {
TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
ByteString rowKey = ByteString.copyFromUtf8("");
List<Mutation> mutations = new ArrayList<>();
MutateRowRequest request = MutateRowRequest.newBuilder()
.setTableNameWithTableName(tableName)
.setRowKey(rowKey)
.addAllMutations(mutations)
.build();
ApiFuture<MutateRowResponse> future = bigtableClient.mutateRowCallable().futureCall(request);
// Do something
MutateRowResponse response = future.get();
}
public final com.google.api.gax.rpc.ServerStreamingCallable<com.google.bigtable.v2.MutateRowsRequest,com.google.bigtable.v2.MutateRowsResponse> mutateRowsCallable()
Sample code:
try (BigtableClient bigtableClient = BigtableClient.create()) {
ApiStreamObserver<MutateRowsResponse> responseObserver =
new ApiStreamObserver<MutateRowsResponse>() {
@Override
public void onNext(MutateRowsResponse response) {
// Do something when receive a response
}
@Override
public void onError(Throwable t) {
// Add error-handling
}
@Override
public void onCompleted() {
// Do something when complete.
}
};
TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
List<MutateRowsRequest.Entry> entries = new ArrayList<>();
MutateRowsRequest request = MutateRowsRequest.newBuilder()
.setTableNameWithTableName(tableName)
.addAllEntries(entries)
.build();
bigtableClient.mutateRowsCallable().serverStreamingCall(request, responseObserver));
}
public final com.google.bigtable.v2.CheckAndMutateRowResponse checkAndMutateRow(com.google.bigtable.v2.TableName tableName,
com.google.protobuf.ByteString rowKey,
com.google.bigtable.v2.RowFilter predicateFilter,
List<com.google.bigtable.v2.Mutation> trueMutations,
List<com.google.bigtable.v2.Mutation> falseMutations)
Sample code:
try (BigtableClient bigtableClient = BigtableClient.create()) {
TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
ByteString rowKey = ByteString.copyFromUtf8("");
RowFilter predicateFilter = RowFilter.newBuilder().build();
List<Mutation> trueMutations = new ArrayList<>();
List<Mutation> falseMutations = new ArrayList<>();
CheckAndMutateRowResponse response = bigtableClient.checkAndMutateRow(tableName, rowKey, predicateFilter, trueMutations, falseMutations);
}
tableName - The unique name of the table to which the conditional mutation should be
applied. Values are of the form
`projects/<project>/instances/<instance>/tables/<table>`.rowKey - The key of the row to which the conditional mutation should be applied.predicateFilter - The filter to be applied to the contents of the specified row. Depending
on whether or not any results are yielded, either `true_mutations` or `false_mutations`
will be executed. If unset, checks that the row contains any values at all.trueMutations - Changes to be atomically applied to the specified row if
`predicate_filter` yields at least one cell when applied to `row_key`. Entries are applied
in order, meaning that earlier mutations can be masked by later ones. Must contain at least
one entry if `false_mutations` is empty, and at most 100000.falseMutations - Changes to be atomically applied to the specified row if
`predicate_filter` does not yield any cells when applied to `row_key`. Entries are applied
in order, meaning that earlier mutations can be masked by later ones. Must contain at least
one entry if `true_mutations` is empty, and at most 100000.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.bigtable.v2.CheckAndMutateRowResponse checkAndMutateRow(com.google.bigtable.v2.CheckAndMutateRowRequest request)
Sample code:
try (BigtableClient bigtableClient = BigtableClient.create()) {
TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
ByteString rowKey = ByteString.copyFromUtf8("");
CheckAndMutateRowRequest request = CheckAndMutateRowRequest.newBuilder()
.setTableNameWithTableName(tableName)
.setRowKey(rowKey)
.build();
CheckAndMutateRowResponse response = bigtableClient.checkAndMutateRow(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<com.google.bigtable.v2.CheckAndMutateRowRequest,com.google.bigtable.v2.CheckAndMutateRowResponse> checkAndMutateRowCallable()
Sample code:
try (BigtableClient bigtableClient = BigtableClient.create()) {
TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
ByteString rowKey = ByteString.copyFromUtf8("");
CheckAndMutateRowRequest request = CheckAndMutateRowRequest.newBuilder()
.setTableNameWithTableName(tableName)
.setRowKey(rowKey)
.build();
ApiFuture<CheckAndMutateRowResponse> future = bigtableClient.checkAndMutateRowCallable().futureCall(request);
// Do something
CheckAndMutateRowResponse response = future.get();
}
public final com.google.bigtable.v2.ReadModifyWriteRowResponse readModifyWriteRow(com.google.bigtable.v2.TableName tableName,
com.google.protobuf.ByteString rowKey,
List<com.google.bigtable.v2.ReadModifyWriteRule> rules)
Sample code:
try (BigtableClient bigtableClient = BigtableClient.create()) {
TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
ByteString rowKey = ByteString.copyFromUtf8("");
List<ReadModifyWriteRule> rules = new ArrayList<>();
ReadModifyWriteRowResponse response = bigtableClient.readModifyWriteRow(tableName, rowKey, rules);
}
tableName - The unique name of the table to which the read/modify/write rules should be
applied. Values are of the form
`projects/<project>/instances/<instance>/tables/<table>`.rowKey - The key of the row to which the read/modify/write rules should be applied.rules - Rules specifying how the specified row's contents are to be transformed into
writes. Entries are applied in order, meaning that earlier rules will affect the results of
later ones.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.bigtable.v2.ReadModifyWriteRowResponse readModifyWriteRow(com.google.bigtable.v2.ReadModifyWriteRowRequest request)
Sample code:
try (BigtableClient bigtableClient = BigtableClient.create()) {
TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
ByteString rowKey = ByteString.copyFromUtf8("");
List<ReadModifyWriteRule> rules = new ArrayList<>();
ReadModifyWriteRowRequest request = ReadModifyWriteRowRequest.newBuilder()
.setTableNameWithTableName(tableName)
.setRowKey(rowKey)
.addAllRules(rules)
.build();
ReadModifyWriteRowResponse response = bigtableClient.readModifyWriteRow(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<com.google.bigtable.v2.ReadModifyWriteRowRequest,com.google.bigtable.v2.ReadModifyWriteRowResponse> readModifyWriteRowCallable()
Sample code:
try (BigtableClient bigtableClient = BigtableClient.create()) {
TableName tableName = TableName.of("[PROJECT]", "[INSTANCE]", "[TABLE]");
ByteString rowKey = ByteString.copyFromUtf8("");
List<ReadModifyWriteRule> rules = new ArrayList<>();
ReadModifyWriteRowRequest request = ReadModifyWriteRowRequest.newBuilder()
.setTableNameWithTableName(tableName)
.setRowKey(rowKey)
.addAllRules(rules)
.build();
ApiFuture<ReadModifyWriteRowResponse> future = bigtableClient.readModifyWriteRowCallable().futureCall(request);
// Do something
ReadModifyWriteRowResponse response = future.get();
}
public final void close()
throws Exception
close in interface AutoCloseableExceptionpublic void shutdown()
shutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isShutdown()
isShutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isTerminated()
isTerminated in interface com.google.api.gax.core.BackgroundResourcepublic void shutdownNow()
shutdownNow in interface com.google.api.gax.core.BackgroundResourcepublic boolean awaitTermination(long duration,
TimeUnit unit)
throws InterruptedException
awaitTermination in interface com.google.api.gax.core.BackgroundResourceInterruptedExceptionCopyright © 2017 Google. All rights reserved.