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

posted on 2018-01-23 16:35  偶尔发呆  阅读(2284)  评论(0编辑  收藏  举报