diff options
author | Eric Gribkoff <ericgribkoff@google.com> | 2017-06-19 23:20:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-19 23:20:59 -0700 |
commit | e01cec5c2c23fc38e4a3f3ff92d7c08617f76d30 (patch) | |
tree | 2d7d3c34c0a5f9d2ab0c6853ee949e3b7c41927e /netty | |
parent | d3d30e1c3a353e0ded89c487e60bc8c9d6d8615d (diff) | |
download | grpc-grpc-java-e01cec5c2c23fc38e4a3f3ff92d7c08617f76d30.tar.gz |
netty: push sslContext initialization into transportCreationParamsFilterFactory
Diffstat (limited to 'netty')
-rw-r--r-- | netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java | 88 |
1 files changed, 48 insertions, 40 deletions
diff --git a/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java b/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java index 18770a8e3..3683c6242 100644 --- a/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java +++ b/netty/src/main/java/io/grpc/netty/NettyChannelBuilder.java @@ -432,7 +432,6 @@ public final class NettyChannelBuilder private final Class<? extends Channel> channelType; private final Map<ChannelOption<?>, ?> channelOptions; private final NegotiationType negotiationType; - private final SslContext sslContext; private final EventLoopGroup group; private final boolean usingSharedGroup; private final int flowControlWindow; @@ -452,23 +451,10 @@ public final class NettyChannelBuilder this.channelType = channelType; this.negotiationType = negotiationType; this.channelOptions = new HashMap<ChannelOption<?>, Object>(channelOptions); - if (negotiationType == NegotiationType.TLS && sslContext == null) { - try { - sslContext = GrpcSslContexts.forClient().build(); - } catch (SSLException ex) { - throw new RuntimeException(ex); - } - } - this.sslContext = sslContext; if (transportCreationParamsFilterFactory == null) { - transportCreationParamsFilterFactory = new TransportCreationParamsFilterFactory() { - @Override - public TransportCreationParamsFilter create( - SocketAddress targetServerAddress, String authority, String userAgent) { - return new DynamicNettyTransportParams(targetServerAddress, authority, userAgent); - } - }; + transportCreationParamsFilterFactory = + new DefaultNettyTransportCreationParamsFilterFactory(sslContext); } this.transportCreationParamsFilterFactory = transportCreationParamsFilterFactory; @@ -523,38 +509,60 @@ public final class NettyChannelBuilder } } - @CheckReturnValue - private final class DynamicNettyTransportParams implements TransportCreationParamsFilter { + private final class DefaultNettyTransportCreationParamsFilterFactory + implements TransportCreationParamsFilterFactory { + private final SslContext sslContext; - private final SocketAddress targetServerAddress; - private final String authority; - @Nullable private final String userAgent; - - private DynamicNettyTransportParams( - SocketAddress targetServerAddress, String authority, String userAgent) { - this.targetServerAddress = targetServerAddress; - this.authority = authority; - this.userAgent = userAgent; + private DefaultNettyTransportCreationParamsFilterFactory(SslContext sslContext) { + if (negotiationType == NegotiationType.TLS && sslContext == null) { + try { + sslContext = GrpcSslContexts.forClient().build(); + } catch (SSLException ex) { + throw new RuntimeException(ex); + } + } + this.sslContext = sslContext; } @Override - public SocketAddress getTargetServerAddress() { - return targetServerAddress; + public TransportCreationParamsFilter create( + SocketAddress targetServerAddress, String authority, String userAgent) { + return new DynamicNettyTransportParams(targetServerAddress, authority, userAgent); } - @Override - public String getAuthority() { - return authority; - } + @CheckReturnValue + private final class DynamicNettyTransportParams implements TransportCreationParamsFilter { - @Override - public String getUserAgent() { - return userAgent; - } + private final SocketAddress targetServerAddress; + private final String authority; + @Nullable private final String userAgent; - @Override - public ProtocolNegotiator getProtocolNegotiator() { - return createProtocolNegotiator(authority, negotiationType, sslContext); + private DynamicNettyTransportParams( + SocketAddress targetServerAddress, String authority, String userAgent) { + this.targetServerAddress = targetServerAddress; + this.authority = authority; + this.userAgent = userAgent; + } + + @Override + public SocketAddress getTargetServerAddress() { + return targetServerAddress; + } + + @Override + public String getAuthority() { + return authority; + } + + @Override + public String getUserAgent() { + return userAgent; + } + + @Override + public ProtocolNegotiator getProtocolNegotiator() { + return createProtocolNegotiator(authority, negotiationType, sslContext); + } } } } |