diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java index b5e3977998fd..cfd358c994bb 100644 --- a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClient.java @@ -34,7 +34,7 @@ import com.google.cloud.bigtable.admin.v2.models.CreateTableRequest; import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest; import com.google.cloud.bigtable.admin.v2.models.Table; -import com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStub; +import com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; @@ -97,7 +97,7 @@ * } */ public final class BigtableTableAdminClient implements AutoCloseable { - private final BigtableTableAdminStub stub; + private final EnhancedBigtableTableAdminStub stub; private final InstanceName instanceName; /** Constructs an instance of BigtableTableAdminClient with the given instanceName. */ @@ -109,17 +109,19 @@ public static BigtableTableAdminClient create(@Nonnull InstanceName instanceName /** Constructs an instance of BigtableTableAdminClient with the given settings. */ public static BigtableTableAdminClient create(@Nonnull BigtableTableAdminSettings settings) throws IOException { - return create(settings.getInstanceName(), settings.getStubSettings().createStub()); + EnhancedBigtableTableAdminStub stub = EnhancedBigtableTableAdminStub + .createEnhanced(settings.getStubSettings()); + return create(settings.getInstanceName(), stub); } /** Constructs an instance of BigtableTableAdminClient with the given instanceName and stub. */ public static BigtableTableAdminClient create(@Nonnull InstanceName instanceName, - @Nonnull BigtableTableAdminStub stub) { + @Nonnull EnhancedBigtableTableAdminStub stub) { return new BigtableTableAdminClient(instanceName, stub); } private BigtableTableAdminClient(@Nonnull InstanceName instanceName, - @Nonnull BigtableTableAdminStub stub) { + @Nonnull EnhancedBigtableTableAdminStub stub) { Preconditions.checkNotNull(instanceName); Preconditions.checkNotNull(stub); this.instanceName = instanceName; diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java new file mode 100644 index 000000000000..f4586acf0553 --- /dev/null +++ b/google-cloud-clients/google-cloud-bigtable-admin/src/main/java/com/google/cloud/bigtable/admin/v2/stub/EnhancedBigtableTableAdminStub.java @@ -0,0 +1,47 @@ +/* + * Copyright 2018 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.cloud.bigtable.admin.v2.stub; + +import com.google.api.core.InternalApi; +import com.google.api.gax.rpc.ClientContext; +import java.io.IOException; + +/** + * Extension of the autogenerated {@link GrpcBigtableTableAdminStub}. It acts as a decorator to add + * enhanced abilities to the autogenerated stub. + * + *
This class is considered an internal implementation detail and not meant to be used by
+ * applications.
+ */
+@InternalApi
+public class EnhancedBigtableTableAdminStub extends GrpcBigtableTableAdminStub {
+ private final BigtableTableAdminStubSettings settings;
+ private final ClientContext clientContext;
+
+ public static EnhancedBigtableTableAdminStub createEnhanced(
+ BigtableTableAdminStubSettings settings)
+ throws IOException {
+ return new EnhancedBigtableTableAdminStub(settings, ClientContext.create(settings));
+ }
+
+ private EnhancedBigtableTableAdminStub(BigtableTableAdminStubSettings settings,
+ ClientContext clientContext) throws IOException {
+ super(settings, clientContext);
+
+ this.settings = settings;
+ this.clientContext = clientContext;
+ }
+}
diff --git a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java
index 1494638091db..86d52f1cceb3 100644
--- a/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java
+++ b/google-cloud-clients/google-cloud-bigtable-admin/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableTableAdminClientTest.java
@@ -40,6 +40,7 @@
import com.google.cloud.bigtable.admin.v2.models.ModifyColumnFamiliesRequest;
import com.google.cloud.bigtable.admin.v2.models.Table;
import com.google.cloud.bigtable.admin.v2.stub.BigtableTableAdminStub;
+import com.google.cloud.bigtable.admin.v2.stub.EnhancedBigtableTableAdminStub;
import com.google.common.collect.Lists;
import com.google.protobuf.ByteString;
import com.google.protobuf.Empty;
@@ -63,7 +64,7 @@ public class BigtableTableAdminClientTest {
private BigtableTableAdminClient adminClient;
@Mock
- private BigtableTableAdminStub mockStub;
+ private EnhancedBigtableTableAdminStub mockStub;
@Mock
private UnaryCallable