僅用於記錄在分析netty源碼的日誌bootstrap
EventLoopGroup boss = new NioEventLoopGroup(1); EventLoopGroup io = new NioEventLoopGroup(); ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(boss, io); bootstrap.channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<NioSocketChannel>() { @Override protected void initChannel(NioSocketChannel ch) throws Exception { } }); bootstrap.bind(25001).sync().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { System.out.println("啓動成功"); } else { future.cause().printStackTrace(); } } });
代碼執行到bootstrap.bind(25001)
時,netty內部的綁定端口以下:ide
AbstractBootstrap --> bind() --> doBind() --> doBind0()
AbstractChannel --> bind()
DefaultChannelPipeline --> bind()
AbstractChannelHandlerContext --> bind()
HeadContext --> bind()
AbstractChannel.AbstractUnsafe --> bind()
,而後調用AbstractChannel --> doBind()
,而他的實現類看下一步NioServerSocketChannel --> doBind()