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

HeaderExchangeClient的更多相关文章

  1. Dubbo中服务消费者和服务提供者之间的请求和响应过程

    服务提供者初始化完成之后,对外暴露Exporter.服务消费者初始化完成之后,得到的是Proxy代理,方法调用的时候就是调用代理. 服务消费者经过初始化之后,得到的是一个动态代理类,InvokerIn ...

  2. Dubbo中消费者初始化的过程解析

    首先还是Spring碰到dubbo的标签之后,会使用parseCustomElement解析dubbo标签,使用的解析器是dubbo的DubboBeanDefinitionParser,解析完成之后返 ...

  3. Dubbo 源码分析 - 服务调用过程

    注: 本系列文章已捐赠给 Dubbo 社区,你也可以在 Dubbo 官方文档中阅读本系列文章. 1. 简介 在前面的文章中,我们分析了 Dubbo SPI.服务导出与引入.以及集群容错方面的代码.经过 ...

  4. Dubbo 源码分析 - 服务引用

    1. 简介 在上一篇文章中,我详细的分析了服务导出的原理.本篇文章我们趁热打铁,继续分析服务引用的原理.在 Dubbo 中,我们可以通过两种方式引用远程服务.第一种是使用服务直联的方式引用服务,第二种 ...

  5. 【Dubbo 源码解析】05_Dubbo 服务发现&引用

    Dubbo 服务发现&引用 Dubbo 引用的服务消费者最终会构造成一个 Spring 的 Bean,具体是通过 ReferenceBean 来实现的.它是一个 FactoryBean,所有的 ...

  6. 9.7 dubbo心跳机制

    dubbo的心跳机制: 目的:检测provider与consumer之间的connection连接是不是还连接着,如果连接断了,需要作出相应的处理. 原理: provider:dubbo的心跳默认是在 ...

  7. bubbo调用Failed to invoke remote method异常解决

    bubbo调用服务异常: com.alibaba.dubbo.rpc.RpcException: Failed to invoke remote method: getPlanFlowInfo, pr ...

  8. 浅谈dubbo的ExceptionFilter异常处理

    背景 我们的项目使用了dubbo进行不同系统之间的调用. 每个项目都有一个全局的异常处理,对于业务异常,我们会抛出自定义的业务异常(继承RuntimeException). 全局的异常处理会根据不同的 ...

  9. dubbo超时重试和异常处理

    dubbo超时重试和异常处理 dubbo超时重试和异常处理 参考: https://www.cnblogs.com/ASPNET2008/p/7292472.html https://www.tuic ...

随机推荐

  1. htm5之视频音频(shit IE10都不支持)

    <p style="color: red; background-color: black;"> 视频<br /> autoplay autoplay 如果 ...

  2. Python3基础 str + 字符串变量拼接

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  3. BZOJ3942: [Usaco2015 Feb]Censoring 栈+KMP

    Description Farmer John has purchased a subscription to Good Hooveskeeping magazine for his cows, so ...

  4. React Native 的组件之底部导航栏 TabBarIOS(一)

    import React,{Component}from 'react'; import { AppRegistry, StyleSheet, Text, View, TabBarIOS, } fro ...

  5. Error: Checksum mismatch.

    bogon:bin macname$ brew install go ==> Downloading https://homebrew.bintray.com/bottles-portable- ...

  6. Ubuntu14.04 获取文件或者文件夹大小

    [root@bogon ~]# stat -c%s install.log

  7. editplus5激活码

    editplus5激活码 name: Vovan code: 3AG46-JJ48E-CEACC-8E6EW-ECUAW 转自:https://blog.csdn.net/webfront/artic ...

  8. 《剑指offer》第三十六题(二叉搜索树与双向链表)

    // 面试题36:二叉搜索树与双向链表 // 题目:输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求 // 不能创建任何新的结点,只能调整树中结点指针的指向. #include < ...

  9. PHP访问Oracle数据库

    说明:Oracle数据库帐号:sticOracle数据库密码:sticOracle数据库实例:orclOracle数据库表:UserInfoOracle表的列:ID,Name 不处理异常的代码如下:/ ...

  10. HTML提交方式post和get区别(实验)

    HTML提交方式post和get区别(实验) 一.post和get区别 get提交,提交的信息都显示在地址栏中. post提交,提交的信息不显示地址栏中,显示在消息体中. 二.客户端代码 <!D ...