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

  • 相关阅读:
    ndk工具使用之armeabiaddr2line 【转http://www.2cto.com/kf/201207/140136.html】
    amr文件格式分析【转http://blog.csdn.net/dinggo/article/details/1966444】
    使用Windows Azure Mobile Service开发Windows Phone 8 App【转http://www.cnblogs.com/dlbrant/archive/2013/04/02/2996627.html】
    unity3D android游戏屏幕分辨率问题【转http://blog.csdn.net/jeksonal/article/details/8501549】
    android配置jni过程可能会遇到的问题
    Android native code的编译和调试【转http://billhoo.blog.51cto.com/2337751/1125039】
    github上的优秀项目和开发环境配置【转http://www.cnblogs.com/2018/archive/2012/11/09/2763119.html】
    如何使用armlinuxandroideabiaddr2line 【转http://blog.csdn.net/hun_sunny/article/details/8350151】
    While循环 Carol
    循环,逻辑运算,格式化输出 Carol
  • 原文地址:https://www.cnblogs.com/allenwas3/p/8336526.html
Copyright © 2011-2022 走看看