Package io.grpc.netty

Class NettyChannelBuilder

    • 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​(java.net.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​(java.net.SocketAddress serverAddress,
                                                     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​(java.lang.String host,
                                                     int port)
        Creates a new builder with the given host and port.
      • forTarget

        public static NettyChannelBuilder forTarget​(java.lang.String target)
        Creates a new builder with the given target string that will be resolved by NameResolver.
      • channelType

        @CanIgnoreReturnValue
        public NettyChannelBuilder channelType​(java.lang.Class<? extends io.netty.channel.Channel> channelType)
        Specifies the channel type to use, by default we use 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.

      • channelFactory

        @CanIgnoreReturnValue
        public NettyChannelBuilder channelFactory​(io.netty.channel.ChannelFactory<? extends io.netty.channel.Channel> channelFactory)
        Specifies the 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.

      • withOption

        @CanIgnoreReturnValue
        public <T> NettyChannelBuilder 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.
      • negotiationType

        @CanIgnoreReturnValue
        public NettyChannelBuilder negotiationType​(NegotiationType type)
        Sets the negotiation type for the HTTP/2 connection.

        Default: TLS

      • eventLoopGroup

        @CanIgnoreReturnValue
        public NettyChannelBuilder eventLoopGroup​(@Nullable
                                                  io.netty.channel.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) 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.

      • sslContext

        @CanIgnoreReturnValue
        public NettyChannelBuilder sslContext​(io.netty.handler.ssl.SslContext sslContext)
        SSL/TLS context to use instead of the system default. It must have been configured with GrpcSslContexts, 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, use flowControlWindow(int). By default, auto flow control is enabled with initial flow control window size of DEFAULT_FLOW_CONTROL_WINDOW.
      • flowControlWindow

        @CanIgnoreReturnValue
        public NettyChannelBuilder flowControlWindow​(int flowControlWindow)
        Sets the flow control window in bytes. Setting flowControlWindow disables auto flow control tuning; use initialFlowControlWindow(int) to enable auto flow control tuning. If not called, the default value is DEFAULT_FLOW_CONTROL_WINDOW) with auto flow control tuning.
      • maxHeaderListSize

        @CanIgnoreReturnValue
        @Deprecated
        @InlineMe(replacement="this.maxInboundMetadataSize(maxHeaderListSize)")
        public NettyChannelBuilder maxHeaderListSize​(int maxHeaderListSize)
        Deprecated.
        Sets 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.
      • keepAliveTime

        @CanIgnoreReturnValue
        public NettyChannelBuilder keepAliveTime​(long keepAliveTime,
                                                 java.util.concurrent.TimeUnit timeUnit)
        Sets the time without read activity before sending a keepalive ping. An unreasonably small value might be increased, and Long.MAX_VALUE nano seconds or an unreasonably large value will disable keepalive. Defaults to infinite.

        Clients must receive permission from the service owner before enabling this option. Keepalives can increase the load on services and are commonly "invisible" making it hard to notice when they are causing excessive load. Clients are strongly encouraged to use only as small of a value as necessary.

        Overrides:
        keepAliveTime in class ForwardingChannelBuilder2<NettyChannelBuilder>
        Since:
        1.3.0
        See Also:
        gRFC A8 Client-side Keepalive
      • keepAliveTimeout

        @CanIgnoreReturnValue
        public NettyChannelBuilder keepAliveTimeout​(long keepAliveTimeout,
                                                    java.util.concurrent.TimeUnit timeUnit)
        Sets the time waiting for read activity after sending a keepalive ping. If the time expires without any read activity on the connection, the connection is considered dead. An unreasonably small value might be increased. Defaults to 20 seconds.

        This value should be at least multiple times the RTT to allow for lost packets.

        Overrides:
        keepAliveTimeout in class ForwardingChannelBuilder2<NettyChannelBuilder>
        Since:
        1.3.0
        See Also:
        gRFC A8 Client-side Keepalive
      • 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:
        maxInboundMessageSize in class ForwardingChannelBuilder2<NettyChannelBuilder>
        Parameters:
        max - the maximum number of bytes a single message can be.
        Returns:
        this