dubbo笔记-remoting(1)基本概念

1.基本概念

1.1.EndPoint

dubbo笔记-remoting(1)基本概念_第1张图片

EndPoint为网络端结点的抽象接口,定义了获取网络端点地址、连接、及最原始的发送消息的方法。

1.2.ChannelHandler

dubbo笔记-remoting(1)基本概念_第2张图片

ChannelHandler为网络事件处理器接口,定义了Server端监听到各种类型的网络事件时的处理方法

1.3.Channel

Channel继承自EndPoint,除了EndPoint的能力,同时还扩展了Attribute的能力

dubbo笔记-remoting(1)基本概念_第3张图片

2 抽象实现

2.1 AbstractPeer

public abstract class AbstractPeer implements Endpoint, ChannelHandler {

    private final ChannelHandler handler;

    private volatile URL url;

    public AbstractPeer(URL url, ChannelHandler handler) {
        if (url == null) {
            throw new IllegalArgumentException("url == null");
        }
        if (handler == null) {
            throw new IllegalArgumentException("handler == null");
        }
        this.url = url;
        this.handler = handler;
    }
}

AbstractPeer类实现了ChannelHandler和EndPoint接口
构造函数传入了ChannelHandler和URL,ChannelHandler的实现通过传入的ChannelHandler属性代理实现
ChannelHandler接口的相关方法依赖其channelHandler属性完成实现,EndPoint接口相关方法,完成了一个抽象类的脚本架,除了send实际方法未实现之外

2.2 AbstractEndpoint

public abstract class AbstractEndpoint extends AbstractPeer implements Resetable {

    private static final Logger logger = LoggerFactory.getLogger(AbstractEndpoint.class);

    private Codec2 codec;

    private int timeout;

    private int connectTimeout;

    public AbstractEndpoint(URL url, ChannelHandler handler) {
        super(url, handler);
        this.codec = getChannelCodec(url);
        this.timeout = url.getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
        this.connectTimeout = url.getPositiveParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT);
    }

AbstractEndpoint暴露了timeout和codec属性

3.Client和Server

dubbo笔记-remoting(1)基本概念_第4张图片

Client和Server接口定义了相应的接口

public interface Client extends Endpoint, Channel, Resetable {

    /**
     * reconnect.
     */
    void reconnect() throws RemotingException;

    @Deprecated
    void reset(com.alibaba.dubbo.common.Parameters parameters);

}

public interface Server extends Endpoint, Resetable {

    /**
     * is bound.
     *
     * @return bound
     */
    boolean isBound();

    /**
     * get channels.
     *
     * @return channels
     */
    Collection getChannels();

    /**
     * get channel.
     *
     * @param remoteAddress
     * @return channel
     */
    Channel getChannel(InetSocketAddress remoteAddress);

    @Deprecated
    void reset(com.alibaba.dubbo.common.Parameters parameters);

}

后续再来看具体的实现

参考:
dubbo剖析:三 网络通信之 -- Server实现

你可能感兴趣的:(dubbo笔记-remoting(1)基本概念)