2323import com .google .api .gax .rpc .TransportChannel ;
2424import com .google .api .gax .rpc .TransportChannelProvider ;
2525import com .google .auth .Credentials ;
26+ import com .google .cloud .bigtable .data .v2 .stub .BigtableChannelPrimer ;
2627import com .google .common .base .Preconditions ;
2728import io .grpc .ManagedChannel ;
2829import java .io .IOException ;
2930import java .util .Map ;
3031import java .util .concurrent .Executor ;
3132import java .util .concurrent .ScheduledExecutorService ;
33+ import javax .annotation .Nullable ;
3234
3335/**
3436 * An instance of TransportChannelProvider that provides a TransportChannel through a supplied
3840public final class BigtableTransportChannelProvider implements TransportChannelProvider {
3941
4042 private final InstantiatingGrpcChannelProvider delegate ;
43+ @ Nullable private final BigtableChannelPrimer channelPrimer ;
4144
4245 private BigtableTransportChannelProvider (
43- InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider ) {
46+ InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider ,
47+ BigtableChannelPrimer channelPrimer ) {
4448 delegate = Preconditions .checkNotNull (instantiatingGrpcChannelProvider );
49+ this .channelPrimer = channelPrimer ;
4550 }
4651
4752 @ Override
@@ -63,7 +68,7 @@ public BigtableTransportChannelProvider withExecutor(ScheduledExecutorService ex
6368 public BigtableTransportChannelProvider withExecutor (Executor executor ) {
6469 InstantiatingGrpcChannelProvider newChannelProvider =
6570 (InstantiatingGrpcChannelProvider ) delegate .withExecutor (executor );
66- return new BigtableTransportChannelProvider (newChannelProvider );
71+ return new BigtableTransportChannelProvider (newChannelProvider , channelPrimer );
6772 }
6873
6974 @ Override
@@ -75,7 +80,7 @@ public boolean needsHeaders() {
7580 public BigtableTransportChannelProvider withHeaders (Map <String , String > headers ) {
7681 InstantiatingGrpcChannelProvider newChannelProvider =
7782 (InstantiatingGrpcChannelProvider ) delegate .withHeaders (headers );
78- return new BigtableTransportChannelProvider (newChannelProvider );
83+ return new BigtableTransportChannelProvider (newChannelProvider , channelPrimer );
7984 }
8085
8186 @ Override
@@ -87,7 +92,7 @@ public boolean needsEndpoint() {
8792 public TransportChannelProvider withEndpoint (String endpoint ) {
8893 InstantiatingGrpcChannelProvider newChannelProvider =
8994 (InstantiatingGrpcChannelProvider ) delegate .withEndpoint (endpoint );
90- return new BigtableTransportChannelProvider (newChannelProvider );
95+ return new BigtableTransportChannelProvider (newChannelProvider , channelPrimer );
9196 }
9297
9398 @ Deprecated
@@ -101,7 +106,7 @@ public boolean acceptsPoolSize() {
101106 public TransportChannelProvider withPoolSize (int size ) {
102107 InstantiatingGrpcChannelProvider newChannelProvider =
103108 (InstantiatingGrpcChannelProvider ) delegate .withPoolSize (size );
104- return new BigtableTransportChannelProvider (newChannelProvider );
109+ return new BigtableTransportChannelProvider (newChannelProvider , channelPrimer );
105110 }
106111
107112 /** Expected to only be called once when BigtableClientContext is created */
@@ -130,7 +135,8 @@ public TransportChannel getTransportChannel() throws IOException {
130135 BigtableChannelPoolSettings btPoolSettings =
131136 BigtableChannelPoolSettings .copyFrom (delegate .getChannelPoolSettings ());
132137
133- BigtableChannelPool btChannelPool = BigtableChannelPool .create (btPoolSettings , channelFactory );
138+ BigtableChannelPool btChannelPool =
139+ BigtableChannelPool .create (btPoolSettings , channelFactory , channelPrimer );
134140
135141 return GrpcTransportChannel .create (btChannelPool );
136142 }
@@ -149,12 +155,19 @@ public boolean needsCredentials() {
149155 public TransportChannelProvider withCredentials (Credentials credentials ) {
150156 InstantiatingGrpcChannelProvider newChannelProvider =
151157 (InstantiatingGrpcChannelProvider ) delegate .withCredentials (credentials );
152- return new BigtableTransportChannelProvider (newChannelProvider );
158+ return new BigtableTransportChannelProvider (newChannelProvider , channelPrimer );
153159 }
154160
155161 /** Creates a BigtableTransportChannelProvider. */
156162 public static BigtableTransportChannelProvider create (
163+ InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider ,
164+ BigtableChannelPrimer channelPrimer ) {
165+ Preconditions .checkNotNull (channelPrimer );
166+ return new BigtableTransportChannelProvider (instantiatingGrpcChannelProvider , channelPrimer );
167+ }
168+
169+ public static BigtableTransportChannelProvider createWithoutChannelPriming (
157170 InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider ) {
158- return new BigtableTransportChannelProvider (instantiatingGrpcChannelProvider );
171+ return new BigtableTransportChannelProvider (instantiatingGrpcChannelProvider , null );
159172 }
160173}
0 commit comments