mirror of https://github.com/grpc/grpc-java.git
netty: Allow specifying ProtocolNegotatiorFactory directly to Channels
This will be the replacement for TransportCreationParamsFilterFactory and matches somewhat what used to be done and what is done on server-side.
This commit is contained in:
parent
70b1b1696a
commit
acf80d63b0
|
|
@ -63,6 +63,19 @@ public final class InternalNettyChannelBuilder {
|
||||||
builder.setDynamicParamsFactory(factory);
|
builder.setDynamicParamsFactory(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A class that provides a Netty handler to control protocol negotiation. */
|
||||||
|
public interface ProtocolNegotiatorFactory
|
||||||
|
extends NettyChannelBuilder.ProtocolNegotiatorFactory {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@link ProtocolNegotiatorFactory} to be used. Overrides any specified negotiation type
|
||||||
|
* and {@code SslContext}.
|
||||||
|
*/
|
||||||
|
public static void setProtocolNegotiatorFactory(
|
||||||
|
NettyChannelBuilder builder, ProtocolNegotiatorFactory protocolNegotiator) {
|
||||||
|
builder.protocolNegotiatorFactory(protocolNegotiator);
|
||||||
|
}
|
||||||
|
|
||||||
public static void setStatsEnabled(NettyChannelBuilder builder, boolean value) {
|
public static void setStatsEnabled(NettyChannelBuilder builder, boolean value) {
|
||||||
builder.setStatsEnabled(value);
|
builder.setStatsEnabled(value);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ public final class NettyChannelBuilder
|
||||||
private long keepAliveTimeoutNanos = DEFAULT_KEEPALIVE_TIMEOUT_NANOS;
|
private long keepAliveTimeoutNanos = DEFAULT_KEEPALIVE_TIMEOUT_NANOS;
|
||||||
private boolean keepAliveWithoutCalls;
|
private boolean keepAliveWithoutCalls;
|
||||||
private TransportCreationParamsFilterFactory dynamicParamsFactory;
|
private TransportCreationParamsFilterFactory dynamicParamsFactory;
|
||||||
|
private ProtocolNegotiatorFactory protocolNegotiatorFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new builder with the given server address. This factory method is primarily intended
|
* Creates a new builder with the given server address. This factory method is primarily intended
|
||||||
|
|
@ -334,6 +335,10 @@ public final class NettyChannelBuilder
|
||||||
TransportCreationParamsFilterFactory transportCreationParamsFilterFactory =
|
TransportCreationParamsFilterFactory transportCreationParamsFilterFactory =
|
||||||
dynamicParamsFactory;
|
dynamicParamsFactory;
|
||||||
if (transportCreationParamsFilterFactory == null) {
|
if (transportCreationParamsFilterFactory == null) {
|
||||||
|
ProtocolNegotiator negotiator;
|
||||||
|
if (protocolNegotiatorFactory != null) {
|
||||||
|
negotiator = protocolNegotiatorFactory.buildProtocolNegotiator();
|
||||||
|
} else {
|
||||||
SslContext localSslContext = sslContext;
|
SslContext localSslContext = sslContext;
|
||||||
if (negotiationType == NegotiationType.TLS && localSslContext == null) {
|
if (negotiationType == NegotiationType.TLS && localSslContext == null) {
|
||||||
try {
|
try {
|
||||||
|
|
@ -342,8 +347,8 @@ public final class NettyChannelBuilder
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ProtocolNegotiator negotiator =
|
negotiator = createProtocolNegotiatorByType(negotiationType, localSslContext);
|
||||||
createProtocolNegotiatorByType(negotiationType, localSslContext);
|
}
|
||||||
transportCreationParamsFilterFactory =
|
transportCreationParamsFilterFactory =
|
||||||
new DefaultNettyTransportCreationParamsFilterFactory(negotiator);
|
new DefaultNettyTransportCreationParamsFilterFactory(negotiator);
|
||||||
}
|
}
|
||||||
|
|
@ -413,6 +418,11 @@ public final class NettyChannelBuilder
|
||||||
this.dynamicParamsFactory = checkNotNull(factory, "factory");
|
this.dynamicParamsFactory = checkNotNull(factory, "factory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void protocolNegotiatorFactory(ProtocolNegotiatorFactory protocolNegotiatorFactory) {
|
||||||
|
this.protocolNegotiatorFactory
|
||||||
|
= Preconditions.checkNotNull(protocolNegotiatorFactory, "protocolNegotiatorFactory");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setTracingEnabled(boolean value) {
|
protected void setTracingEnabled(boolean value) {
|
||||||
super.setTracingEnabled(value);
|
super.setTracingEnabled(value);
|
||||||
|
|
@ -454,6 +464,14 @@ public final class NettyChannelBuilder
|
||||||
ProtocolNegotiator getProtocolNegotiator();
|
ProtocolNegotiator getProtocolNegotiator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ProtocolNegotiatorFactory {
|
||||||
|
/**
|
||||||
|
* Returns a ProtocolNegotatior instance configured for this Builder. This method is called
|
||||||
|
* during {@code ManagedChannelBuilder#build()}.
|
||||||
|
*/
|
||||||
|
ProtocolNegotiator buildProtocolNegotiator();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates Netty transports. Exposed for internal use, as it should be private.
|
* Creates Netty transports. Exposed for internal use, as it should be private.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue