@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1784") @CanIgnoreReturnValue public final class NettyChannelBuilder extends AbstractManagedChannelImplBuilder<NettyChannelBuilder>
| Modifier and Type | Class and Description |
|---|---|
static class |
NettyChannelBuilder.LocalSocketPicker
This class is meant to be overriden with a custom implementation of
NettyChannelBuilder.LocalSocketPicker.createSocketAddress(java.net.SocketAddress, io.grpc.Attributes). |
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_FLOW_CONTROL_WINDOW |
transportTracerFactory| Modifier and Type | Method and Description |
|---|---|
protected ClientTransportFactory |
buildTransportFactory()
Subclasses should override this method to provide the
ClientTransportFactory
appropriate for this channel. |
NettyChannelBuilder |
channelFactory(io.netty.channel.ChannelFactory<? extends io.netty.channel.Channel> channelFactory)
Specifies the
ChannelFactory to create Channel instances. |
NettyChannelBuilder |
channelType(Class<? extends io.netty.channel.Channel> channelType)
Specifies the channel type to use, by default we use
EpollSocketChannel if available,
otherwise using NioSocketChannel. |
protected String |
checkAuthority(String authority)
Verifies the authority is valid.
|
NettyChannelBuilder |
enableKeepAlive(boolean enable)
Deprecated.
|
NettyChannelBuilder |
enableKeepAlive(boolean enable,
long keepAliveTime,
TimeUnit delayUnit,
long keepAliveTimeout,
TimeUnit timeoutUnit)
Deprecated.
|
NettyChannelBuilder |
eventLoopGroup(io.netty.channel.EventLoopGroup eventLoopGroup)
Provides an EventGroupLoop to be used by the netty transport.
|
NettyChannelBuilder |
flowControlWindow(int flowControlWindow)
Sets the flow control window in bytes.
|
static NettyChannelBuilder |
forAddress(SocketAddress serverAddress)
Creates a new builder with the given server address.
|
static NettyChannelBuilder |
forAddress(String host,
int port)
Creates a new builder with the given host and port.
|
static NettyChannelBuilder |
forTarget(String target)
Creates a new builder with the given target string that will be resolved by
NameResolver. |
protected int |
getDefaultPort()
Subclasses can override this method to provide a default port to
NameResolver for use
in cases where the target string doesn't include a port. |
NettyChannelBuilder |
keepAliveTime(long keepAliveTime,
TimeUnit timeUnit)
Sets the time without read activity before sending a keepalive ping.
|
NettyChannelBuilder |
keepAliveTimeout(long keepAliveTimeout,
TimeUnit timeUnit)
Sets the time waiting for read activity after sending a keepalive ping.
|
NettyChannelBuilder |
keepAliveWithoutCalls(boolean enable)
Sets whether keepalive will be performed when there are no outstanding RPC on a connection.
|
NettyChannelBuilder |
localSocketPicker(NettyChannelBuilder.LocalSocketPicker localSocketPicker)
If non-
null, attempts to create connections bound to a local port. |
NettyChannelBuilder |
maxHeaderListSize(int maxHeaderListSize)
Deprecated.
Use
maxInboundMetadataSize(int) instead |
NettyChannelBuilder |
maxInboundMetadataSize(int bytes)
Sets the maximum size of metadata allowed to be received.
|
NettyChannelBuilder |
negotiationType(NegotiationType type)
Sets the negotiation type for the HTTP/2 connection.
|
protected void |
setStatsEnabled(boolean value)
Disable or enable stats features.
|
protected void |
setStatsRecordRealTimeMetrics(boolean value)
Disable or enable real-time metrics recording.
|
protected void |
setStatsRecordStartedRpcs(boolean value)
Disable or enable stats recording for RPC upstarts.
|
protected void |
setTracingEnabled(boolean value)
Disable or enable tracing features.
|
NettyChannelBuilder |
sslContext(io.netty.handler.ssl.SslContext sslContext)
SSL/TLS context to use instead of the system default.
|
NettyChannelBuilder |
usePlaintext()
Equivalent to using
negotiationType(NegotiationType) with PLAINTEXT. |
NettyChannelBuilder |
usePlaintext(boolean skipNegotiation)
Deprecated.
use
usePlaintext() instead. |
NettyChannelBuilder |
useTransportSecurity()
Equivalent to using
negotiationType(NegotiationType) with TLS. |
<T> NettyChannelBuilder |
withOption(io.netty.channel.ChannelOption<T> option,
T value)
Specifies a channel option.
|
build, compressorRegistry, decompressorRegistry, defaultLoadBalancingPolicy, defaultServiceConfig, directExecutor, disableRetry, disableServiceConfigLookUp, enableFullStreamDecompression, enableRetry, executor, idleTimeout, intercept, intercept, maxHedgedAttempts, maxInboundMessageSize, maxInboundMessageSize, maxRetryAttempts, maxTraceEvents, nameResolverFactory, overrideAuthority, overrideCensusStatsModule, perRpcBufferLimit, proxyDetector, retryBufferSize, setBinaryLog, setStatsRecordFinishedRpcs, userAgentpublic static final int DEFAULT_FLOW_CONTROL_WINDOW
@CheckReturnValue public static NettyChannelBuilder forAddress(SocketAddress serverAddress)
forAddress(String, int) should
generally be preferred over this method, since that API permits delaying DNS lookups and
noticing changes to DNS.@CheckReturnValue public static NettyChannelBuilder forAddress(String host, int port)
@CheckReturnValue public static NettyChannelBuilder forTarget(String target)
NameResolver.public NettyChannelBuilder channelType(Class<? extends io.netty.channel.Channel> channelType)
EpollSocketChannel if available,
otherwise using NioSocketChannel.
You either use this or channelFactory(io.netty.channel.ChannelFactory) if your
Channel implementation has no no-args constructor.
It's an optional parameter. If the user has not provided an Channel type or ChannelFactory when the channel is built, the builder will use the default one which is static.
You must also provide corresponding eventLoopGroup(EventLoopGroup). For example,
NioSocketChannel must use NioEventLoopGroup, otherwise
your application won't start.
public NettyChannelBuilder channelFactory(io.netty.channel.ChannelFactory<? extends io.netty.channel.Channel> channelFactory)
ChannelFactory to create Channel instances. This method is
usually only used if the specific Channel requires complex logic which requires
additional information to create the Channel. Otherwise, recommend to use channelType(Class).
It's an optional parameter. If the user has not provided an Channel type or ChannelFactory when the channel is built, the builder will use the default one which is static.
You must also provide corresponding eventLoopGroup(EventLoopGroup). For example,
NioSocketChannel based ChannelFactory must use NioEventLoopGroup, otherwise your application won't start.
public <T> NettyChannelBuilder withOption(io.netty.channel.ChannelOption<T> option, T value)
public NettyChannelBuilder negotiationType(NegotiationType type)
Default: TLS
public NettyChannelBuilder eventLoopGroup(@Nullable io.netty.channel.EventLoopGroup eventLoopGroup)
It's an optional parameter. If the user has not provided an EventGroupLoop when the channel is built, the builder will use the default one which is static.
You must also provide corresponding channelType(Class) or channelFactory(ChannelFactory) corresponding to the given EventLoopGroup. For
example, NioEventLoopGroup requires NioSocketChannel
The channel won't take ownership of the given EventLoopGroup. It's caller's responsibility to shut it down when it's desired.
public NettyChannelBuilder sslContext(io.netty.handler.ssl.SslContext sslContext)
GrpcSslContexts, but options could have been overridden.public NettyChannelBuilder flowControlWindow(int flowControlWindow)
DEFAULT_FLOW_CONTROL_WINDOW).@Deprecated public NettyChannelBuilder maxHeaderListSize(int maxHeaderListSize)
maxInboundMetadataSize(int) insteadpublic NettyChannelBuilder maxInboundMetadataSize(int bytes)
maxInboundMetadataSize in class ManagedChannelBuilder<NettyChannelBuilder>bytes - the maximum size of received metadataIllegalArgumentException - if bytes is non-positive@Deprecated public NettyChannelBuilder usePlaintext(boolean skipNegotiation)
usePlaintext() instead.usePlaintext in class ManagedChannelBuilder<NettyChannelBuilder>skipNegotiation - @{code true} if there is a priori knowledge that the endpoint supports
plaintext, false if plaintext use must be negotiated.public NettyChannelBuilder usePlaintext()
negotiationType(NegotiationType) with PLAINTEXT.usePlaintext in class ManagedChannelBuilder<NettyChannelBuilder>public NettyChannelBuilder useTransportSecurity()
negotiationType(NegotiationType) with TLS.useTransportSecurity in class ManagedChannelBuilder<NettyChannelBuilder>@Deprecated public final NettyChannelBuilder enableKeepAlive(boolean enable)
keepAliveTime(long, java.util.concurrent.TimeUnit) and keepAliveTimeout(long, java.util.concurrent.TimeUnit) instead@Deprecated public final NettyChannelBuilder enableKeepAlive(boolean enable, long keepAliveTime, TimeUnit delayUnit, long keepAliveTimeout, TimeUnit timeoutUnit)
keepAliveTime(long, java.util.concurrent.TimeUnit) and keepAliveTimeout(long, java.util.concurrent.TimeUnit) insteadpublic NettyChannelBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit)
Long.MAX_VALUE nano seconds or an unreasonably large
value will disable keepalive. Defaults to infinite.
Clients must receive permission from the service owner before enabling this option. Keepalives can increase the load on services and are commonly "invisible" making it hard to notice when they are causing excessive load. Clients are strongly encouraged to use only as small of a value as necessary.
keepAliveTime in class ManagedChannelBuilder<NettyChannelBuilder>public NettyChannelBuilder keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit)
This value should be at least multiple times the RTT to allow for lost packets.
keepAliveTimeout in class ManagedChannelBuilder<NettyChannelBuilder>public NettyChannelBuilder keepAliveWithoutCalls(boolean enable)
false.
Clients must receive permission from the service owner before enabling this option.
Keepalives on unused connections can easilly accidentally consume a considerable amount of
bandwidth and CPU. idleTimeout() should generally be
used instead of this option.
keepAliveWithoutCalls in class ManagedChannelBuilder<NettyChannelBuilder>ManagedChannelBuilder.keepAliveTime(long, TimeUnit)public NettyChannelBuilder localSocketPicker(@Nullable NettyChannelBuilder.LocalSocketPicker localSocketPicker)
null, attempts to create connections bound to a local port.@CheckReturnValue @Internal protected ClientTransportFactory buildTransportFactory()
AbstractManagedChannelImplBuilderClientTransportFactory
appropriate for this channel. This method is meant for Transport implementors and should not
be used by normal users.buildTransportFactory in class AbstractManagedChannelImplBuilder<NettyChannelBuilder>@CheckReturnValue protected int getDefaultPort()
AbstractManagedChannelImplBuilderNameResolver for use
in cases where the target string doesn't include a port. The default implementation returns
GrpcUtil.DEFAULT_PORT_SSL.getDefaultPort in class AbstractManagedChannelImplBuilder<NettyChannelBuilder>@CheckReturnValue @Internal protected String checkAuthority(String authority)
AbstractManagedChannelImplBuildercheckAuthority in class AbstractManagedChannelImplBuilder<NettyChannelBuilder>protected void setTracingEnabled(boolean value)
AbstractManagedChannelImplBuilderFor the current release, calling setTracingEnabled(true) may have a side effect that
disables retry.
setTracingEnabled in class AbstractManagedChannelImplBuilder<NettyChannelBuilder>protected void setStatsEnabled(boolean value)
AbstractManagedChannelImplBuilderFor the current release, calling setStatsEnabled(true) may have a side effect that
disables retry.
setStatsEnabled in class AbstractManagedChannelImplBuilder<NettyChannelBuilder>protected void setStatsRecordStartedRpcs(boolean value)
AbstractManagedChannelImplBuilderAbstractManagedChannelImplBuilder.setStatsEnabled(boolean) is set to true. Enabled by default.setStatsRecordStartedRpcs in class AbstractManagedChannelImplBuilder<NettyChannelBuilder>protected void setStatsRecordRealTimeMetrics(boolean value)
AbstractManagedChannelImplBuilderAbstractManagedChannelImplBuilder.setStatsEnabled(boolean) is
set to true. Disabled by default.setStatsRecordRealTimeMetrics in class AbstractManagedChannelImplBuilder<NettyChannelBuilder>