@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1784") 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 |
bossEventLoopGroup(EventLoopGroup group)
Provides the boss EventGroupLoop to the server.
|
protected io.grpc.netty.NettyServer |
buildTransportServer(List<io.grpc.ServerStreamTracer.Factory> streamTracerFactories) |
NettyServerBuilder |
channelType(Class<? extends ServerChannel> channelType)
Specify the channel type to use, by default we use
NioServerSocketChannel . |
NettyServerBuilder |
flowControlWindow(int flowControlWindow)
Sets the HTTP/2 flow control window.
|
static NettyServerBuilder |
forAddress(SocketAddress address)
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.
|
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)
Sets the maximum size of header list allowed to be received.
|
NettyServerBuilder |
maxMessageSize(int maxMessageSize)
Sets the maximum message size allowed to be received on the server.
|
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(ProtocolNegotiator protocolNegotiator)
Sets the
ProtocolNegotiator to be used. |
NettyServerBuilder |
sslContext(SslContext sslContext)
Sets the TLS context to use for encryption.
|
NettyServerBuilder |
useTransportSecurity(File certChain,
File privateKey) |
NettyServerBuilder |
workerEventLoopGroup(EventLoopGroup group)
Provides the worker EventGroupLoop to the server.
|
public static final int DEFAULT_FLOW_CONTROL_WINDOW
@CheckReturnValue public static NettyServerBuilder forPort(int port)
port
- the port on which the server is to be bound.@CheckReturnValue public static NettyServerBuilder forAddress(SocketAddress address)
SocketAddress
.address
- the socket address on which the server is to be bound.public NettyServerBuilder channelType(Class<? extends ServerChannel> channelType)
NioServerSocketChannel
.public NettyServerBuilder bossEventLoopGroup(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.
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.
public NettyServerBuilder workerEventLoopGroup(EventLoopGroup group)
It's an optional parameter. If the user has not provided one when the server is built, the builder will create one.
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.
public NettyServerBuilder sslContext(SslContext sslContext)
GrpcSslContexts
, but options could have been overridden.@Internal public final NettyServerBuilder protocolNegotiator(@Nullable ProtocolNegotiator protocolNegotiator)
ProtocolNegotiator
to be used. If non-null
, overrides the value
specified in sslContext(SslContext)
.
Default: null
.
public NettyServerBuilder maxConcurrentCallsPerConnection(int maxCalls)
public NettyServerBuilder flowControlWindow(int flowControlWindow)
DEFAULT_FLOW_CONTROL_WINDOW
).public NettyServerBuilder maxMessageSize(int maxMessageSize)
public NettyServerBuilder maxHeaderListSize(int maxHeaderListSize)
public NettyServerBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit)
Long.MAX_VALUE
nano seconds or an unreasonably
large value will disable keepalive.public NettyServerBuilder keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit)
public NettyServerBuilder maxConnectionIdle(long maxConnectionIdle, TimeUnit timeUnit)
Long.MAX_VALUE
nano seconds or an unreasonably large value will disable
max connection idle.public NettyServerBuilder maxConnectionAge(long maxConnectionAge, TimeUnit timeUnit)
Long.MAX_VALUE
nano seconds or an unreasonably large value will disable
max connection age.public NettyServerBuilder maxConnectionAgeGrace(long maxConnectionAgeGrace, TimeUnit timeUnit)
Long.MAX_VALUE
nano seconds or an
unreasonably large value are considered infinite.maxConnectionAge(long, TimeUnit)
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.
permitKeepAliveWithoutCalls(boolean)
public NettyServerBuilder permitKeepAliveWithoutCalls(boolean permit)
false
.permitKeepAliveTime(long, TimeUnit)
@CheckReturnValue protected io.grpc.netty.NettyServer buildTransportServer(List<io.grpc.ServerStreamTracer.Factory> streamTracerFactories)
buildTransportServer
in class io.grpc.internal.AbstractServerImplBuilder<NettyServerBuilder>
public NettyServerBuilder useTransportSecurity(File certChain, File privateKey)
useTransportSecurity
in class io.grpc.ServerBuilder<NettyServerBuilder>