标签:node clusterNode ClusterNode ClusterBuilderSlot context Sentinel new
ClusterBuilderSlot源码解析
ClusterBuilderSlot里面有这么几个重要的属性
// static 有点意思 实际上全局的一个资源对应一个ClusterNode private static volatile Map<ResourceWrapper, ClusterNode> clusterNodeMap = new HashMap<>(); // For DCL private static final Object lock = new Object(); private volatile ClusterNode clusterNode = null;
就是说ClusterBuilderSlot里面维护了所有的资源与clusteNode的关系,同时也维护当前资源的ClusterNode。ClusterNode主要用于数据统计,这块将在后续介绍。
@Override public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count, boolean prioritized, Object... args) throws Throwable { if (clusterNode == null) { synchronized (lock) { if (clusterNode == null) { // Create the cluster node. clusterNode = new ClusterNode(resourceWrapper.getName(), resourceWrapper.getResourceType()); HashMap<ResourceWrapper, ClusterNode> newMap = new HashMap<>(Math.max(clusterNodeMap.size(), 16)); newMap.putAll(clusterNodeMap); newMap.put(node.getId(), clusterNode); clusterNodeMap = newMap; } } } // default node node.setClusterNode(clusterNode); /* * if context origin is set, we should get or create a new {@link Node} of * the specific origin. */ // 为context创建一个originNode if (!"".equals(context.getOrigin())) { /** * 在相同资源的clusterNode中,保存origin 与 StatisticNode的对应关系。 * 列如统计了资源A的clusternode在APP_A源中的统计数据StatisticNode */ // originNode = new StatisticNode Node originNode = node.getClusterNode().getOrCreateOriginNode(context.getOrigin()); context.getCurEntry().setOriginNode(originNode); } fireEntry(context, resourceWrapper, node, count, prioritized, args); }
当前的DefalutNode会维护该资源的clusterNode,同时在上一个NodeSelectorSlot中把当前的DefaultNode设置在了context的CurNode中。
在ClusterBuilderSlot的最后会在当前的DefaultNode中 保存该资源clusterNode中的该来源的statisticNode,也就是OriginNode。
标签:node,clusterNode,ClusterNode,ClusterBuilderSlot,context,Sentinel,new 来源: https://www.cnblogs.com/gaojy/p/15291303.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。