Skip to content

Commit

Permalink
cronet: CronetChannelBuilder extends a public API class
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiitk committed Sep 1, 2020
1 parent d2aa91d commit 8c2b44e
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions cronet/src/main/java/io/grpc/cronet/CronetChannelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
import com.google.common.util.concurrent.MoreExecutors;
import io.grpc.ChannelLogger;
import io.grpc.ExperimentalApi;
import io.grpc.internal.AbstractManagedChannelImplBuilder;
import io.grpc.ForwardingChannelBuilder;
import io.grpc.Internal;
import io.grpc.ManagedChannelBuilder;
import io.grpc.internal.ClientTransportFactory;
import io.grpc.internal.ConnectionClientTransport;
import io.grpc.internal.GrpcUtil;
import io.grpc.internal.ManagedChannelImplBuilder;
import io.grpc.internal.ManagedChannelImplBuilder.ClientTransportFactoryBuilder;
import io.grpc.internal.SharedResourceHolder;
import io.grpc.internal.TransportTracer;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -46,8 +50,7 @@

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

private static final String LOG_TAG = "CronetChannelBuilder";

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

private final CronetEngine cronetEngine;
private final ManagedChannelImplBuilder managedChannelImplBuilder;
private TransportTracer.Factory transportTracerFactory = TransportTracer.getDefaultFactory();

private boolean alwaysUsePut = false;

Expand All @@ -103,12 +108,27 @@ public static CronetChannelBuilder forAddress(String name, int port) {
private int trafficStatsUid;

private CronetChannelBuilder(String host, int port, CronetEngine cronetEngine) {
super(
final class CronetChannelTransportFactoryBuilder implements ClientTransportFactoryBuilder {
@Override
public ClientTransportFactory buildClientTransportFactory() {
return buildTransportFactory();
}
}

managedChannelImplBuilder = new ManagedChannelImplBuilder(
InetSocketAddress.createUnresolved(host, port),
GrpcUtil.authorityFromHostAndPort(host, port));
GrpcUtil.authorityFromHostAndPort(host, port),
new CronetChannelTransportFactoryBuilder(),
null);
this.cronetEngine = Preconditions.checkNotNull(cronetEngine, "cronetEngine");
}

@Internal
@Override
protected ManagedChannelBuilder<?> delegate() {
return managedChannelImplBuilder;
}

/**
* Sets the maximum message size allowed to be received on the channel. If not called,
* defaults to {@link io.grpc.internal.GrpcUtil#DEFAULT_MAX_MESSAGE_SIZE}.
Expand Down Expand Up @@ -188,8 +208,7 @@ public final CronetChannelBuilder scheduledExecutorService(
return this;
}

@Override
protected final ClientTransportFactory buildTransportFactory() {
ClientTransportFactory buildTransportFactory() {
return new CronetTransportFactory(
new TaggingStreamFactory(
cronetEngine, trafficStatsTagSet, trafficStatsTag, trafficStatsUidSet, trafficStatsUid),
Expand Down

0 comments on commit 8c2b44e

Please sign in to comment.