1515 */
1616package com .google .cloud .bigtable .gaxx .grpc ;
1717
18- import com .google .api .core .InternalExtensionOnly ;
19- import com .google .api .gax .grpc .ChannelFactory ;
20- import com .google .api .gax .grpc .ChannelPoolSettings ;
21- import com .google .api .gax .grpc .GrpcTransportChannel ;
22- import com .google .api .gax .grpc .InstantiatingGrpcChannelProvider ;
23- import com .google .auth .Credentials ;
24- import com .google .common .base .Preconditions ;
25- import io .grpc .ManagedChannel ;
26- import java .io .IOException ;
27- import java .util .Map ;
28- import java .util .concurrent .Executor ;
29- import java .util .concurrent .ScheduledExecutorService ;
30- import com .google .api .gax .rpc .TransportChannel ;
31- import com .google .api .gax .rpc .TransportChannelProvider ;
32- import java .util .function .Supplier ;
33-
18+ import com .google .api .core .InternalExtensionOnly ;
19+ import com .google .api .gax .grpc .ChannelFactory ;
20+ import com .google .api .gax .grpc .ChannelPoolSettings ;
21+ import com .google .api .gax .grpc .GrpcTransportChannel ;
22+ import com .google .api .gax .grpc .InstantiatingGrpcChannelProvider ;
23+ import com .google .api .gax .rpc .TransportChannel ;
24+ import com .google .api .gax .rpc .TransportChannelProvider ;
25+ import com .google .auth .Credentials ;
26+ import com .google .common .base .Preconditions ;
27+ import io .grpc .ManagedChannel ;
28+ import java .io .IOException ;
29+ import java .util .Map ;
30+ import java .util .concurrent .Executor ;
31+ import java .util .concurrent .ScheduledExecutorService ;
3432
3533/** An instance of TransportChannelProvider that always provides the same TransportChannel. */
3634@ InternalExtensionOnly
@@ -57,12 +55,13 @@ public boolean needsExecutor() {
5755
5856 @ Override
5957 public BigtableTransportChannelProvider withExecutor (ScheduledExecutorService executor ) {
60- return withExecutor ((Executor ) executor );
58+ return withExecutor ((Executor ) executor );
6159 }
6260
6361 @ Override
6462 public BigtableTransportChannelProvider withExecutor (Executor executor ) {
65- InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider ) delegate .withExecutor (executor );
63+ InstantiatingGrpcChannelProvider newChannelProvider =
64+ (InstantiatingGrpcChannelProvider ) delegate .withExecutor (executor );
6665 return new BigtableTransportChannelProvider (newChannelProvider );
6766 }
6867
@@ -74,8 +73,7 @@ public boolean needsHeaders() {
7473 @ Override
7574 public BigtableTransportChannelProvider withHeaders (Map <String , String > headers ) {
7675 InstantiatingGrpcChannelProvider newChannelProvider =
77- (InstantiatingGrpcChannelProvider )
78- delegate .withHeaders (headers );
76+ (InstantiatingGrpcChannelProvider ) delegate .withHeaders (headers );
7977 return new BigtableTransportChannelProvider (newChannelProvider );
8078 }
8179
@@ -91,26 +89,25 @@ public TransportChannelProvider withEndpoint(String endpoint) {
9189 return new BigtableTransportChannelProvider (newChannelProvider );
9290 }
9391
94-
9592 @ Deprecated
9693 @ Override
9794 public boolean acceptsPoolSize () {
9895 return delegate .acceptsPoolSize ();
9996 }
10097
101-
10298 @ Deprecated
10399 @ Override
104100 public TransportChannelProvider withPoolSize (int size ) {
105- InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider ) delegate .withPoolSize (size );
101+ InstantiatingGrpcChannelProvider newChannelProvider =
102+ (InstantiatingGrpcChannelProvider ) delegate .withPoolSize (size );
106103 return new BigtableTransportChannelProvider (newChannelProvider );
107104 }
108105
109106 @ Override
110107 public TransportChannel getTransportChannel () throws IOException {
111108 TransportChannel result = transportChannel ;
112- if (result == null ){
113- synchronized (lock ) {
109+ if (result == null ) {
110+ synchronized (lock ) {
114111 result = transportChannel ;
115112 if (result == null ) {
116113 transportChannel = result = createTransportChannel ();
@@ -128,22 +125,18 @@ private TransportChannel createTransportChannel() throws IOException {
128125 // We achieve this by configuring our delegate to not use its own pooling
129126 // (by setting pool size to 1) and then calling getTransportChannel() on it.
130127 InstantiatingGrpcChannelProvider singleChannelProvider =
131- delegate .toBuilder ()
132- .setChannelPoolSettings (ChannelPoolSettings .staticallySized (1 ))
133- .build ();
134-
135- // Supplier<Channel> channelSupplier =
136- ChannelFactory channelFactory = () -> {
137- // () -> {
138- try {
139- // Each call creates a new underlying channel for the pool.
140- GrpcTransportChannel channel = (GrpcTransportChannel ) singleChannelProvider .getTransportChannel ();
141- return (ManagedChannel ) channel .getChannel ();
142- } catch (IOException e ) {
143- throw new java .io .UncheckedIOException (e );
144- }
145- };
146- // ChannelFactory channelFactory = () -> (ManagedChannel) channelSupplier.get();
128+ delegate .toBuilder ().setChannelPoolSettings (ChannelPoolSettings .staticallySized (1 )).build ();
129+
130+ ChannelFactory channelFactory =
131+ () -> {
132+ try {
133+ GrpcTransportChannel channel =
134+ (GrpcTransportChannel ) singleChannelProvider .getTransportChannel ();
135+ return (ManagedChannel ) channel .getChannel ();
136+ } catch (IOException e ) {
137+ throw new java .io .UncheckedIOException (e );
138+ }
139+ };
147140
148141 // Transfer pooling settings from the original delegate to the BigtableChannelPool.
149142 ChannelPoolSettings ogPoolSettings = delegate .getChannelPoolSettings ();
@@ -157,8 +150,7 @@ private TransportChannel createTransportChannel() throws IOException {
157150 .setPreemptiveRefreshEnabled (ogPoolSettings .isPreemptiveRefreshEnabled ())
158151 .build ();
159152
160- BigtableChannelPool btChannelPool =
161- BigtableChannelPool .create (btPoolSettings , channelFactory );
153+ BigtableChannelPool btChannelPool = BigtableChannelPool .create (btPoolSettings , channelFactory );
162154
163155 return GrpcTransportChannel .create (btChannelPool );
164156 }
@@ -175,12 +167,14 @@ public boolean needsCredentials() {
175167
176168 @ Override
177169 public TransportChannelProvider withCredentials (Credentials credentials ) {
178- InstantiatingGrpcChannelProvider newChannelProvider = (InstantiatingGrpcChannelProvider ) delegate .withCredentials (credentials );
170+ InstantiatingGrpcChannelProvider newChannelProvider =
171+ (InstantiatingGrpcChannelProvider ) delegate .withCredentials (credentials );
179172 return new BigtableTransportChannelProvider (newChannelProvider );
180173 }
181174
182175 /** Creates a FixedTransportChannelProvider. */
183- public static BigtableTransportChannelProvider create (InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider ) {
176+ public static BigtableTransportChannelProvider create (
177+ InstantiatingGrpcChannelProvider instantiatingGrpcChannelProvider ) {
184178 return new BigtableTransportChannelProvider (instantiatingGrpcChannelProvider );
185179 }
186- }
180+ }
0 commit comments