1818import com .google .api .core .BetaApi ;
1919import com .google .bigtable .v2 .InstanceName ;
2020import com .google .cloud .bigtable .data .v2 .stub .BigtableClientContext ;
21+ import com .google .cloud .bigtable .data .v2 .stub .ClientOperationSettings ;
22+ import com .google .cloud .bigtable .data .v2 .stub .EnhancedBigtableStub ;
2123import java .io .IOException ;
2224import javax .annotation .Nonnull ;
2325
6163 */
6264@ BetaApi ("This feature is currently experimental and can change in the future" )
6365public final class BigtableDataClientFactory implements AutoCloseable {
64-
65- private final BigtableDataSettings defaultSettings ;
6666 private final BigtableClientContext sharedClientContext ;
67+ private final ClientOperationSettings perOpSettings ;
6768
6869 /**
6970 * Create a instance of this factory.
@@ -75,13 +76,14 @@ public static BigtableDataClientFactory create(BigtableDataSettings defaultSetti
7576 throws IOException {
7677 BigtableClientContext sharedClientContext =
7778 BigtableClientContext .create (defaultSettings .getStubSettings ());
78- return new BigtableDataClientFactory (sharedClientContext , defaultSettings );
79+ ClientOperationSettings perOpSettings = defaultSettings .getStubSettings ().getPerOpSettings ();
80+ return new BigtableDataClientFactory (sharedClientContext , perOpSettings );
7981 }
8082
8183 private BigtableDataClientFactory (
82- BigtableClientContext sharedClientContext , BigtableDataSettings defaultSettings ) {
84+ BigtableClientContext sharedClientContext , ClientOperationSettings perOpSettings ) {
8385 this .sharedClientContext = sharedClientContext ;
84- this .defaultSettings = defaultSettings ;
86+ this .perOpSettings = perOpSettings ;
8587 }
8688
8789 /**
@@ -109,7 +111,7 @@ public BigtableDataClient createDefault() {
109111 sharedClientContext .createChild (
110112 sharedClientContext .getInstanceName (), sharedClientContext .getAppProfileId ());
111113
112- return BigtableDataClient . createWithClientContext ( defaultSettings , ctx );
114+ return new BigtableDataClient ( new EnhancedBigtableStub ( perOpSettings , ctx ) );
113115 } catch (IOException e ) {
114116 // Should never happen because the connection has been established already
115117 throw new RuntimeException (
@@ -127,14 +129,10 @@ public BigtableDataClient createDefault() {
127129 * release all resources, first close all of the created clients and then this factory instance.
128130 */
129131 public BigtableDataClient createForAppProfile (@ Nonnull String appProfileId ) throws IOException {
130- BigtableDataSettings settings =
131- defaultSettings .toBuilder ().setAppProfileId (appProfileId ).build ();
132132 BigtableClientContext ctx =
133- sharedClientContext .createChild (
134- InstanceName .of (settings .getProjectId (), settings .getInstanceId ()),
135- settings .getAppProfileId ());
133+ sharedClientContext .createChild (sharedClientContext .getInstanceName (), appProfileId );
136134
137- return BigtableDataClient . createWithClientContext ( settings , ctx );
135+ return new BigtableDataClient ( new EnhancedBigtableStub ( perOpSettings , ctx ) );
138136 }
139137
140138 /**
@@ -148,18 +146,10 @@ public BigtableDataClient createForAppProfile(@Nonnull String appProfileId) thro
148146 */
149147 public BigtableDataClient createForInstance (@ Nonnull String projectId , @ Nonnull String instanceId )
150148 throws IOException {
151- BigtableDataSettings settings =
152- defaultSettings .toBuilder ()
153- .setProjectId (projectId )
154- .setInstanceId (instanceId )
155- .setDefaultAppProfileId ()
156- .build ();
157149 BigtableClientContext ctx =
158- sharedClientContext .createChild (
159- InstanceName .of (settings .getProjectId (), settings .getInstanceId ()),
160- settings .getAppProfileId ());
150+ sharedClientContext .createChild (InstanceName .of (projectId , instanceId ), "" );
161151
162- return BigtableDataClient . createWithClientContext ( settings , ctx );
152+ return new BigtableDataClient ( new EnhancedBigtableStub ( perOpSettings , ctx ) );
163153 }
164154
165155 /**
@@ -174,17 +164,9 @@ public BigtableDataClient createForInstance(@Nonnull String projectId, @Nonnull
174164 public BigtableDataClient createForInstance (
175165 @ Nonnull String projectId , @ Nonnull String instanceId , @ Nonnull String appProfileId )
176166 throws IOException {
177- BigtableDataSettings settings =
178- defaultSettings .toBuilder ()
179- .setProjectId (projectId )
180- .setInstanceId (instanceId )
181- .setAppProfileId (appProfileId )
182- .build ();
183167 BigtableClientContext ctx =
184- sharedClientContext .createChild (
185- InstanceName .of (settings .getProjectId (), settings .getInstanceId ()),
186- settings .getAppProfileId ());
168+ sharedClientContext .createChild (InstanceName .of (projectId , instanceId ), appProfileId );
187169
188- return BigtableDataClient . createWithClientContext ( settings , ctx );
170+ return new BigtableDataClient ( new EnhancedBigtableStub ( perOpSettings , ctx ) );
189171 }
190172}
0 commit comments