1616package com .google .cloud .bigtable .admin .v2 .stub ;
1717
1818import com .google .api .core .ApiAsyncFunction ;
19- import com .google .api .core .ApiClock ;
2019import com .google .api .core .ApiFunction ;
2120import com .google .api .core .ApiFuture ;
2221import com .google .api .core .ApiFutures ;
23- import com .google .api .core .InternalApi ;
2422import com .google .api .gax .retrying .ExponentialPollAlgorithm ;
2523import com .google .api .gax .retrying .NonCancellableFuture ;
2624import com .google .api .gax .retrying .ResultRetryAlgorithmWithContext ;
3230import com .google .api .gax .retrying .ScheduledRetryingExecutor ;
3331import com .google .api .gax .retrying .TimedAttemptSettings ;
3432import com .google .api .gax .rpc .ApiCallContext ;
33+ import com .google .api .gax .rpc .ClientContext ;
3534import com .google .api .gax .rpc .UnaryCallable ;
3635import com .google .bigtable .admin .v2 .CheckConsistencyRequest ;
3736import com .google .bigtable .admin .v2 .CheckConsistencyResponse ;
4342import com .google .common .util .concurrent .MoreExecutors ;
4443import java .util .concurrent .Callable ;
4544import java .util .concurrent .CancellationException ;
46- import java .util .concurrent .ScheduledExecutorService ;
47- import javax .annotation .Nullable ;
4845
4946/**
5047 * Callable that waits until either replication or Data Boost has caught up to the point it was
5350 * <p>This callable wraps GenerateConsistencyToken and CheckConsistency RPCs. It will generate a
5451 * token then poll until isConsistent is true.
5552 */
56- @ InternalApi
57- public class AwaitConsistencyCallable extends UnaryCallable <ConsistencyRequest , Void > {
53+ class AwaitConsistencyCallable extends UnaryCallable <ConsistencyRequest , Void > {
5854 private final UnaryCallable <GenerateConsistencyTokenRequest , GenerateConsistencyTokenResponse >
5955 generateCallable ;
6056 private final UnaryCallable <CheckConsistencyRequest , CheckConsistencyResponse > checkCallable ;
6157 private final RetryingExecutor <CheckConsistencyResponse > executor ;
6258
63- @ Nullable private final TableAdminRequestContext requestContext ;
59+ private final TableAdminRequestContext requestContext ;
6460
65- @ InternalApi
66- public static AwaitConsistencyCallable create (
61+ static AwaitConsistencyCallable create (
6762 UnaryCallable <GenerateConsistencyTokenRequest , GenerateConsistencyTokenResponse >
6863 generateCallable ,
6964 UnaryCallable <CheckConsistencyRequest , CheckConsistencyResponse > checkCallable ,
70- ApiClock clock ,
71- ScheduledExecutorService executor ,
65+ ClientContext clientContext ,
7266 RetrySettings pollingSettings ,
73- @ Nullable TableAdminRequestContext requestContext ) {
67+ TableAdminRequestContext requestContext ) {
7468
7569 RetryAlgorithm <CheckConsistencyResponse > retryAlgorithm =
7670 new RetryAlgorithm <>(
77- new PollResultAlgorithm (), new ExponentialPollAlgorithm (pollingSettings , clock ));
71+ new PollResultAlgorithm (),
72+ new ExponentialPollAlgorithm (pollingSettings , clientContext .getClock ()));
7873
7974 RetryingExecutor <CheckConsistencyResponse > retryingExecutor =
80- new ScheduledRetryingExecutor <>(retryAlgorithm , executor );
75+ new ScheduledRetryingExecutor <>(retryAlgorithm , clientContext . getExecutor () );
8176
8277 return new AwaitConsistencyCallable (
8378 generateCallable , checkCallable , retryingExecutor , requestContext );
8479 }
8580
86- @ InternalApi
87- public static AwaitConsistencyCallable create (
88- UnaryCallable <GenerateConsistencyTokenRequest , GenerateConsistencyTokenResponse >
89- generateCallable ,
90- UnaryCallable <CheckConsistencyRequest , CheckConsistencyResponse > checkCallable ,
91- ApiClock clock ,
92- ScheduledExecutorService executor ,
93- RetrySettings pollingSettings ) {
94- return create (generateCallable , checkCallable , clock , executor , pollingSettings , null );
95- }
96-
9781 @ VisibleForTesting
9882 AwaitConsistencyCallable (
9983 UnaryCallable <GenerateConsistencyTokenRequest , GenerateConsistencyTokenResponse >
10084 generateCallable ,
10185 UnaryCallable <CheckConsistencyRequest , CheckConsistencyResponse > checkCallable ,
10286 RetryingExecutor <CheckConsistencyResponse > executor ,
103- @ Nullable TableAdminRequestContext requestContext ) {
87+ TableAdminRequestContext requestContext ) {
10488 this .generateCallable = generateCallable ;
10589 this .checkCallable = checkCallable ;
10690 this .executor = executor ;
@@ -114,30 +98,22 @@ public ApiFuture<Void> futureCall(
11498 // If the token is already provided, skip generation and poll directly.
11599 if (consistencyRequest .getConsistencyToken () != null ) {
116100 CheckConsistencyRequest request =
117- requestContext == null
118- ? consistencyRequest .toCheckConsistencyProto (consistencyRequest .getConsistencyToken ())
119- : consistencyRequest .toCheckConsistencyProto (
120- requestContext , consistencyRequest .getConsistencyToken ());
101+ consistencyRequest .toCheckConsistencyProto (
102+ requestContext , consistencyRequest .getConsistencyToken ());
121103 return pollToken (request , apiCallContext );
122104 }
123105
124106 ApiFuture <GenerateConsistencyTokenResponse > tokenFuture =
125- generateToken (
126- requestContext == null
127- ? consistencyRequest .toGenerateTokenProto ()
128- : consistencyRequest .toGenerateTokenProto (requestContext ),
129- apiCallContext );
107+ generateToken (consistencyRequest .toGenerateTokenProto (requestContext ), apiCallContext );
130108
131109 return ApiFutures .transformAsync (
132110 tokenFuture ,
133111 new ApiAsyncFunction <GenerateConsistencyTokenResponse , Void >() {
134112 @ Override
135113 public ApiFuture <Void > apply (GenerateConsistencyTokenResponse input ) {
136114 CheckConsistencyRequest request =
137- requestContext == null
138- ? consistencyRequest .toCheckConsistencyProto (input .getConsistencyToken ())
139- : consistencyRequest .toCheckConsistencyProto (
140- requestContext , input .getConsistencyToken ());
115+ consistencyRequest .toCheckConsistencyProto (
116+ requestContext , input .getConsistencyToken ());
141117 return pollToken (request , apiCallContext );
142118 }
143119 },
0 commit comments