• Sentinel-ClusterBuilderSlot


    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。

  • 相关阅读:
    TypeScript 第一讲 ———— 基本数据类型的使用
    关于TypeScript命名空间
    Egret 自定义皮肤 ———— 引入类中以及createChildren()和 childrenCreated()的使用
    egret基础——控件
    回顾过去,展望未来
    JDBC、Hibernate、Mybatis之间的区别
    SSM框架优缺点和spring boot 比起优缺点是什么?
    拦截器和过滤器的区别
    转发和重定向区别
    关于虚拟机中克隆的linux为什么不能开启网络服务
  • 原文地址:https://www.cnblogs.com/gaojy/p/15291303.html
Copyright © 2020-2023  润新知