Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit bccb0ec

Browse files
committed
cleanup
Change-Id: If2c94d93cec5903795cd723a9b7b26bd36efaf79
1 parent e365916 commit bccb0ec

2 files changed

Lines changed: 44 additions & 65 deletions

File tree

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/BigtableClientContext.java

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
import com.google.api.gax.core.BackgroundResource;
2121
import com.google.api.gax.core.CredentialsProvider;
2222
import com.google.api.gax.core.FixedCredentialsProvider;
23-
import com.google.api.gax.rpc.TransportChannelProvider;
2423
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
2524
import com.google.api.gax.rpc.ClientContext;
26-
import com.google.cloud.bigtable.gaxx.grpc.BigtableTransportChannelProvider;
2725
import com.google.auth.Credentials;
2826
import com.google.auth.oauth2.ServiceAccountJwtAccessCredentials;
2927
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
@@ -34,6 +32,7 @@
3432
import com.google.cloud.bigtable.data.v2.stub.metrics.ErrorCountPerConnectionMetricTracker;
3533
import com.google.cloud.bigtable.data.v2.stub.metrics.MetricsProvider;
3634
import com.google.cloud.bigtable.data.v2.stub.metrics.NoopMetricsProvider;
35+
import com.google.cloud.bigtable.gaxx.grpc.BigtableTransportChannelProvider;
3736
import io.grpc.ManagedChannelBuilder;
3837
import io.grpc.opentelemetry.GrpcOpenTelemetry;
3938
import io.opentelemetry.api.OpenTelemetry;
@@ -63,17 +62,6 @@ public static BigtableClientContext create(EnhancedBigtableStubSettings settings
6362
throws IOException {
6463
EnhancedBigtableStubSettings.Builder builder = settings.toBuilder();
6564

66-
// TransportChannelProvider transportChannelProvider = settings.getTransportChannelProvider();
67-
// if (transportChannelProvider instanceof InstantiatingGrpcChannelProvider) {
68-
//
69-
//
70-
//
71-
// BigtableTransportChannelProvider btTransportProvider = BigtableTransportChannelProvider.create(
72-
// (InstantiatingGrpcChannelProvider) transportChannelProvider);
73-
//
74-
// builder.setTransportChannelProvider(btTransportProvider);
75-
// }
76-
7765
// Set up credentials
7866
patchCredentials(builder);
7967

@@ -107,7 +95,6 @@ public static BigtableClientContext create(EnhancedBigtableStubSettings settings
10795
? ((InstantiatingGrpcChannelProvider) builder.getTransportChannelProvider()).toBuilder()
10896
: null;
10997

110-
11198
@Nullable OpenTelemetrySdk internalOtel = null;
11299
@Nullable ErrorCountPerConnectionMetricTracker errorCountPerConnectionMetricTracker = null;
113100

@@ -145,13 +132,11 @@ public static BigtableClientContext create(EnhancedBigtableStubSettings settings
145132
builder.getHeaderProvider().getHeaders()));
146133
}
147134

148-
149-
BigtableTransportChannelProvider btTransportProvider = BigtableTransportChannelProvider.create(
150-
(InstantiatingGrpcChannelProvider) transportProvider.build());
135+
BigtableTransportChannelProvider btTransportProvider =
136+
BigtableTransportChannelProvider.create(
137+
(InstantiatingGrpcChannelProvider) transportProvider.build());
151138

152139
builder.setTransportChannelProvider(btTransportProvider);
153-
154-
//builder.setTransportChannelProvider(transportProvider.build());
155140
}
156141

157142
ClientContext clientContext = ClientContext.create(builder.build());

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/gaxx/grpc/BigtableTransportChannelProvider.java

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@
1515
*/
1616
package 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

Comments
 (0)