Class NettyChannelBuilder
- java.lang.Object
-
- io.grpc.ManagedChannelBuilder<T>
-
- io.grpc.ForwardingChannelBuilder2<NettyChannelBuilder>
-
- io.grpc.netty.NettyChannelBuilder
-
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1784") @CheckReturnValue public final class NettyChannelBuilder extends io.grpc.ForwardingChannelBuilder2<NettyChannelBuilder>A builder to help simplify construction of channels using the Netty transport.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNettyChannelBuilder.LocalSocketPickerThis class is meant to be overriden with a custom implementation ofNettyChannelBuilder.LocalSocketPicker.createSocketAddress(java.net.SocketAddress, io.grpc.Attributes).
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_FLOW_CONTROL_WINDOW
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description NettyChannelBuilderchannelFactory(ChannelFactory<? extends Channel> channelFactory)Specifies theChannelFactoryto createChannelinstances.NettyChannelBuilderchannelFactory(ChannelFactory<? extends Channel> channelFactory, Class<? extends SocketAddress> transportSocketType)Similar tochannelFactory(ChannelFactory)above but allows the caller to specify the socket-type associated with the channelFactory.NettyChannelBuilderchannelType(Class<? extends Channel> channelType)Specifies the channel type to use, by default we useEpollSocketChannelif available, otherwise usingNioSocketChannel.NettyChannelBuilderchannelType(Class<? extends Channel> channelType, Class<? extends SocketAddress> transportSocketType)Similar tochannelType(Class)above but allows the caller to specify the socket-type associated with the channelType.protected io.grpc.ManagedChannelBuilder<?>delegate()NettyChannelBuildereventLoopGroup(EventLoopGroup eventLoopGroup)Provides an EventGroupLoop to be used by the netty transport.NettyChannelBuilderflowControlWindow(int flowControlWindow)Sets the flow control window in bytes.static NettyChannelBuilderforAddress(String host, int port)Creates a new builder with the given host and port.static NettyChannelBuilderforAddress(String host, int port, io.grpc.ChannelCredentials creds)Creates a new builder with the given host and port.static NettyChannelBuilderforAddress(SocketAddress serverAddress)Creates a new builder with the given server address.static NettyChannelBuilderforAddress(SocketAddress serverAddress, io.grpc.ChannelCredentials creds)Creates a new builder with the given server address.static NettyChannelBuilderforTarget(String target)Creates a new builder with the given target string that will be resolved byNameResolver.static NettyChannelBuilderforTarget(String target, io.grpc.ChannelCredentials creds)Creates a new builder with the given target string that will be resolved byNameResolver.NettyChannelBuilderinitialFlowControlWindow(int initialFlowControlWindow)Sets the initial flow control window in bytes.NettyChannelBuilderkeepAliveTime(long keepAliveTime, TimeUnit timeUnit)NettyChannelBuilderkeepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit)NettyChannelBuilderkeepAliveWithoutCalls(boolean enable)NettyChannelBuilderlocalSocketPicker(NettyChannelBuilder.LocalSocketPicker localSocketPicker)If non-null, attempts to create connections bound to a local port.NettyChannelBuildermaxHeaderListSize(int maxHeaderListSize)Deprecated.UsemaxInboundMetadataSize(int)insteadNettyChannelBuildermaxInboundMessageSize(int max)Sets the maximum message size allowed for a single gRPC frame.NettyChannelBuildermaxInboundMetadataSize(int bytes)Sets the maximum size of metadata allowed to be received.NettyChannelBuildernegotiationType(NegotiationType type)Sets the negotiation type for the HTTP/2 connection.NettyChannelBuildersslContext(SslContext sslContext)SSL/TLS context to use instead of the system default.NettyChannelBuilderusePlaintext()Equivalent to usingnegotiationType(NegotiationType)withPLAINTEXT.NettyChannelBuilderuseTransportSecurity()Equivalent to usingnegotiationType(NegotiationType)withTLS.<T> NettyChannelBuilderwithOption(ChannelOption<T> option, T value)Specifies a channel option.-
Methods inherited from class io.grpc.ForwardingChannelBuilder2
addMetricSink, addTransportFilter, build, compressorRegistry, decompressorRegistry, defaultLoadBalancingPolicy, defaultServiceConfig, directExecutor, disableRetry, disableServiceConfigLookUp, enableRetry, executor, idleTimeout, intercept, intercept, interceptWithTarget, maxHedgedAttempts, maxRetryAttempts, maxTraceEvents, nameResolverFactory, offloadExecutor, overrideAuthority, perRpcBufferLimit, proxyDetector, retryBufferSize, setBinaryLog, toString, userAgent
-
-
-
-
Field Detail
-
DEFAULT_FLOW_CONTROL_WINDOW
public static final int DEFAULT_FLOW_CONTROL_WINDOW
- See Also:
- Constant Field Values
-
-
Method Detail
-
forAddress
public static NettyChannelBuilder forAddress(SocketAddress serverAddress)
Creates a new builder with the given server address. This factory method is primarily intended for using Netty Channel types other than SocketChannel.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.
-
forAddress
public static NettyChannelBuilder forAddress(SocketAddress serverAddress, io.grpc.ChannelCredentials creds)
Creates a new builder with the given server address. This factory method is primarily intended for using Netty Channel types other than SocketChannel.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.
-
forAddress
public static NettyChannelBuilder forAddress(String host, int port)
Creates a new builder with the given host and port.
-
forAddress
public static NettyChannelBuilder forAddress(String host, int port, io.grpc.ChannelCredentials creds)
Creates a new builder with the given host and port.
-
forTarget
public static NettyChannelBuilder forTarget(String target)
Creates a new builder with the given target string that will be resolved byNameResolver.
-
forTarget
public static NettyChannelBuilder forTarget(String target, io.grpc.ChannelCredentials creds)
Creates a new builder with the given target string that will be resolved byNameResolver.
-
delegate
@Internal protected io.grpc.ManagedChannelBuilder<?> delegate()
- Specified by:
delegatein classio.grpc.ForwardingChannelBuilder2<NettyChannelBuilder>
-
channelType
@CanIgnoreReturnValue public NettyChannelBuilder channelType(Class<? extends Channel> channelType)
Specifies the channel type to use, by default we useEpollSocketChannelif available, otherwise usingNioSocketChannel.You either use this or
channelFactory(io.netty.channel.ChannelFactory)if yourChannelimplementation 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,NioSocketChannelmust useNioEventLoopGroup, otherwise your application won't start.
-
channelType
@CanIgnoreReturnValue public NettyChannelBuilder channelType(Class<? extends Channel> channelType, @Nullable Class<? extends SocketAddress> transportSocketType)
Similar tochannelType(Class)above but allows the caller to specify the socket-type associated with the channelType.- Parameters:
channelType- the type ofChannelto use.transportSocketType- the associatedSocketAddresstype. Ifnull, then no compatibility check is performed between channel transport and name-resolver addresses.
-
channelFactory
@CanIgnoreReturnValue public NettyChannelBuilder channelFactory(ChannelFactory<? extends Channel> channelFactory)
Specifies theChannelFactoryto createChannelinstances. This method is usually only used if the specificChannelrequires complex logic which requires additional information to create theChannel. 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
eventLoopGroup(EventLoopGroup). For example,NioSocketChannelbasedChannelFactorymust useNioEventLoopGroup, otherwise your application won't start.
-
channelFactory
@CanIgnoreReturnValue public NettyChannelBuilder channelFactory(ChannelFactory<? extends Channel> channelFactory, @Nullable Class<? extends SocketAddress> transportSocketType)
Similar tochannelFactory(ChannelFactory)above but allows the caller to specify the socket-type associated with the channelFactory.- Parameters:
channelFactory- theChannelFactoryto use.transportSocketType- the associatedSocketAddresstype. Ifnull, then no compatibility check is performed between channel transport and name-resolver addresses.
-
withOption
@CanIgnoreReturnValue public <T> NettyChannelBuilder withOption(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.
-
negotiationType
@CanIgnoreReturnValue public NettyChannelBuilder negotiationType(NegotiationType type)
Sets the negotiation type for the HTTP/2 connection.Default:
TLS
-
eventLoopGroup
@CanIgnoreReturnValue public NettyChannelBuilder eventLoopGroup(@Nullable EventLoopGroup eventLoopGroup)
Provides an EventGroupLoop to be used by the netty transport.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)orchannelFactory(ChannelFactory)corresponding to the givenEventLoopGroup. For example,NioEventLoopGrouprequiresNioSocketChannelThe channel won't take ownership of the given EventLoopGroup. It's caller's responsibility to shut it down when it's desired.
-
sslContext
@CanIgnoreReturnValue public NettyChannelBuilder sslContext(SslContext sslContext)
SSL/TLS context to use instead of the system default. It must have been configured withGrpcSslContexts, but options could have been overridden.
-
initialFlowControlWindow
@CanIgnoreReturnValue public NettyChannelBuilder 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 NettyChannelBuilder 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.
-
maxHeaderListSize
@CanIgnoreReturnValue @Deprecated @InlineMe(replacement="this.maxInboundMetadataSize(maxHeaderListSize)") public NettyChannelBuilder 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 NettyChannelBuilder 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 classio.grpc.ForwardingChannelBuilder2<NettyChannelBuilder>- Parameters:
bytes- the maximum size of received metadata- Returns:
- this
- Throws:
IllegalArgumentException- if bytes is non-positive- Since:
- 1.17.0
-
usePlaintext
@CanIgnoreReturnValue public NettyChannelBuilder usePlaintext()
Equivalent to usingnegotiationType(NegotiationType)withPLAINTEXT.- Overrides:
usePlaintextin classio.grpc.ForwardingChannelBuilder2<NettyChannelBuilder>
-
useTransportSecurity
@CanIgnoreReturnValue public NettyChannelBuilder useTransportSecurity()
Equivalent to usingnegotiationType(NegotiationType)withTLS.- Overrides:
useTransportSecurityin classio.grpc.ForwardingChannelBuilder2<NettyChannelBuilder>
-
keepAliveTime
@CanIgnoreReturnValue public NettyChannelBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit)
- Overrides:
keepAliveTimein classio.grpc.ForwardingChannelBuilder2<NettyChannelBuilder>- Since:
- 1.3.0
-
keepAliveTimeout
@CanIgnoreReturnValue public NettyChannelBuilder keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit)
- Overrides:
keepAliveTimeoutin classio.grpc.ForwardingChannelBuilder2<NettyChannelBuilder>- Since:
- 1.3.0
-
keepAliveWithoutCalls
@CanIgnoreReturnValue public NettyChannelBuilder keepAliveWithoutCalls(boolean enable)
- Overrides:
keepAliveWithoutCallsin classio.grpc.ForwardingChannelBuilder2<NettyChannelBuilder>- Since:
- 1.3.0
-
localSocketPicker
@CanIgnoreReturnValue public NettyChannelBuilder localSocketPicker(@Nullable NettyChannelBuilder.LocalSocketPicker localSocketPicker)
If non-null, attempts to create connections bound to a local port.
-
maxInboundMessageSize
@CanIgnoreReturnValue public NettyChannelBuilder maxInboundMessageSize(int max)
Sets the maximum message size allowed for a single gRPC frame. If an inbound messages larger than this limit is received it will not be processed and the RPC will fail with RESOURCE_EXHAUSTED.- Overrides:
maxInboundMessageSizein classio.grpc.ForwardingChannelBuilder2<NettyChannelBuilder>
-
-