@@ -108,7 +108,8 @@ public static final BigtableTableAdminClientV2 create(BaseBigtableTableAdminSett
108108
109109 OperationCallable <Void , Empty , OptimizeRestoredTableMetadata >
110110 optimizeRestoredTableOperationBaseCallable =
111- createOptimizeRestoredTableOperationBaseCallable (stub , settings , backgroundExecutor );
111+ createOptimizeRestoredTableOperationBaseCallable (
112+ stub , settings .getStubSettings ().getClock (), backgroundExecutor );
112113
113114 return new BigtableTableAdminClientV2 (
114115 stub ,
@@ -118,6 +119,34 @@ public static final BigtableTableAdminClientV2 create(BaseBigtableTableAdminSett
118119 optimizeRestoredTableOperationBaseCallable );
119120 }
120121
122+ /**
123+ * Package-private factory method to construct an instance of {@link BigtableTableAdminClientV2}
124+ * by reusing an existing stub, settings, clock, and background executor.
125+ *
126+ * <p>This is used by the legacy {@code BigtableTableAdminClient}'s escape hatch ({@code
127+ * getBaseClient()}) to wrap the legacy client's active stub, ensuring the underlying gRPC channel
128+ * and resources are shared rather than recreated.
129+ */
130+ static BigtableTableAdminClientV2 create (
131+ GrpcBigtableTableAdminStub stub ,
132+ BigtableTableAdminStubSettings settings ,
133+ ApiClock clock ,
134+ ScheduledExecutorService backgroundExecutor ,
135+ boolean shouldAutoClose )
136+ throws IOException {
137+ AwaitConsistencyCallableV2 awaitConsistencyCallable =
138+ createAwaitConsistencyCallable (stub , settings , clock , backgroundExecutor );
139+ OperationCallable <Void , Empty , OptimizeRestoredTableMetadata >
140+ optimizeRestoredTableOperationBaseCallable =
141+ createOptimizeRestoredTableOperationBaseCallable (stub , clock , backgroundExecutor );
142+ return new BigtableTableAdminClientV2 (
143+ stub ,
144+ backgroundExecutor ,
145+ shouldAutoClose ,
146+ awaitConsistencyCallable ,
147+ optimizeRestoredTableOperationBaseCallable );
148+ }
149+
121150 protected BigtableTableAdminClientV2 (
122151 GrpcBigtableTableAdminStub stub ,
123152 @ Nullable ScheduledExecutorService backgroundExecutor ,
@@ -133,7 +162,7 @@ protected BigtableTableAdminClientV2(
133162 this .optimizeRestoredTableOperationBaseCallable = optimizeRestoredTableOperationBaseCallable ;
134163 }
135164
136- static AwaitConsistencyCallableV2 createAwaitConsistencyCallable (
165+ private static AwaitConsistencyCallableV2 createAwaitConsistencyCallable (
137166 GrpcBigtableTableAdminStub stub ,
138167 BigtableTableAdminStubSettings settings ,
139168 ApiClock clock ,
@@ -156,7 +185,7 @@ static AwaitConsistencyCallableV2 createAwaitConsistencyCallable(
156185 private static OperationCallable <Void , Empty , OptimizeRestoredTableMetadata >
157186 createOptimizeRestoredTableOperationBaseCallable (
158187 GrpcBigtableTableAdminStub stub ,
159- BaseBigtableTableAdminSettings settings ,
188+ ApiClock clock ,
160189 ScheduledExecutorService backgroundExecutor )
161190 throws IOException {
162191
@@ -229,7 +258,7 @@ public Empty apply(OperationSnapshot input) {
229258 // (including channels, credentials, and headers) for executing the polling RPCs.
230259 ClientContext clientContext =
231260 ClientContext .newBuilder ()
232- .setClock (settings . getStubSettings (). getClock () )
261+ .setClock (clock )
233262 .setExecutor (backgroundExecutor )
234263 .setDefaultCallContext (GrpcCallContext .createDefault ())
235264 .build ();
0 commit comments