mirror of https://github.com/grpc/grpc-java.git
Allow client to specify ProtocolNegotiator in NettyChannelBuilder.
This commit is contained in:
parent
b9195fb9aa
commit
e775885be2
|
|
@ -65,6 +65,7 @@ public class NettyChannelBuilder extends AbstractManagedChannelImplBuilder<Netty
|
||||||
public static final int DEFAULT_FLOW_CONTROL_WINDOW = 1048576; // 1MiB
|
public static final int DEFAULT_FLOW_CONTROL_WINDOW = 1048576; // 1MiB
|
||||||
|
|
||||||
private NegotiationType negotiationType = NegotiationType.TLS;
|
private NegotiationType negotiationType = NegotiationType.TLS;
|
||||||
|
private ProtocolNegotiator protocolNegotiator;
|
||||||
private Class<? extends Channel> channelType = NioSocketChannel.class;
|
private Class<? extends Channel> channelType = NioSocketChannel.class;
|
||||||
@Nullable
|
@Nullable
|
||||||
private EventLoopGroup eventLoopGroup;
|
private EventLoopGroup eventLoopGroup;
|
||||||
|
|
@ -133,6 +134,18 @@ public class NettyChannelBuilder extends AbstractManagedChannelImplBuilder<Netty
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@link ProtocolNegotiator} to be used. If non-{@code null}, overrides the value
|
||||||
|
* specified in {@link #negotiationType(NegotiationType)} or {@link #usePlaintext(boolean)}.
|
||||||
|
*
|
||||||
|
* <p>Default: {@code null}.
|
||||||
|
*/
|
||||||
|
public final NettyChannelBuilder protocolNegotiator(
|
||||||
|
@Nullable ProtocolNegotiator protocolNegotiator) {
|
||||||
|
this.protocolNegotiator = protocolNegotiator;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides an EventGroupLoop to be used by the netty transport.
|
* Provides an EventGroupLoop to be used by the netty transport.
|
||||||
*
|
*
|
||||||
|
|
@ -202,7 +215,7 @@ public class NettyChannelBuilder extends AbstractManagedChannelImplBuilder<Netty
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ClientTransportFactory buildTransportFactory() {
|
protected ClientTransportFactory buildTransportFactory() {
|
||||||
return new NettyTransportFactory(channelType, negotiationType, sslContext,
|
return new NettyTransportFactory(channelType, negotiationType, protocolNegotiator, sslContext,
|
||||||
eventLoopGroup, flowControlWindow, maxMessageSize, maxHeaderListSize);
|
eventLoopGroup, flowControlWindow, maxMessageSize, maxHeaderListSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -252,6 +265,7 @@ public class NettyChannelBuilder extends AbstractManagedChannelImplBuilder<Netty
|
||||||
implements ClientTransportFactory {
|
implements ClientTransportFactory {
|
||||||
private final Class<? extends Channel> channelType;
|
private final Class<? extends Channel> channelType;
|
||||||
private final NegotiationType negotiationType;
|
private final NegotiationType negotiationType;
|
||||||
|
private final ProtocolNegotiator protocolNegotiator;
|
||||||
private final SslContext sslContext;
|
private final SslContext sslContext;
|
||||||
private final EventLoopGroup group;
|
private final EventLoopGroup group;
|
||||||
private final boolean usingSharedGroup;
|
private final boolean usingSharedGroup;
|
||||||
|
|
@ -261,6 +275,7 @@ public class NettyChannelBuilder extends AbstractManagedChannelImplBuilder<Netty
|
||||||
|
|
||||||
private NettyTransportFactory(Class<? extends Channel> channelType,
|
private NettyTransportFactory(Class<? extends Channel> channelType,
|
||||||
NegotiationType negotiationType,
|
NegotiationType negotiationType,
|
||||||
|
ProtocolNegotiator protocolNegotiator,
|
||||||
SslContext sslContext,
|
SslContext sslContext,
|
||||||
EventLoopGroup group,
|
EventLoopGroup group,
|
||||||
int flowControlWindow,
|
int flowControlWindow,
|
||||||
|
|
@ -268,6 +283,7 @@ public class NettyChannelBuilder extends AbstractManagedChannelImplBuilder<Netty
|
||||||
int maxHeaderListSize) {
|
int maxHeaderListSize) {
|
||||||
this.channelType = channelType;
|
this.channelType = channelType;
|
||||||
this.negotiationType = negotiationType;
|
this.negotiationType = negotiationType;
|
||||||
|
this.protocolNegotiator = protocolNegotiator;
|
||||||
this.sslContext = sslContext;
|
this.sslContext = sslContext;
|
||||||
this.flowControlWindow = flowControlWindow;
|
this.flowControlWindow = flowControlWindow;
|
||||||
this.maxMessageSize = maxMessageSize;
|
this.maxMessageSize = maxMessageSize;
|
||||||
|
|
@ -283,7 +299,7 @@ public class NettyChannelBuilder extends AbstractManagedChannelImplBuilder<Netty
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClientTransport newClientTransport(SocketAddress serverAddress, String authority) {
|
public ClientTransport newClientTransport(SocketAddress serverAddress, String authority) {
|
||||||
ProtocolNegotiator negotiator =
|
ProtocolNegotiator negotiator = protocolNegotiator != null ? protocolNegotiator :
|
||||||
createProtocolNegotiator(authority, negotiationType, sslContext);
|
createProtocolNegotiator(authority, negotiationType, sslContext);
|
||||||
return new NettyClientTransport(serverAddress, channelType, group, negotiator,
|
return new NettyClientTransport(serverAddress, channelType, group, negotiator,
|
||||||
flowControlWindow, maxMessageSize, maxHeaderListSize, authority);
|
flowControlWindow, maxMessageSize, maxHeaderListSize, authority);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue