Class NettyServerBuilder
- java.lang.Object
-
- io.grpc.ServerBuilder<T>
-
- io.grpc.ForwardingServerBuilder<NettyServerBuilder>
-
- io.grpc.netty.NettyServerBuilder
-
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1784") @CheckReturnValue public final class NettyServerBuilder extends ForwardingServerBuilder<NettyServerBuilder>
A builder to help simplify the construction of a Netty-based GRPC server.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classNettyServerBuilder.NettyClientTransportServersBuilder
-
Field Summary
Fields Modifier and Type Field Description private static longAS_LARGE_AS_INFINITEprivate booleanautoFlowControlprivate ObjectPool<? extends io.netty.channel.EventLoopGroup>bossEventLoopGroupPoolprivate io.netty.channel.ChannelFactory<? extends io.netty.channel.ServerChannel>channelFactoryprivate java.util.Map<io.netty.channel.ChannelOption<?>,java.lang.Object>channelOptionsprivate java.util.Map<io.netty.channel.ChannelOption<?>,java.lang.Object>childChannelOptionsprivate static ObjectPool<? extends io.netty.channel.EventLoopGroup>DEFAULT_BOSS_EVENT_LOOP_GROUP_POOLstatic intDEFAULT_FLOW_CONTROL_WINDOWprivate static ObjectPool<? extends io.netty.channel.EventLoopGroup>DEFAULT_WORKER_EVENT_LOOP_GROUP_POOLprivate AttributeseagAttributesprivate intflowControlWindowprivate booleanforceHeapBufferprivate booleanfreezeProtocolNegotiatorFactoryprivate longkeepAliveTimeInNanosprivate longkeepAliveTimeoutInNanosprivate java.util.List<java.net.SocketAddress>listenAddresses(package private) static longMAX_CONNECTION_AGE_GRACE_NANOS_INFINITE(package private) static longMAX_CONNECTION_AGE_NANOS_DISABLED(package private) static longMAX_CONNECTION_IDLE_NANOS_DISABLED(package private) static intMAX_RST_COUNT_DISABLEDprivate intmaxConcurrentCallsPerConnectionprivate longmaxConnectionAgeGraceInNanosprivate longmaxConnectionAgeInNanosprivate longmaxConnectionIdleInNanosprivate intmaxHeaderListSizeprivate intmaxMessageSizeprivate intmaxRstCountprivate longmaxRstPeriodNanosprivate static longMIN_MAX_CONNECTION_AGE_NANOprivate static longMIN_MAX_CONNECTION_IDLE_NANOprivate longpermitKeepAliveTimeInNanosprivate booleanpermitKeepAliveWithoutCallsprivate ProtocolNegotiator.ServerFactoryprotocolNegotiatorFactoryprivate ServerImplBuilderserverImplBuilderprivate TransportTracer.FactorytransportTracerFactoryprivate ObjectPool<? extends io.netty.channel.EventLoopGroup>workerEventLoopGroupPool
-
Constructor Summary
Constructors Modifier Constructor Description privateNettyServerBuilder(java.net.SocketAddress address)(package private)NettyServerBuilder(java.net.SocketAddress address, ProtocolNegotiator.ServerFactory negotiatorFactory)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description NettyServerBuilderaddListenAddress(java.net.SocketAddress listenAddress)Adds an additional address for this server to listen on.(package private) voidassertEventLoopsAndChannelType()NettyServerBuilderbossEventLoopGroup(io.netty.channel.EventLoopGroup group)Provides the boss EventGroupLoop to the server.(package private) NettyServerBuilderbossEventLoopGroupPool(ObjectPool<? extends io.netty.channel.EventLoopGroup> bossEventLoopGroupPool)(package private) NettyServerbuildTransportServers(java.util.List<? extends ServerStreamTracer.Factory> streamTracerFactories)NettyServerBuilderchannelFactory(io.netty.channel.ChannelFactory<? extends io.netty.channel.ServerChannel> channelFactory)Specifies theChannelFactoryto createServerChannelinstances.NettyServerBuilderchannelType(java.lang.Class<? extends io.netty.channel.ServerChannel> channelType)Specifies the channel type to use, by default we useEpollServerSocketChannelif available, otherwise usingNioServerSocketChannel.protected ServerBuilder<?>delegate()Returns the delegatedServerBuilder.(package private) voideagAttributes(Attributes eagAttributes)Sets the EAG attributes available to protocol negotiators.NettyServerBuilderflowControlWindow(int flowControlWindow)Sets the flow control window in bytes.static NettyServerBuilderforAddress(java.net.SocketAddress address)Creates a server builder configured with the givenSocketAddress.static NettyServerBuilderforAddress(java.net.SocketAddress address, ServerCredentials creds)Creates a server builder configured with the givenSocketAddress.static NettyServerBuilderforPort(int port)Creates a server builder that will bind to the given port.static NettyServerBuilderforPort(int port, ServerCredentials creds)Creates a server builder that will bind to the given port.NettyServerBuilderinitialFlowControlWindow(int initialFlowControlWindow)Sets the initial flow control window in bytes.NettyServerBuilderkeepAliveTime(long keepAliveTime, java.util.concurrent.TimeUnit timeUnit)Sets a custom keepalive time, the delay time for sending next keepalive ping.NettyServerBuilderkeepAliveTimeout(long keepAliveTimeout, java.util.concurrent.TimeUnit timeUnit)Sets a custom keepalive timeout, the timeout for keepalive ping requests.NettyServerBuildermaxConcurrentCallsPerConnection(int maxCalls)The maximum number of concurrent calls permitted for each incoming connection.NettyServerBuildermaxConnectionAge(long maxConnectionAge, java.util.concurrent.TimeUnit timeUnit)Sets a custom max connection age, connection lasting longer than which will be gracefully terminated.NettyServerBuildermaxConnectionAgeGrace(long maxConnectionAgeGrace, java.util.concurrent.TimeUnit timeUnit)Sets a custom grace time for the graceful connection termination.NettyServerBuildermaxConnectionIdle(long maxConnectionIdle, java.util.concurrent.TimeUnit timeUnit)Sets a custom max connection idle time, connection being idle for longer than which will be gracefully terminated.NettyServerBuildermaxHeaderListSize(int maxHeaderListSize)Deprecated.UsemaxInboundMetadataSize(int)insteadNettyServerBuildermaxInboundMessageSize(int bytes)Sets the maximum message size allowed to be received on the server.NettyServerBuildermaxInboundMetadataSize(int bytes)Sets the maximum size of metadata allowed to be received.NettyServerBuildermaxMessageSize(int maxMessageSize)Deprecated.CallmaxInboundMessageSize(int)instead.NettyServerBuildermaxRstFramesPerWindow(int maxRstStream, int secondsPerWindow)Limits the rate of incoming RST_STREAM frames per connection to maxRstStream per secondsPerWindow.NettyServerBuilderpermitKeepAliveTime(long keepAliveTime, java.util.concurrent.TimeUnit timeUnit)Specify the most aggressive keep-alive time clients are permitted to configure.NettyServerBuilderpermitKeepAliveWithoutCalls(boolean permit)Sets whether to allow clients to send keep-alive HTTP/2 PINGs even if there are no outstanding RPCs on the connection.NettyServerBuilderprotocolNegotiator(ProtocolNegotiator protocolNegotiator)Sets theProtocolNegotiatorto be used.(package private) voidsetForceHeapBuffer(boolean value)Force using heap buffer when custom allocator is enabled.(package private) voidsetStatsEnabled(boolean value)(package private) voidsetStatsRecordRealTimeMetrics(boolean value)(package private) voidsetStatsRecordStartedRpcs(boolean value)(package private) voidsetTracingEnabled(boolean value)(package private) NettyServerBuildersetTransportTracerFactory(TransportTracer.Factory transportTracerFactory)NettyServerBuildersslContext(io.netty.handler.ssl.SslContext sslContext)Sets the TLS context to use for encryption.NettyServerBuilderuseTransportSecurity(java.io.File certChain, java.io.File privateKey)Makes the server use TLS.NettyServerBuilderuseTransportSecurity(java.io.InputStream certChain, java.io.InputStream privateKey)Makes the server use TLS.<T> NettyServerBuilderwithChildOption(io.netty.channel.ChannelOption<T> option, T value)Specifies a child channel option.<T> NettyServerBuilderwithOption(io.netty.channel.ChannelOption<T> option, T value)Specifies a channel option.NettyServerBuilderworkerEventLoopGroup(io.netty.channel.EventLoopGroup group)Provides the worker EventGroupLoop to the server.(package private) NettyServerBuilderworkerEventLoopGroupPool(ObjectPool<? extends io.netty.channel.EventLoopGroup> workerEventLoopGroupPool)-
Methods inherited from class io.grpc.ForwardingServerBuilder
addService, addService, addStreamTracerFactory, addTransportFilter, build, callExecutor, compressorRegistry, decompressorRegistry, directExecutor, executor, fallbackHandlerRegistry, handshakeTimeout, intercept, setBinaryLog, toString
-
Methods inherited from class io.grpc.ServerBuilder
addServices
-
-
-
-
Field Detail
-
DEFAULT_FLOW_CONTROL_WINDOW
public static final int DEFAULT_FLOW_CONTROL_WINDOW
- See Also:
- Constant Field Values
-
MAX_CONNECTION_IDLE_NANOS_DISABLED
static final long MAX_CONNECTION_IDLE_NANOS_DISABLED
- See Also:
- Constant Field Values
-
MAX_CONNECTION_AGE_NANOS_DISABLED
static final long MAX_CONNECTION_AGE_NANOS_DISABLED
- See Also:
- Constant Field Values
-
MAX_CONNECTION_AGE_GRACE_NANOS_INFINITE
static final long MAX_CONNECTION_AGE_GRACE_NANOS_INFINITE
- See Also:
- Constant Field Values
-
MAX_RST_COUNT_DISABLED
static final int MAX_RST_COUNT_DISABLED
- See Also:
- Constant Field Values
-
MIN_MAX_CONNECTION_IDLE_NANO
private static final long MIN_MAX_CONNECTION_IDLE_NANO
-
MIN_MAX_CONNECTION_AGE_NANO
private static final long MIN_MAX_CONNECTION_AGE_NANO
-
AS_LARGE_AS_INFINITE
private static final long AS_LARGE_AS_INFINITE
-
DEFAULT_BOSS_EVENT_LOOP_GROUP_POOL
private static final ObjectPool<? extends io.netty.channel.EventLoopGroup> DEFAULT_BOSS_EVENT_LOOP_GROUP_POOL
-
DEFAULT_WORKER_EVENT_LOOP_GROUP_POOL
private static final ObjectPool<? extends io.netty.channel.EventLoopGroup> DEFAULT_WORKER_EVENT_LOOP_GROUP_POOL
-
serverImplBuilder
private final ServerImplBuilder serverImplBuilder
-
listenAddresses
private final java.util.List<java.net.SocketAddress> listenAddresses
-
transportTracerFactory
private TransportTracer.Factory transportTracerFactory
-
channelFactory
private io.netty.channel.ChannelFactory<? extends io.netty.channel.ServerChannel> channelFactory
-
channelOptions
private final java.util.Map<io.netty.channel.ChannelOption<?>,java.lang.Object> channelOptions
-
childChannelOptions
private final java.util.Map<io.netty.channel.ChannelOption<?>,java.lang.Object> childChannelOptions
-
bossEventLoopGroupPool
private ObjectPool<? extends io.netty.channel.EventLoopGroup> bossEventLoopGroupPool
-
workerEventLoopGroupPool
private ObjectPool<? extends io.netty.channel.EventLoopGroup> workerEventLoopGroupPool
-
forceHeapBuffer
private boolean forceHeapBuffer
-
protocolNegotiatorFactory
private ProtocolNegotiator.ServerFactory protocolNegotiatorFactory
-
freezeProtocolNegotiatorFactory
private final boolean freezeProtocolNegotiatorFactory
-
maxConcurrentCallsPerConnection
private int maxConcurrentCallsPerConnection
-
autoFlowControl
private boolean autoFlowControl
-
flowControlWindow
private int flowControlWindow
-
maxMessageSize
private int maxMessageSize
-
maxHeaderListSize
private int maxHeaderListSize
-
keepAliveTimeInNanos
private long keepAliveTimeInNanos
-
keepAliveTimeoutInNanos
private long keepAliveTimeoutInNanos
-
maxConnectionIdleInNanos
private long maxConnectionIdleInNanos
-
maxConnectionAgeInNanos
private long maxConnectionAgeInNanos
-
maxConnectionAgeGraceInNanos
private long maxConnectionAgeGraceInNanos
-
permitKeepAliveWithoutCalls
private boolean permitKeepAliveWithoutCalls
-
permitKeepAliveTimeInNanos
private long permitKeepAliveTimeInNanos
-
maxRstCount
private int maxRstCount
-
maxRstPeriodNanos
private long maxRstPeriodNanos
-
eagAttributes
private Attributes eagAttributes
-
-
Constructor Detail
-
NettyServerBuilder
private NettyServerBuilder(java.net.SocketAddress address)
-
NettyServerBuilder
NettyServerBuilder(java.net.SocketAddress address, ProtocolNegotiator.ServerFactory negotiatorFactory)
-
-
Method Detail
-
forPort
public static NettyServerBuilder forPort(int port)
Creates a server builder that will bind to the given port.- Parameters:
port- the port on which the server is to be bound.- Returns:
- the server builder.
-
forPort
public static NettyServerBuilder forPort(int port, ServerCredentials creds)
Creates a server builder that will bind to the given port.- Parameters:
port- the port on which the server is to be bound.- Returns:
- the server builder.
-
forAddress
public static NettyServerBuilder forAddress(java.net.SocketAddress address)
Creates a server builder configured with the givenSocketAddress.- Parameters:
address- the socket address on which the server is to be bound.- Returns:
- the server builder
-
forAddress
public static NettyServerBuilder forAddress(java.net.SocketAddress address, ServerCredentials creds)
Creates a server builder configured with the givenSocketAddress.- Parameters:
address- the socket address on which the server is to be bound.- Returns:
- the server builder
-
delegate
@Internal protected ServerBuilder<?> delegate()
Description copied from class:ForwardingServerBuilderReturns the delegatedServerBuilder.- Specified by:
delegatein classForwardingServerBuilder<NettyServerBuilder>
-
addListenAddress
@CanIgnoreReturnValue public NettyServerBuilder addListenAddress(java.net.SocketAddress listenAddress)
Adds an additional address for this server to listen on. Callers must ensure that all socket addresses are compatible with the Netty channel type, and that they don't conflict with each other.
-
channelType
@CanIgnoreReturnValue public NettyServerBuilder channelType(java.lang.Class<? extends io.netty.channel.ServerChannel> channelType)
Specifies the channel type to use, by default we useEpollServerSocketChannelif available, otherwise usingNioServerSocketChannel.You either use this or
channelFactory(io.netty.channel.ChannelFactory)if yourServerChannelimplementation 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
EventLoopGroupusingworkerEventLoopGroup(EventLoopGroup)andbossEventLoopGroup(EventLoopGroup). For example,NioServerSocketChannelmust useNioEventLoopGroup, otherwise your server won't start.
-
channelFactory
@CanIgnoreReturnValue public NettyServerBuilder channelFactory(io.netty.channel.ChannelFactory<? extends io.netty.channel.ServerChannel> channelFactory)
Specifies theChannelFactoryto createServerChannelinstances. This method is usually only used if the specificServerChannelrequires complex logic which requires additional information to create theServerChannel. Otherwise, recommend to usechannelType(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
EventLoopGroupusingworkerEventLoopGroup(EventLoopGroup)andbossEventLoopGroup(EventLoopGroup). For example, if the factory createsNioServerSocketChannelyou must useNioEventLoopGroup, otherwise your server won't start.
-
withOption
@CanIgnoreReturnValue public <T> NettyServerBuilder withOption(io.netty.channel.ChannelOption<T> option, T value)
Specifies a channel option. As the underlying channel as well as network implementation may ignore this value applications should consider it a hint.- Since:
- 1.30.0
-
withChildOption
@CanIgnoreReturnValue public <T> NettyServerBuilder withChildOption(io.netty.channel.ChannelOption<T> option, T value)
Specifies a child channel option. As the underlying channel as well as network implementation may ignore this value applications should consider it a hint.- Since:
- 1.9.0
-
bossEventLoopGroup
@CanIgnoreReturnValue public NettyServerBuilder bossEventLoopGroup(io.netty.channel.EventLoopGroup group)
Provides the boss EventGroupLoop to the server.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
Channeltype usingchannelType(Class)andworkerEventLoopGroup(EventLoopGroup). For example,NioServerSocketChannelmust useNioEventLoopGroupfor both boss and workerEventLoopGroup, 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
Threads by default and thus aServerwill continue to run even after the main thread has terminated. However, users have to be cautious when providing their ownEventLoopGroups. For example, Netty'sEventLoopGroups 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 callServer.awaitTermination()to keep the main thread alive until the server has terminated.
-
bossEventLoopGroupPool
@CanIgnoreReturnValue NettyServerBuilder bossEventLoopGroupPool(ObjectPool<? extends io.netty.channel.EventLoopGroup> bossEventLoopGroupPool)
-
workerEventLoopGroup
@CanIgnoreReturnValue public NettyServerBuilder workerEventLoopGroup(io.netty.channel.EventLoopGroup group)
Provides the worker EventGroupLoop to the server.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
Channeltype usingchannelType(Class)andbossEventLoopGroup(EventLoopGroup). For example,NioServerSocketChannelmust useNioEventLoopGroupfor both boss and workerEventLoopGroup, 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
Threads by default and thus aServerwill continue to run even after the main thread has terminated. However, users have to be cautious when providing their ownEventLoopGroups. For example, Netty'sEventLoopGroups 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 callServer.awaitTermination()to keep the main thread alive until the server has terminated.
-
workerEventLoopGroupPool
@CanIgnoreReturnValue NettyServerBuilder workerEventLoopGroupPool(ObjectPool<? extends io.netty.channel.EventLoopGroup> workerEventLoopGroupPool)
-
setForceHeapBuffer
void setForceHeapBuffer(boolean value)
Force using heap buffer when custom allocator is enabled.
-
sslContext
@CanIgnoreReturnValue public NettyServerBuilder sslContext(io.netty.handler.ssl.SslContext sslContext)
Sets the TLS context to use for encryption. Providing a context enables encryption. It must have been configured withGrpcSslContexts, but options could have been overridden.
-
protocolNegotiator
@CanIgnoreReturnValue @Internal public final NettyServerBuilder protocolNegotiator(ProtocolNegotiator protocolNegotiator)
Sets theProtocolNegotiatorto be used. Overrides the value specified insslContext(SslContext).
-
setTracingEnabled
void setTracingEnabled(boolean value)
-
setStatsEnabled
void setStatsEnabled(boolean value)
-
setStatsRecordStartedRpcs
void setStatsRecordStartedRpcs(boolean value)
-
setStatsRecordRealTimeMetrics
void setStatsRecordRealTimeMetrics(boolean value)
-
maxConcurrentCallsPerConnection
@CanIgnoreReturnValue public NettyServerBuilder maxConcurrentCallsPerConnection(int maxCalls)
The maximum number of concurrent calls permitted for each incoming connection. Defaults to no limit.
-
initialFlowControlWindow
@CanIgnoreReturnValue public NettyServerBuilder initialFlowControlWindow(int initialFlowControlWindow)
Sets the initial flow control window in bytes. Setting initial flow control window enables auto flow control tuning using bandwidth-delay product algorithm. To disable auto flow control tuning, useflowControlWindow(int). By default, auto flow control is enabled with initial flow control window size ofDEFAULT_FLOW_CONTROL_WINDOW.
-
flowControlWindow
@CanIgnoreReturnValue public NettyServerBuilder flowControlWindow(int flowControlWindow)
Sets the flow control window in bytes. Setting flowControlWindow disables auto flow control tuning; useinitialFlowControlWindow(int)to enable auto flow control tuning. If not called, the default value isDEFAULT_FLOW_CONTROL_WINDOW) with auto flow control tuning.
-
maxMessageSize
@CanIgnoreReturnValue @Deprecated @InlineMe(replacement="this.maxInboundMessageSize(maxMessageSize)") public NettyServerBuilder maxMessageSize(int maxMessageSize)
Deprecated.CallmaxInboundMessageSize(int)instead. This method will be removed in a future release.Sets the maximum message size allowed to be received on the server. If not called, defaults to 4 MiB. The default provides protection to services who haven't considered the possibility of receiving large messages while trying to be large enough to not be hit in normal usage.
-
maxInboundMessageSize
@CanIgnoreReturnValue public NettyServerBuilder maxInboundMessageSize(int bytes)
Sets the maximum message size allowed to be received on the server. If not called, defaults to 4 MiB. The default provides protection to servers who haven't considered the possibility of receiving large messages while trying to be large enough to not be hit in normal usage.This method is advisory, and implementations may decide to not enforce this. Currently, the only known transport to not enforce this is
InProcessServer.- Overrides:
maxInboundMessageSizein classForwardingServerBuilder<NettyServerBuilder>- Parameters:
bytes- the maximum number of bytes a single message can be.- Returns:
- this
-
maxHeaderListSize
@CanIgnoreReturnValue @Deprecated @InlineMe(replacement="this.maxInboundMetadataSize(maxHeaderListSize)") public NettyServerBuilder maxHeaderListSize(int maxHeaderListSize)
Deprecated.UsemaxInboundMetadataSize(int)insteadSets the maximum size of header list allowed to be received. This is cumulative size of the headers with some overhead, as defined for HTTP/2's SETTINGS_MAX_HEADER_LIST_SIZE. The default is 8 KiB.
-
maxInboundMetadataSize
@CanIgnoreReturnValue public NettyServerBuilder maxInboundMetadataSize(int bytes)
Sets the maximum size of metadata allowed to be received. This is cumulative size of the entries with some overhead, as defined for HTTP/2's SETTINGS_MAX_HEADER_LIST_SIZE. The default is 8 KiB.- Overrides:
maxInboundMetadataSizein classForwardingServerBuilder<NettyServerBuilder>- Parameters:
bytes- the maximum size of received metadata- Returns:
- this
- Throws:
java.lang.IllegalArgumentException- if bytes is non-positive- Since:
- 1.17.0
-
keepAliveTime
@CanIgnoreReturnValue public NettyServerBuilder keepAliveTime(long keepAliveTime, java.util.concurrent.TimeUnit timeUnit)
Sets a custom keepalive time, the delay time for sending next keepalive ping. An unreasonably small value might be increased, andLong.MAX_VALUEnano seconds or an unreasonably large value will disable keepalive.- Overrides:
keepAliveTimein classForwardingServerBuilder<NettyServerBuilder>- Since:
- 1.3.0
- See Also:
- gRFC A9 Server-side Connection Management
-
keepAliveTimeout
@CanIgnoreReturnValue public NettyServerBuilder keepAliveTimeout(long keepAliveTimeout, java.util.concurrent.TimeUnit timeUnit)
Sets a custom keepalive timeout, the timeout for keepalive ping requests. An unreasonably small value might be increased.- Overrides:
keepAliveTimeoutin classForwardingServerBuilder<NettyServerBuilder>- Since:
- 1.3.0
- See Also:
- gRFC A9 Server-side Connection Management
-
maxConnectionIdle
@CanIgnoreReturnValue public NettyServerBuilder maxConnectionIdle(long maxConnectionIdle, java.util.concurrent.TimeUnit timeUnit)
Sets a custom max connection idle time, connection being idle for longer than which will be gracefully terminated. Idleness duration is defined since the most recent time the number of outstanding RPCs became zero or the connection establishment. An unreasonably small value might be increased.Long.MAX_VALUEnano seconds or an unreasonably large value will disable max connection idle.- Overrides:
maxConnectionIdlein classForwardingServerBuilder<NettyServerBuilder>- Since:
- 1.4.0
- See Also:
- gRFC A9 Server-side Connection Management
-
maxConnectionAge
@CanIgnoreReturnValue public NettyServerBuilder maxConnectionAge(long maxConnectionAge, java.util.concurrent.TimeUnit timeUnit)
Sets a custom max connection age, connection lasting longer than which will be gracefully terminated. An unreasonably small value might be increased. A random jitter of +/-10% will be added to it.Long.MAX_VALUEnano seconds or an unreasonably large value will disable max connection age.- Overrides:
maxConnectionAgein classForwardingServerBuilder<NettyServerBuilder>- Since:
- 1.3.0
- See Also:
- gRFC A9 Server-side Connection Management
-
maxConnectionAgeGrace
@CanIgnoreReturnValue public NettyServerBuilder maxConnectionAgeGrace(long maxConnectionAgeGrace, java.util.concurrent.TimeUnit timeUnit)
Sets a custom grace time for the graceful connection termination. Once the max connection age is reached, RPCs have the grace time to complete. RPCs that do not complete in time will be cancelled, allowing the connection to terminate.Long.MAX_VALUEnano seconds or an unreasonably large value are considered infinite.- Overrides:
maxConnectionAgeGracein classForwardingServerBuilder<NettyServerBuilder>- Since:
- 1.3.0
- See Also:
maxConnectionAge(long, TimeUnit)
-
permitKeepAliveTime
@CanIgnoreReturnValue public NettyServerBuilder permitKeepAliveTime(long keepAliveTime, java.util.concurrent.TimeUnit timeUnit)
Specify the most aggressive keep-alive time clients are permitted to configure. The server will try to detect clients exceeding this rate and when detected will forcefully close the connection. The default is 5 minutes.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.
- Overrides:
permitKeepAliveTimein classForwardingServerBuilder<NettyServerBuilder>- Since:
- 1.3.0
- See Also:
permitKeepAliveWithoutCalls(boolean)
-
permitKeepAliveWithoutCalls
@CanIgnoreReturnValue public 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. Defaults tofalse.- Overrides:
permitKeepAliveWithoutCallsin classForwardingServerBuilder<NettyServerBuilder>- Since:
- 1.3.0
- See Also:
permitKeepAliveTime(long, TimeUnit)
-
maxRstFramesPerWindow
@CanIgnoreReturnValue public NettyServerBuilder maxRstFramesPerWindow(int maxRstStream, int secondsPerWindow)
Limits the rate of incoming RST_STREAM frames per connection to maxRstStream per secondsPerWindow. When exceeded on a connection, the connection is closed. This can reduce the impact of an attacker continually resetting RPCs before they complete, when combined with TLS andmaxConcurrentCallsPerConnection(int).gRPC clients send RST_STREAM when they cancel RPCs, so some RST_STREAMs are normal and setting this too low can cause errors for legimitate clients.
By default there is no limit.
- Parameters:
maxRstStream- the positive limit of RST_STREAM frames per connection per period, orInteger.MAX_VALUEfor unlimitedsecondsPerWindow- the positive number of seconds per period
-
eagAttributes
void eagAttributes(Attributes eagAttributes)
Sets the EAG attributes available to protocol negotiators. Not for general use.
-
buildTransportServers
NettyServer buildTransportServers(java.util.List<? extends ServerStreamTracer.Factory> streamTracerFactories)
-
assertEventLoopsAndChannelType
void assertEventLoopsAndChannelType()
-
setTransportTracerFactory
@CanIgnoreReturnValue NettyServerBuilder setTransportTracerFactory(TransportTracer.Factory transportTracerFactory)
-
useTransportSecurity
@CanIgnoreReturnValue public NettyServerBuilder useTransportSecurity(java.io.File certChain, java.io.File privateKey)
Description copied from class:ServerBuilderMakes the server use TLS.- Overrides:
useTransportSecurityin classForwardingServerBuilder<NettyServerBuilder>- Parameters:
certChain- file containing the full certificate chainprivateKey- file containing the private key- Returns:
- this
-
useTransportSecurity
@CanIgnoreReturnValue public NettyServerBuilder useTransportSecurity(java.io.InputStream certChain, java.io.InputStream privateKey)
Description copied from class:ServerBuilderMakes the server use TLS.- Overrides:
useTransportSecurityin classForwardingServerBuilder<NettyServerBuilder>- Parameters:
certChain- InputStream containing the full certificate chainprivateKey- InputStream containing the private key- Returns:
- this
-
-