Skip to content

Commit c92aa67

Browse files
committed
cronet: CronetChannelBuilder extends a public API class
1 parent 972ae59 commit c92aa67

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

cronet/src/main/java/io/grpc/cronet/CronetChannelBuilder.java

+29-7
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@
2626
import com.google.common.util.concurrent.MoreExecutors;
2727
import io.grpc.ChannelLogger;
2828
import io.grpc.ExperimentalApi;
29-
import io.grpc.internal.AbstractManagedChannelImplBuilder;
29+
import io.grpc.ForwardingChannelBuilder;
30+
import io.grpc.Internal;
31+
import io.grpc.ManagedChannelBuilder;
3032
import io.grpc.internal.ClientTransportFactory;
3133
import io.grpc.internal.ConnectionClientTransport;
3234
import io.grpc.internal.GrpcUtil;
35+
import io.grpc.internal.ManagedChannelImplBuilder;
36+
import io.grpc.internal.ManagedChannelImplBuilder.ClientTransportFactoryBuilder;
3337
import io.grpc.internal.SharedResourceHolder;
3438
import io.grpc.internal.TransportTracer;
3539
import java.lang.reflect.InvocationTargetException;
@@ -46,8 +50,7 @@
4650

4751
/** Convenience class for building channels with the cronet transport. */
4852
@ExperimentalApi("There is no plan to make this API stable, given transport API instability")
49-
public final class CronetChannelBuilder extends
50-
AbstractManagedChannelImplBuilder<CronetChannelBuilder> {
53+
public final class CronetChannelBuilder extends ForwardingChannelBuilder<CronetChannelBuilder> {
5154

5255
private static final String LOG_TAG = "CronetChannelBuilder";
5356

@@ -81,6 +84,8 @@ public static CronetChannelBuilder forAddress(String name, int port) {
8184
private ScheduledExecutorService scheduledExecutorService;
8285

8386
private final CronetEngine cronetEngine;
87+
private final ManagedChannelImplBuilder managedChannelImplBuilder;
88+
private TransportTracer.Factory transportTracerFactory = TransportTracer.getDefaultFactory();
8489

8590
private boolean alwaysUsePut = false;
8691

@@ -103,12 +108,30 @@ public static CronetChannelBuilder forAddress(String name, int port) {
103108
private int trafficStatsUid;
104109

105110
private CronetChannelBuilder(String host, int port, CronetEngine cronetEngine) {
106-
super(
111+
super();
112+
113+
// An anonymous class to inject client transport factory builder.
114+
final class CronetChannelTransportFactoryBuilder implements ClientTransportFactoryBuilder {
115+
@Override
116+
public ClientTransportFactory buildClientTransportFactory() {
117+
return buildTransportFactory();
118+
}
119+
}
120+
121+
managedChannelImplBuilder = new ManagedChannelImplBuilder(
107122
InetSocketAddress.createUnresolved(host, port),
108-
GrpcUtil.authorityFromHostAndPort(host, port));
123+
GrpcUtil.authorityFromHostAndPort(host, port),
124+
new CronetChannelTransportFactoryBuilder(),
125+
null);
109126
this.cronetEngine = Preconditions.checkNotNull(cronetEngine, "cronetEngine");
110127
}
111128

129+
@Internal
130+
@Override
131+
protected ManagedChannelBuilder<?> delegate() {
132+
return managedChannelImplBuilder;
133+
}
134+
112135
/**
113136
* Sets the maximum message size allowed to be received on the channel. If not called,
114137
* defaults to {@link io.grpc.internal.GrpcUtil#DEFAULT_MAX_MESSAGE_SIZE}.
@@ -188,8 +211,7 @@ public final CronetChannelBuilder scheduledExecutorService(
188211
return this;
189212
}
190213

191-
@Override
192-
protected final ClientTransportFactory buildTransportFactory() {
214+
final ClientTransportFactory buildTransportFactory() {
193215
return new CronetTransportFactory(
194216
new TaggingStreamFactory(
195217
cronetEngine, trafficStatsTagSet, trafficStatsTag, trafficStatsUidSet, trafficStatsUid),

0 commit comments

Comments
 (0)