From 3be67732b94e5045508c3770d82440df194ad515 Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Thu, 13 Aug 2020 17:18:17 -0400 Subject: [PATCH] Issue #7211 WIP --- .../internal/ManagedChannelImplBuilder.java | 25 +++++++++++++++++++ .../io/grpc/okhttp/OkHttpChannelBuilder.java | 20 ++++++++++----- 2 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java diff --git a/core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java b/core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java new file mode 100644 index 000000000000..a3d34906e9f7 --- /dev/null +++ b/core/src/main/java/io/grpc/internal/ManagedChannelImplBuilder.java @@ -0,0 +1,25 @@ +package io.grpc.internal; + +public class ManagedChannelImplBuilder extends AbstractManagedChannelImplBuilder { + private final TransportFactoryBuilder transportFactoryBuilder; + + public interface TransportFactoryBuilder { + ClientTransportFactory buildTransportFactory(); + } + + protected ManagedChannelImplBuilder(String target, + TransportFactoryBuilder transportFactoryBuilder) { + super(target); + this.transportFactoryBuilder = transportFactoryBuilder; + } + + public static ManagedChannelImplBuilder forTarget(String target, + TransportFactoryBuilder transportFactoryBuilder) { + return new ManagedChannelImplBuilder(target, transportFactoryBuilder); + } + + @Override + protected ClientTransportFactory buildTransportFactory() { + return transportFactoryBuilder.buildTransportFactory(); + } +} \ No newline at end of file diff --git a/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java b/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java index 26a76f2c8c45..56f247b503da 100644 --- a/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java +++ b/okhttp/src/main/java/io/grpc/okhttp/OkHttpChannelBuilder.java @@ -24,13 +24,14 @@ import com.google.common.base.Preconditions; import io.grpc.ChannelLogger; import io.grpc.ExperimentalApi; +import io.grpc.ForwardingChannelBuilder; import io.grpc.Internal; -import io.grpc.internal.AbstractManagedChannelImplBuilder; import io.grpc.internal.AtomicBackoff; import io.grpc.internal.ClientTransportFactory; import io.grpc.internal.ConnectionClientTransport; import io.grpc.internal.GrpcUtil; import io.grpc.internal.KeepAliveManager; +import io.grpc.internal.ManagedChannelImplBuilder; import io.grpc.internal.SharedResourceHolder; import io.grpc.internal.SharedResourceHolder.Resource; import io.grpc.internal.TransportTracer; @@ -55,9 +56,11 @@ /** Convenience class for building channels with the OkHttp transport. */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1785") public class OkHttpChannelBuilder extends - AbstractManagedChannelImplBuilder { + ForwardingChannelBuilder { public static final int DEFAULT_FLOW_CONTROL_WINDOW = 65535; + private final ManagedChannelImplBuilder managedChannelImplBuilder; + private TransportTracer.Factory transportTracerFactory = TransportTracer.getDefaultFactory(); /** Identifies the negotiation used for starting up HTTP/2. */ private enum NegotiationType { @@ -115,6 +118,11 @@ public static OkHttpChannelBuilder forTarget(String target) { return new OkHttpChannelBuilder(target); } + @Override + protected ManagedChannelImplBuilder delegate() { + return managedChannelImplBuilder; + } + private Executor transportExecutor; private ScheduledExecutorService scheduledExecutorService; @@ -140,7 +148,9 @@ protected OkHttpChannelBuilder(String host, int port) { } private OkHttpChannelBuilder(String target) { - super(target); + super(); + managedChannelImplBuilder = ManagedChannelImplBuilder.forTarget(target, + this::buildTransportFactory); } @VisibleForTesting @@ -363,9 +373,7 @@ public OkHttpChannelBuilder maxInboundMetadataSize(int bytes) { return this; } - @Override - @Internal - protected final ClientTransportFactory buildTransportFactory() { + private final ClientTransportFactory buildTransportFactory() { boolean enableKeepAlive = keepAliveTimeNanos != KEEPALIVE_TIME_NANOS_DISABLED; return new OkHttpTransportFactory( transportExecutor,