@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1784") @CheckReturnValue public final class NettyChannelBuilder extends io.grpc.internal.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 |
Modifier and Type | Method and Description |
---|---|
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 ManagedChannelBuilder<?> |
delegate() |
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(SocketAddress serverAddress,
ChannelCredentials creds)
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 |
forAddress(String host,
int port,
ChannelCredentials creds)
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 . |
static NettyChannelBuilder |
forTarget(String target,
ChannelCredentials creds)
Creates a new builder with the given target string that will be resolved by
NameResolver . |
NettyChannelBuilder |
initialFlowControlWindow(int initialFlowControlWindow)
Sets the initial flow control window in bytes.
|
NettyChannelBuilder |
keepAliveTime(long keepAliveTime,
TimeUnit timeUnit) |
NettyChannelBuilder |
keepAliveTimeout(long keepAliveTimeout,
TimeUnit timeUnit) |
NettyChannelBuilder |
keepAliveWithoutCalls(boolean enable) |
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 |
maxInboundMessageSize(int max)
Sets the maximum message size allowed for a single gRPC frame.
|
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.
|
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 |
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, maxRetryAttempts, maxTraceEvents, nameResolverFactory, offloadExecutor, overrideAuthority, perRpcBufferLimit, proxyDetector, retryBufferSize, setBinaryLog, thisT, toString, userAgent
public static final int DEFAULT_FLOW_CONTROL_WINDOW
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. If an unresolved InetSocketAddress is passed in, then it will remain
unresolved.public static NettyChannelBuilder forAddress(SocketAddress serverAddress, ChannelCredentials creds)
forAddress(String, int, ChannelCredentials)
should generally be preferred over this
method, since that API permits delaying DNS lookups and noticing changes to DNS. If an
unresolved InetSocketAddress is passed in, then it will remain unresolved.public static NettyChannelBuilder forAddress(String host, int port)
public static NettyChannelBuilder forAddress(String host, int port, ChannelCredentials creds)
public static NettyChannelBuilder forTarget(String target)
NameResolver
.public static NettyChannelBuilder forTarget(String target, ChannelCredentials creds)
NameResolver
.@Internal protected ManagedChannelBuilder<?> delegate()
delegate
in class io.grpc.internal.AbstractManagedChannelImplBuilder<NettyChannelBuilder>
@CanIgnoreReturnValue 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.
@CanIgnoreReturnValue 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.
@CanIgnoreReturnValue public <T> NettyChannelBuilder withOption(io.netty.channel.ChannelOption<T> option, T value)
@CanIgnoreReturnValue public NettyChannelBuilder negotiationType(NegotiationType type)
Default: TLS
@CanIgnoreReturnValue 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.
@CanIgnoreReturnValue public NettyChannelBuilder sslContext(io.netty.handler.ssl.SslContext sslContext)
GrpcSslContexts
, but options could have been overridden.@CanIgnoreReturnValue public NettyChannelBuilder initialFlowControlWindow(int initialFlowControlWindow)
flowControlWindow(int)
. By default, auto flow control is enabled with
initial flow control window size of DEFAULT_FLOW_CONTROL_WINDOW
.@CanIgnoreReturnValue public NettyChannelBuilder flowControlWindow(int flowControlWindow)
initialFlowControlWindow(int)
to enable auto flow control tuning. If not
called, the default value is DEFAULT_FLOW_CONTROL_WINDOW
) with auto flow control
tuning.@CanIgnoreReturnValue @Deprecated @InlineMe(replacement="this.maxInboundMetadataSize(maxHeaderListSize)") public NettyChannelBuilder maxHeaderListSize(int maxHeaderListSize)
maxInboundMetadataSize(int)
instead@CanIgnoreReturnValue public NettyChannelBuilder maxInboundMetadataSize(int bytes)
maxInboundMetadataSize
in class io.grpc.internal.AbstractManagedChannelImplBuilder<NettyChannelBuilder>
bytes
- the maximum size of received metadataIllegalArgumentException
- if bytes is non-positive@CanIgnoreReturnValue public NettyChannelBuilder usePlaintext()
negotiationType(NegotiationType)
with PLAINTEXT
.usePlaintext
in class io.grpc.internal.AbstractManagedChannelImplBuilder<NettyChannelBuilder>
@CanIgnoreReturnValue public NettyChannelBuilder useTransportSecurity()
negotiationType(NegotiationType)
with TLS
.useTransportSecurity
in class io.grpc.internal.AbstractManagedChannelImplBuilder<NettyChannelBuilder>
@CanIgnoreReturnValue public NettyChannelBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit)
keepAliveTime
in class io.grpc.internal.AbstractManagedChannelImplBuilder<NettyChannelBuilder>
@CanIgnoreReturnValue public NettyChannelBuilder keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit)
keepAliveTimeout
in class io.grpc.internal.AbstractManagedChannelImplBuilder<NettyChannelBuilder>
@CanIgnoreReturnValue public NettyChannelBuilder keepAliveWithoutCalls(boolean enable)
keepAliveWithoutCalls
in class io.grpc.internal.AbstractManagedChannelImplBuilder<NettyChannelBuilder>
@CanIgnoreReturnValue public NettyChannelBuilder localSocketPicker(@Nullable NettyChannelBuilder.LocalSocketPicker localSocketPicker)
null
, attempts to create connections bound to a local port.@CanIgnoreReturnValue public NettyChannelBuilder maxInboundMessageSize(int max)
maxInboundMessageSize
in class io.grpc.internal.AbstractManagedChannelImplBuilder<NettyChannelBuilder>