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 ;
23+ import com .google .cloud .bigtable .data .v2 .stub .EnhancedBigtableStubSettings ;
2124import java .io .IOException ;
2225import javax .annotation .Nonnull ;
2326
6164 */
6265@ BetaApi ("This feature is currently experimental and can change in the future" )
6366public final class BigtableDataClientFactory implements AutoCloseable {
64-
65- private final BigtableDataSettings defaultSettings ;
6667 private final BigtableClientContext sharedClientContext ;
68+ private final ClientOperationSettings perOpSettings ;
6769
6870 /**
6971 * Create a instance of this factory.
@@ -75,13 +77,14 @@ public static BigtableDataClientFactory create(BigtableDataSettings defaultSetti
7577 throws IOException {
7678 BigtableClientContext sharedClientContext =
7779 BigtableClientContext .create (defaultSettings .getStubSettings ());
78- return new BigtableDataClientFactory (sharedClientContext , defaultSettings );
80+ ClientOperationSettings perOpSettings = defaultSettings .getStubSettings ().getPerOpSettings ();
81+ return new BigtableDataClientFactory (sharedClientContext , perOpSettings );
7982 }
8083
8184 private BigtableDataClientFactory (
82- BigtableClientContext sharedClientContext , BigtableDataSettings defaultSettings ) {
85+ BigtableClientContext sharedClientContext , ClientOperationSettings perOpSettings ) {
8386 this .sharedClientContext = sharedClientContext ;
84- this .defaultSettings = defaultSettings ;
87+ this .perOpSettings = perOpSettings ;
8588 }
8689
8790 /**
@@ -109,7 +112,7 @@ public BigtableDataClient createDefault() {
109112 sharedClientContext .createChild (
110113 sharedClientContext .getInstanceName (), sharedClientContext .getAppProfileId ());
111114
112- return BigtableDataClient . createWithClientContext ( defaultSettings , ctx );
115+ return new BigtableDataClient ( new EnhancedBigtableStub ( perOpSettings , ctx ) );
113116 } catch (IOException e ) {
114117 // Should never happen because the connection has been established already
115118 throw new RuntimeException (
@@ -127,14 +130,10 @@ public BigtableDataClient createDefault() {
127130 * release all resources, first close all of the created clients and then this factory instance.
128131 */
129132 public BigtableDataClient createForAppProfile (@ Nonnull String appProfileId ) throws IOException {
130- BigtableDataSettings settings =
131- defaultSettings .toBuilder ().setAppProfileId (appProfileId ).build ();
132133 BigtableClientContext ctx =
133- sharedClientContext .createChild (
134- InstanceName .of (settings .getProjectId (), settings .getInstanceId ()),
135- settings .getAppProfileId ());
134+ sharedClientContext .createChild (sharedClientContext .getInstanceName (), appProfileId );
136135
137- return BigtableDataClient . createWithClientContext ( settings , ctx );
136+ return new BigtableDataClient ( new EnhancedBigtableStub ( perOpSettings , ctx ) );
138137 }
139138
140139 /**
@@ -148,18 +147,11 @@ public BigtableDataClient createForAppProfile(@Nonnull String appProfileId) thro
148147 */
149148 public BigtableDataClient createForInstance (@ Nonnull String projectId , @ Nonnull String instanceId )
150149 throws IOException {
151- BigtableDataSettings settings =
152- defaultSettings .toBuilder ()
153- .setProjectId (projectId )
154- .setInstanceId (instanceId )
155- .setDefaultAppProfileId ()
156- .build ();
157150 BigtableClientContext ctx =
158151 sharedClientContext .createChild (
159- InstanceName .of (settings .getProjectId (), settings .getInstanceId ()),
160- settings .getAppProfileId ());
152+ InstanceName .of (projectId , instanceId ), "" );
161153
162- return BigtableDataClient . createWithClientContext ( settings , ctx );
154+ return new BigtableDataClient ( new EnhancedBigtableStub ( perOpSettings , ctx ) );
163155 }
164156
165157 /**
@@ -174,17 +166,9 @@ public BigtableDataClient createForInstance(@Nonnull String projectId, @Nonnull
174166 public BigtableDataClient createForInstance (
175167 @ Nonnull String projectId , @ Nonnull String instanceId , @ Nonnull String appProfileId )
176168 throws IOException {
177- BigtableDataSettings settings =
178- defaultSettings .toBuilder ()
179- .setProjectId (projectId )
180- .setInstanceId (instanceId )
181- .setAppProfileId (appProfileId )
182- .build ();
183169 BigtableClientContext ctx =
184- sharedClientContext .createChild (
185- InstanceName .of (settings .getProjectId (), settings .getInstanceId ()),
186- settings .getAppProfileId ());
170+ sharedClientContext .createChild (InstanceName .of (projectId , instanceId ), appProfileId );
187171
188- return BigtableDataClient . createWithClientContext ( settings , ctx );
172+ return new BigtableDataClient ( new EnhancedBigtableStub ( perOpSettings , ctx ) );
189173 }
190174}
0 commit comments