zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    简单Linux C线程池2
    简单xmlwriter类
    给10^7个有重复的整数排序(败者树)
    给10^7个无重复的整数排序
    将一个4字节整数的二进制表示中的001替换为011
    腾讯社招面试经历
    小闹钟 免费 开源 C# .net framework4
    国内外PHP开源建站程序
    用 .NET Memory Profiler 跟踪.net 应用内存使用情况基本应用篇 (转载)
    c# 语言 winform 项目中 control.parent 的使用 (原创)
  • 原文地址:https://www.cnblogs.com/allenwas3/p/8336526.html
Copyright © 2011-2022 走看看