zoukankan      html  css  js  c++  java
  • 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。

  • 相关阅读:
    Android UI开发 popupwindow介绍以及代码实例
    前端之Android入门(5) – MVC模式(下)
    前端之Android入门(4) – MVC模式(中)
    前端之Android入门(3) – MVC模式(上)
    前端之Android入门(2) – 程序目录及UI简介
    前端之Android入门(1) – 环境配置
    android之SQLite数据库应用(二)
    android之SQLite数据库应用(一)
    android 裁剪图片大小 控制图片尺寸
    Android应用盈利广告平台的嵌入方法详解
  • 原文地址:https://www.cnblogs.com/gaojy/p/15291303.html
Copyright © 2011-2022 走看看