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连接
发布评论