栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

ES对plugin间按照依赖关系进行排序

ES对plugin间按照依赖关系进行排序

        for (Bundle bundle : bundles) {
            addSortedBundle(bundle, namedBundles, sortedBundles, dependencyStack);
        }

遍历所有的bundle。

    // add the given bundle to the sorted bundles, first adding dependencies
    private static void addSortedBundle(Bundle bundle, Map bundles, linkedHashSet sortedBundles,
                                        linkedHashSet dependencyStack) {

        String name = bundle.plugin.getName();
        if (dependencyStack.contains(name)) {
            StringBuilder msg = new StringBuilder("Cycle found in plugin dependencies: ");
            dependencyStack.forEach(s -> {
                msg.append(s);
                msg.append(" -> ");
            });
            msg.append(name);
            throw new IllegalStateException(msg.toString());
        }
        if (sortedBundles.contains(bundle)) {
            // already added this plugin, via a dependency
            return;
        }

        dependencyStack.add(name);
        for (String dependency : bundle.plugin.getExtendedPlugins()) {
            Bundle depBundle = bundles.get(dependency);
            if (depBundle == null) {
                throw new IllegalArgumentException("Missing plugin [" + dependency + "], dependency of [" + name + "]");
            }
            addSortedBundle(depBundle, bundles, sortedBundles, dependencyStack);
            assert sortedBundles.contains(depBundle);
        }
        dependencyStack.remove(name);

        sortedBundles.add(bundle);
    }

步骤

1. 判断dependencyStack中是否含有当前待处理的bunlde的name, 如果包含则证明存在循环依赖则报错。

2. bunlde已经存在在sortedBundles中。则直接返回。

3. 将当前bundle的name加入到dependencyStack中

4. 遍历当前bunlde所有的依赖, 每个依赖的bundle都会从步骤1开始执行。

5. 将当前bundle的name从dependencyStack中删除

6. 将当前bundle加入到sortedBundles中。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/307808.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号