dubbo rpc NettyClient连接

编程入门 行业动态 更新时间:2024-10-28 21:29:31

<a href=https://www.elefans.com/category/jswz/34/1768019.html style=dubbo rpc NettyClient连接"/>

dubbo rpc NettyClient连接

consumer获取channel

NettyChannel.CHANNEL_MAP(静态变量)中存储着channel。

/*** the cache for netty channel and dubbo channel*/private static final ConcurrentMap<Channel, NettyChannel> CHANNEL_MAP = new ConcurrentHashMap<Channel, NettyChannel>();

通过NettyChannel类中的getOrAddChannel方法获取

    /*** Get dubbo channel by netty channel through channel cache.* Put netty channel into it if dubbo channel don't exist in the cache.** @param ch      netty channel* @param url* @param handler dubbo handler that contain netty's handler* @return*/static NettyChannel getOrAddChannel(Channel ch, URL url, ChannelHandler handler) {if (ch == null) {return null;}NettyChannel ret = CHANNEL_MAP.get(ch);if (ret == null) {NettyChannel nettyChannel = new NettyChannel(ch, url, handler);if (ch.isActive()) {//先尝试存入mapnettyChannel.markActive(true);ret = CHANNEL_MAP.putIfAbsent(ch, nettyChannel);}if (ret == null) {//无论是否成功存入map,也要将其返回ret = nettyChannel;}}return ret;}

NettyChannel.CHANNEL_MAP中获取失败,就重新构建一个NettyChannel对象。
ch.isActive为true,将其存到NettyChannel.CHANNEL_MAP
ch.isActive等价于NioSocketChannel.ch.state==2 && NioSocketChannel.ch.open==true

consumer关闭客户端时

provider中会有警告(AbstractServer.disconnected中的代码)

[06/12/20 12:13:07:007 CST] NettyServerWorker-5-7  WARN transport.AbstractServer:  [DUBBO] All clients has disconnected from /192.168.161.1:20880. You can graceful shutdown now., dubbo version: 2.7.7, current host: 192.168.0.107

猜测其触发方式是由于套接字发出了什么事件。然后在轮询SingleThreadEventExecutor.runAllTasks时在taskQueue中检测到新的任务,开始执行任务。

更多推荐

dubbo rpc NettyClient连接

本文发布于:2024-03-06 06:11:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1714572.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:dubbo   rpc   NettyClient

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!