@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1784") @CheckReturnValue public final class NettyServerBuilder extends io.grpc.internal.AbstractServerImplBuilder<NettyServerBuilder>
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_FLOW_CONTROL_WINDOW |
Modifier and Type | Method and Description |
---|---|
NettyServerBuilder |
addListenAddress(SocketAddress listenAddress)
Adds an additional address for this server to listen on.
|
NettyServerBuilder |
bossEventLoopGroup(io.netty.channel.EventLoopGroup group)
Provides the boss EventGroupLoop to the server.
|
NettyServerBuilder |
channelFactory(io.netty.channel.ChannelFactory<? extends io.netty.channel.ServerChannel> channelFactory)
Specifies the
ChannelFactory to create ServerChannel instances. |
NettyServerBuilder |
channelType(Class<? extends io.netty.channel.ServerChannel> channelType)
Specifies the channel type to use, by default we use
EpollServerSocketChannel if
available, otherwise using NioServerSocketChannel . |
protected io.grpc.ServerBuilder<?> |
delegate() |
NettyServerBuilder |
flowControlWindow(int flowControlWindow)
Sets the flow control window in bytes.
|
static NettyServerBuilder |
forAddress(SocketAddress address)
Creates a server builder configured with the given
SocketAddress . |
static NettyServerBuilder |
forAddress(SocketAddress address,
io.grpc.ServerCredentials creds)
Creates a server builder configured with the given
SocketAddress . |
static NettyServerBuilder |
forPort(int port)
Creates a server builder that will bind to the given port.
|
static NettyServerBuilder |
forPort(int port,
io.grpc.ServerCredentials creds)
Creates a server builder that will bind to the given port.
|
NettyServerBuilder |
initialFlowControlWindow(int initialFlowControlWindow)
Sets the initial flow control window in bytes.
|
NettyServerBuilder |
keepAliveTime(long keepAliveTime,
TimeUnit timeUnit)
Sets a custom keepalive time, the delay time for sending next keepalive ping.
|
NettyServerBuilder |
keepAliveTimeout(long keepAliveTimeout,
TimeUnit timeUnit)
Sets a custom keepalive timeout, the timeout for keepalive ping requests.
|
NettyServerBuilder |
maxConcurrentCallsPerConnection(int maxCalls)
The maximum number of concurrent calls permitted for each incoming connection.
|
NettyServerBuilder |
maxConnectionAge(long maxConnectionAge,
TimeUnit timeUnit)
Sets a custom max connection age, connection lasting longer than which will be gracefully
terminated.
|
NettyServerBuilder |
maxConnectionAgeGrace(long maxConnectionAgeGrace,
TimeUnit timeUnit)
Sets a custom grace time for the graceful connection termination.
|
NettyServerBuilder |
maxConnectionIdle(long maxConnectionIdle,
TimeUnit timeUnit)
Sets a custom max connection idle time, connection being idle for longer than which will be
gracefully terminated.
|
NettyServerBuilder |
maxHeaderListSize(int maxHeaderListSize)
Deprecated.
Use
maxInboundMetadataSize(int) instead |
NettyServerBuilder |
maxInboundMessageSize(int bytes) |
NettyServerBuilder |
maxInboundMetadataSize(int bytes)
Sets the maximum size of metadata allowed to be received.
|
NettyServerBuilder |
maxMessageSize(int maxMessageSize)
Deprecated.
Call
maxInboundMessageSize(int) instead. This method will be removed in a
future release. |
NettyServerBuilder |
permitKeepAliveTime(long keepAliveTime,
TimeUnit timeUnit)
Specify the most aggressive keep-alive time clients are permitted to configure.
|
NettyServerBuilder |
permitKeepAliveWithoutCalls(boolean permit)
Sets whether to allow clients to send keep-alive HTTP/2 PINGs even if there are no outstanding
RPCs on the connection.
|
NettyServerBuilder |
protocolNegotiator(io.grpc.netty.ProtocolNegotiator protocolNegotiator)
Sets the
ProtocolNegotiator to be used. |
NettyServerBuilder |
sslContext(io.netty.handler.ssl.SslContext sslContext)
Sets the TLS context to use for encryption.
|
NettyServerBuilder |
useTransportSecurity(File certChain,
File privateKey) |
NettyServerBuilder |
useTransportSecurity(InputStream certChain,
InputStream privateKey) |
<T> NettyServerBuilder |
withChildOption(io.netty.channel.ChannelOption<T> option,
T value)
Specifies a child channel option.
|
<T> NettyServerBuilder |
withOption(io.netty.channel.ChannelOption<T> option,
T value)
Specifies a channel option.
|
NettyServerBuilder |
workerEventLoopGroup(io.netty.channel.EventLoopGroup group)
Provides the worker EventGroupLoop to the server.
|
addService, addService, addStreamTracerFactory, addTransportFilter, build, callExecutor, compressorRegistry, decompressorRegistry, directExecutor, executor, fallbackHandlerRegistry, handshakeTimeout, intercept, setBinaryLog, thisT, toString
public static final int DEFAULT_FLOW_CONTROL_WINDOW
public static NettyServerBuilder forPort(int port)
port
- the port on which the server is to be bound.public static NettyServerBuilder forPort(int port, io.grpc.ServerCredentials creds)
port
- the port on which the server is to be bound.public static NettyServerBuilder forAddress(SocketAddress address)
SocketAddress
.address
- the socket address on which the server is to be bound.public static NettyServerBuilder forAddress(SocketAddress address, io.grpc.ServerCredentials creds)
SocketAddress
.address
- the socket address on which the server is to be bound.@Internal protected io.grpc.ServerBuilder<?> delegate()
delegate
in class io.grpc.internal.AbstractServerImplBuilder<NettyServerBuilder>
@CanIgnoreReturnValue public NettyServerBuilder addListenAddress(SocketAddress listenAddress)
@CanIgnoreReturnValue public NettyServerBuilder channelType(Class<? extends io.netty.channel.ServerChannel> channelType)
EpollServerSocketChannel
if
available, otherwise using NioServerSocketChannel
.
You either use this or channelFactory(io.netty.channel.ChannelFactory)
if your
ServerChannel
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
using workerEventLoopGroup(EventLoopGroup)
and bossEventLoopGroup(EventLoopGroup)
. For
example, NioServerSocketChannel
must use NioEventLoopGroup
, otherwise your server won't start.
@CanIgnoreReturnValue public NettyServerBuilder channelFactory(io.netty.channel.ChannelFactory<? extends io.netty.channel.ServerChannel> channelFactory)
ChannelFactory
to create ServerChannel
instances. This method is
usually only used if the specific ServerChannel
requires complex logic which requires
additional information to create the ServerChannel
. 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
using workerEventLoopGroup(EventLoopGroup)
and bossEventLoopGroup(EventLoopGroup)
. For
example, if the factory creates NioServerSocketChannel
you must use NioEventLoopGroup
, otherwise your server won't start.
@CanIgnoreReturnValue public <T> NettyServerBuilder withOption(io.netty.channel.ChannelOption<T> option, T value)
@CanIgnoreReturnValue public <T> NettyServerBuilder withChildOption(io.netty.channel.ChannelOption<T> option, T value)
@CanIgnoreReturnValue public NettyServerBuilder bossEventLoopGroup(io.netty.channel.EventLoopGroup group)
It's an optional parameter. If the user has not provided one when the server is built, the builder will use the default one which is static.
You must also provide corresponding Channel
type using channelType(Class)
and workerEventLoopGroup(EventLoopGroup)
. For example, NioServerSocketChannel
must use NioEventLoopGroup
for both boss
and worker EventLoopGroup
, otherwise your server won't start.
The server won't take ownership of the given EventLoopGroup. It's caller's responsibility to shut it down when it's desired.
Grpc uses non-daemon Thread
s by default and thus a Server
will
continue to run even after the main thread has terminated. However, users have to be cautious
when providing their own EventLoopGroup
s.
For example, Netty's EventLoopGroup
s use daemon threads by default
and thus an application with only daemon threads running besides the main thread will exit as
soon as the main thread completes.
A simple solution to this problem is to call Server.awaitTermination()
to
keep the main thread alive until the server has terminated.
@CanIgnoreReturnValue public NettyServerBuilder workerEventLoopGroup(io.netty.channel.EventLoopGroup group)
It's an optional parameter. If the user has not provided one when the server is built, the builder will create one.
You must also provide corresponding Channel
type using channelType(Class)
and bossEventLoopGroup(EventLoopGroup)
. For example, NioServerSocketChannel
must use NioEventLoopGroup
for both boss
and worker EventLoopGroup
, otherwise your server won't start.
The server won't take ownership of the given EventLoopGroup. It's caller's responsibility to shut it down when it's desired.
Grpc uses non-daemon Thread
s by default and thus a Server
will
continue to run even after the main thread has terminated. However, users have to be cautious
when providing their own EventLoopGroup
s.
For example, Netty's EventLoopGroup
s use daemon threads by default
and thus an application with only daemon threads running besides the main thread will exit as
soon as the main thread completes.
A simple solution to this problem is to call Server.awaitTermination()
to
keep the main thread alive until the server has terminated.
@CanIgnoreReturnValue public NettyServerBuilder sslContext(io.netty.handler.ssl.SslContext sslContext)
GrpcSslContexts
, but options could have been overridden.@CanIgnoreReturnValue @Internal public final NettyServerBuilder protocolNegotiator(io.grpc.netty.ProtocolNegotiator protocolNegotiator)
ProtocolNegotiator
to be used. Overrides the value specified in sslContext(SslContext)
.@CanIgnoreReturnValue public NettyServerBuilder maxConcurrentCallsPerConnection(int maxCalls)
@CanIgnoreReturnValue public NettyServerBuilder 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 NettyServerBuilder 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.maxInboundMessageSize(maxMessageSize)") public NettyServerBuilder maxMessageSize(int maxMessageSize)
maxInboundMessageSize(int)
instead. This method will be removed in a
future release.@CanIgnoreReturnValue public NettyServerBuilder maxInboundMessageSize(int bytes)
maxInboundMessageSize
in class io.grpc.internal.AbstractServerImplBuilder<NettyServerBuilder>
@CanIgnoreReturnValue @Deprecated @InlineMe(replacement="this.maxInboundMetadataSize(maxHeaderListSize)") public NettyServerBuilder maxHeaderListSize(int maxHeaderListSize)
maxInboundMetadataSize(int)
instead@CanIgnoreReturnValue public NettyServerBuilder maxInboundMetadataSize(int bytes)
maxInboundMetadataSize
in class io.grpc.internal.AbstractServerImplBuilder<NettyServerBuilder>
bytes
- the maximum size of received metadataIllegalArgumentException
- if bytes is non-positive@CanIgnoreReturnValue public NettyServerBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit)
Long.MAX_VALUE
nano seconds or an unreasonably
large value will disable keepalive.keepAliveTime
in class io.grpc.internal.AbstractServerImplBuilder<NettyServerBuilder>
@CanIgnoreReturnValue public NettyServerBuilder keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit)
keepAliveTimeout
in class io.grpc.internal.AbstractServerImplBuilder<NettyServerBuilder>
@CanIgnoreReturnValue public NettyServerBuilder maxConnectionIdle(long maxConnectionIdle, TimeUnit timeUnit)
Long.MAX_VALUE
nano seconds or an unreasonably large value will disable
max connection idle.maxConnectionIdle
in class io.grpc.internal.AbstractServerImplBuilder<NettyServerBuilder>
@CanIgnoreReturnValue public NettyServerBuilder maxConnectionAge(long maxConnectionAge, TimeUnit timeUnit)
Long.MAX_VALUE
nano seconds or an unreasonably large value will disable
max connection age.maxConnectionAge
in class io.grpc.internal.AbstractServerImplBuilder<NettyServerBuilder>
@CanIgnoreReturnValue public NettyServerBuilder maxConnectionAgeGrace(long maxConnectionAgeGrace, TimeUnit timeUnit)
Long.MAX_VALUE
nano seconds or an
unreasonably large value are considered infinite.maxConnectionAgeGrace
in class io.grpc.internal.AbstractServerImplBuilder<NettyServerBuilder>
maxConnectionAge(long, TimeUnit)
@CanIgnoreReturnValue public NettyServerBuilder permitKeepAliveTime(long keepAliveTime, TimeUnit timeUnit)
Even though a default is defined that allows some keep-alives, clients must not use keep-alive without approval from the service owner. Otherwise, they may experience failures in the future if the service becomes more restrictive. When unthrottled, keep-alives can cause a significant amount of traffic and CPU usage, so clients and servers should be conservative in what they use and accept.
permitKeepAliveTime
in class io.grpc.internal.AbstractServerImplBuilder<NettyServerBuilder>
permitKeepAliveWithoutCalls(boolean)
@CanIgnoreReturnValue public NettyServerBuilder permitKeepAliveWithoutCalls(boolean permit)
false
.permitKeepAliveWithoutCalls
in class io.grpc.internal.AbstractServerImplBuilder<NettyServerBuilder>
permitKeepAliveTime(long, TimeUnit)
@CanIgnoreReturnValue public NettyServerBuilder useTransportSecurity(File certChain, File privateKey)
useTransportSecurity
in class io.grpc.internal.AbstractServerImplBuilder<NettyServerBuilder>
@CanIgnoreReturnValue public NettyServerBuilder useTransportSecurity(InputStream certChain, InputStream privateKey)
useTransportSecurity
in class io.grpc.internal.AbstractServerImplBuilder<NettyServerBuilder>