What is the difference between ServerBootstrap.option () and ServerBootstrap.childOption () in netty 4.x

According to the New and Noteworthy document in 4.0 , netty4 provided the new bootstrap API, and the document gives the following code example:

public static void main(String[] args) throws Exception {
    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .option(ChannelOption.SO_BACKLOG, 100)
         .localAddress(8080)
         .childOption(ChannelOption.TCP_NODELAY, true)
         .childHandler(new ChannelInitializer<SocketChannel>() {
             @Override
             public void initChannel(SocketChannel ch) throws Exception {
                 ch.pipeline().addLast(handler1, handler2, ...);
             }
         });

        // Start the server.
        ChannelFuture f = b.bind().sync();

        // Wait until the server socket is closed.
        f.channel().closeFuture().sync();
    } finally {
        // Shut down all event loops to terminate all threads.
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();

        // Wait until all threads are terminated.
        bossGroup.terminationFuture().sync();
        workerGroup.terminationFuture().sync();
    }
}

The code is used ServerBootStrap.optionfor installation ChannelOption.SO_BACKLOG, and then used ServerBootStrap.childOptionfor installation ChannelOption.TCP_NODELAY.

What is the difference between ServerBootStrap.optionand ServerBootStrap.childOption? How can I find out which parameter should be optionand which should be childOption?

+4
source share
1 answer

What is the difference between ServerBootStrap.option and ServerBootStrap.childOption?

, ServerBootStrap.option, ChannelConfig ServerChannel, , . , bind() connect(). .

ServerBootStrap.childOption channelConfig, , serverChannel . ( ).

ServerBootStrap.option ( ), , ServerBootStrap.childOption , .

attr vs childAttr handler vs childHandler ServerBootstrap.

, , childOption?

ChannelOptions , . API ChannelConfig, . http://netty.io/4.0/api/io/netty/channel/ChannelConfig.html . ChannelConfig.

+5

Source: https://habr.com/ru/post/1629486/


All Articles