• HeaderExchangeClient


    HeaderExchangeClient 注释是DefaultMessageClient,类中定义了心跳定时器
    HeaderExchangeChannel 发送请求
    HeaderExchangeHandler provider中处理请求,consumer中处理响应

    创建HeaderExchangeClient对象:

    //HeaderExchanger
    public ExchangeClient connect(URL url, ExchangeHandler handler) throws RemotingException {
        //对象是 HeaderExchangeClient/NettyClient/DecodeHandler/HeaderExchangeHandler
        return new HeaderExchangeClient(
            Transporters.connect(url, new DecodeHandler(new HeaderExchangeHandler(handler)))); }

    HeaderExchangeClient类:

    private final ExchangeChannel channel;
    public HeaderExchangeClient(Client client){
        if (client == null) {
            throw new IllegalArgumentException("client == null");
        }
        this.client = client;
        //关联上HeaderExchangeChannel
        this.channel = new HeaderExchangeChannel(client);
        String dubbo = client.getUrl().getParameter(Constants.DUBBO_VERSION_KEY);
        this.heartbeat = client.getUrl().getParameter( Constants.HEARTBEAT_KEY, dubbo != null && dubbo.startsWith("1.0.") ? Constants.DEFAULT_HEARTBEAT : 0 );
        this.heartbeatTimeout = client.getUrl().getParameter( Constants.HEARTBEAT_TIMEOUT_KEY, heartbeat * 3 );
        if ( heartbeatTimeout < heartbeat * 2 ) {
            throw new IllegalStateException( "heartbeatTimeout < heartbeatInterval * 2" );
        }
        startHeatbeatTimer();
    }

    Transporters类:

    //Transporters
    public static Client connect(URL url, ChannelHandler... handlers) throws RemotingException {
        if (url == null) {
            throw new IllegalArgumentException("url == null");
        }
        ChannelHandler handler;
        if (handlers == null || handlers.length == 0) {
            handler = new ChannelHandlerAdapter();
        } else if (handlers.length == 1) {
            handler = handlers[0];
        } else {
            handler = new ChannelHandlerDispatcher(handlers);
        }
        return getTransporter().connect(url, handler);
    }
    
    public static Transporter getTransporter() {
        //返回Transporter$Adpative对象
        return ExtensionLoader.getExtensionLoader(Transporter.class).getAdaptiveExtension();
    }

    Transporter$Adpative类:

    package com.alibaba.dubbo.remoting;
    import com.alibaba.dubbo.common.extension.ExtensionLoader;
    public class Transporter$Adpative implements com.alibaba.dubbo.remoting.Transporter {
        //省略其他代码
        public com.alibaba.dubbo.remoting.Client connect(
                com.alibaba.dubbo.common.URL arg0,
                com.alibaba.dubbo.remoting.ChannelHandler arg1)
                throws com.alibaba.dubbo.common.URL {
            if (arg0 == null)
                throw new IllegalArgumentException("url == null");
            com.alibaba.dubbo.common.URL url = arg0;
            String extName = url.getParameter("client",
                    url.getParameter("transporter", "netty"));
            if (extName == null)
                throw new IllegalStateException(
                        "Fail to get extension(com.alibaba.dubbo.remoting.Transporter) name from url("
                                + url.toString()
                                + ") use keys([client, transporter])");
            com.alibaba.dubbo.remoting.Transporter extension = (com.alibaba.dubbo.remoting.Transporter) ExtensionLoader
                    .getExtensionLoader(
                            com.alibaba.dubbo.remoting.Transporter.class)
                    .getExtension(extName);
            //extension是NettyTransporter
            return extension.connect(arg0, arg1);
        }
    }

    NettyTransporter类

    //NettyTransporter
    public Client connect(URL url, ChannelHandler listener) throws RemotingException {
        return new NettyClient(url, listener);
    }

    /META-INF/dubbo/internal/com.alibaba.dubbo.remoting.Transporter文件内容中,没有发现wrapper。
    netty=com.alibaba.dubbo.remoting.transport.netty.NettyTransporter
    mina=com.alibaba.dubbo.remoting.transport.mina.MinaTransporter
    grizzly=com.alibaba.dubbo.remoting.transport.grizzly.GrizzlyTransporter

  • 相关阅读:
    从0到1构建适配不同端(微信小程序、H5、React-Native 等)的taro + dva应用
    一个基于Ionic3.x cordova的移动APP demo
    基于 MUI 构建一个具有 90 +页面的APP应用
    风清杨之Oracle的安装与说明
    浅析C#中的“==”和Equals
    window.open()的使用
    动态生成级联下拉框和多选框
    生成二维码的两种方式
    登录添加验证码校验
    oracle11g的安装以及配置
  • 原文地址:https://www.cnblogs.com/allenwas3/p/8336526.html
Copyright © 2020-2023  润新知