zoukankan      html  css  js  c++  java
  • netty源码-server端绑定端口流程

    仅用于记录在分析netty源码的日志

    源码调用关系图

    netty绑定端口

    Netty Server示例

            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内部的绑定端口如下:

    1. AbstractBootstrap --> bind() --> doBind() --> doBind0()
    2. NioServerSocketChannel的bind方法在父类AbstractChannel类,所以channel的调用关系:AbstractChannel --> bind()
    3. DefaultChannelPipeline --> bind()
    4. AbstractChannelHandlerContext --> bind()
    5. HeadContext --> bind()
    6. AbstractChannel.AbstractUnsafe --> bind(),然后调用AbstractChannel --> doBind(),而他的实现类看下一步
    7. NioServerSocketChannel --> doBind()

    一介书生:关注多线程、高并发、分布式、微服务和系统架构。
  • 相关阅读:
    动态规划解决数字三角形问题
    动态规划,贪心,分治
    7-3 两个有序序列的中位数 (20分) log n的解法
    二分查找 单峰数组中的最大值 O(log n)
    数据库连接池 C3P0和 Druid
    SQL注入问题
    MATLAB spectrogram命令
    JDBC工具类
    Egret--拼接Rect实现用于新手引导的扣洞
    egrte-取消居中约束
  • 原文地址:https://www.cnblogs.com/leeyazhou/p/12981911.html
Copyright © 2011-2022 走看看