@Test public void testInitPluginsCyclicDependency() { final List<StagemonitorPlugin> plugins = Arrays.asList(new PluginNoDependency(), new PluginCyclicA(), new PluginCyclicB()); assertThatThrownBy(() -> Stagemonitor.initializePluginsInOrder(Collections.emptyList(), plugins)) .isInstanceOf(IllegalStateException.class) .hasMessageContaining("PluginCyclicA") .hasMessageContaining("PluginCyclicB"); }
static void initializePluginsInOrder(Collection<String> disabledPlugins, Iterable<StagemonitorPlugin> plugins) { Set<Class<? extends StagemonitorPlugin>> alreadyInitialized = new HashSet<Class<? extends StagemonitorPlugin>>(); Set<StagemonitorPlugin> notYetInitialized = getPluginsToInit(disabledPlugins, plugins); while (!notYetInitialized.isEmpty()) { int countNotYetInitialized = notYetInitialized.size(); for (Iterator<StagemonitorPlugin> iterator = notYetInitialized.iterator(); iterator.hasNext(); ) { StagemonitorPlugin stagemonitorPlugin = iterator.next(); { final List<Class<? extends StagemonitorPlugin>> dependencies = stagemonitorPlugin.dependsOn(); if (dependencies.isEmpty() || alreadyInitialized.containsAll(dependencies)) { initializePlugin(stagemonitorPlugin); iterator.remove(); alreadyInitialized.add(stagemonitorPlugin.getClass()); } } } if (countNotYetInitialized == notYetInitialized.size()) { throw new IllegalStateException("Cyclic dependencies detected: " + notYetInitialized); } } }
Stagemonitor { static void initializePluginsInOrder(Collection<String> disabledPlugins, Iterable<StagemonitorPlugin> plugins) { Set<Class<? extends StagemonitorPlugin>> alreadyInitialized = new HashSet<Class<? extends StagemonitorPlugin>>(); Set<StagemonitorPlugin> notYetInitialized = getPluginsToInit(disabledPlugins, plugins); while (!notYetInitialized.isEmpty()) { int countNotYetInitialized = notYetInitialized.size(); for (Iterator<StagemonitorPlugin> iterator = notYetInitialized.iterator(); iterator.hasNext(); ) { StagemonitorPlugin stagemonitorPlugin = iterator.next(); { final List<Class<? extends StagemonitorPlugin>> dependencies = stagemonitorPlugin.dependsOn(); if (dependencies.isEmpty() || alreadyInitialized.containsAll(dependencies)) { initializePlugin(stagemonitorPlugin); iterator.remove(); alreadyInitialized.add(stagemonitorPlugin.getClass()); } } } if (countNotYetInitialized == notYetInitialized.size()) { throw new IllegalStateException("Cyclic dependencies detected: " + notYetInitialized); } } } }
Stagemonitor { static void initializePluginsInOrder(Collection<String> disabledPlugins, Iterable<StagemonitorPlugin> plugins) { Set<Class<? extends StagemonitorPlugin>> alreadyInitialized = new HashSet<Class<? extends StagemonitorPlugin>>(); Set<StagemonitorPlugin> notYetInitialized = getPluginsToInit(disabledPlugins, plugins); while (!notYetInitialized.isEmpty()) { int countNotYetInitialized = notYetInitialized.size(); for (Iterator<StagemonitorPlugin> iterator = notYetInitialized.iterator(); iterator.hasNext(); ) { StagemonitorPlugin stagemonitorPlugin = iterator.next(); { final List<Class<? extends StagemonitorPlugin>> dependencies = stagemonitorPlugin.dependsOn(); if (dependencies.isEmpty() || alreadyInitialized.containsAll(dependencies)) { initializePlugin(stagemonitorPlugin); iterator.remove(); alreadyInitialized.add(stagemonitorPlugin.getClass()); } } } if (countNotYetInitialized == notYetInitialized.size()) { throw new IllegalStateException("Cyclic dependencies detected: " + notYetInitialized); } } } private  Stagemonitor(); }
Stagemonitor { static void initializePluginsInOrder(Collection<String> disabledPlugins, Iterable<StagemonitorPlugin> plugins) { Set<Class<? extends StagemonitorPlugin>> alreadyInitialized = new HashSet<Class<? extends StagemonitorPlugin>>(); Set<StagemonitorPlugin> notYetInitialized = getPluginsToInit(disabledPlugins, plugins); while (!notYetInitialized.isEmpty()) { int countNotYetInitialized = notYetInitialized.size(); for (Iterator<StagemonitorPlugin> iterator = notYetInitialized.iterator(); iterator.hasNext(); ) { StagemonitorPlugin stagemonitorPlugin = iterator.next(); { final List<Class<? extends StagemonitorPlugin>> dependencies = stagemonitorPlugin.dependsOn(); if (dependencies.isEmpty() || alreadyInitialized.containsAll(dependencies)) { initializePlugin(stagemonitorPlugin); iterator.remove(); alreadyInitialized.add(stagemonitorPlugin.getClass()); } } } if (countNotYetInitialized == notYetInitialized.size()) { throw new IllegalStateException("Cyclic dependencies detected: " + notYetInitialized); } } } private  Stagemonitor(); static synchronized void init(); static synchronized void shutDown(); @Deprecated static MetricRegistry getMetricRegistry(); static Metric2Registry getMetric2Registry(); static HealthCheckRegistry getHealthCheckRegistry(); static ConfigurationRegistry getConfiguration(); static T getPlugin(Class<T> plugin); @Deprecated static T getConfiguration(Class<T> plugin); static MeasurementSession getMeasurementSession(); static boolean isStarted(); static List<String> getPathsOfWidgetTabPlugins(); static List<String> getPathsOfWidgetMetricTabPlugins(); @Deprecated static void reset(); @Deprecated static void reset(MeasurementSession measurementSession); }
Stagemonitor { static void initializePluginsInOrder(Collection<String> disabledPlugins, Iterable<StagemonitorPlugin> plugins) { Set<Class<? extends StagemonitorPlugin>> alreadyInitialized = new HashSet<Class<? extends StagemonitorPlugin>>(); Set<StagemonitorPlugin> notYetInitialized = getPluginsToInit(disabledPlugins, plugins); while (!notYetInitialized.isEmpty()) { int countNotYetInitialized = notYetInitialized.size(); for (Iterator<StagemonitorPlugin> iterator = notYetInitialized.iterator(); iterator.hasNext(); ) { StagemonitorPlugin stagemonitorPlugin = iterator.next(); { final List<Class<? extends StagemonitorPlugin>> dependencies = stagemonitorPlugin.dependsOn(); if (dependencies.isEmpty() || alreadyInitialized.containsAll(dependencies)) { initializePlugin(stagemonitorPlugin); iterator.remove(); alreadyInitialized.add(stagemonitorPlugin.getClass()); } } } if (countNotYetInitialized == notYetInitialized.size()) { throw new IllegalStateException("Cyclic dependencies detected: " + notYetInitialized); } } } private  Stagemonitor(); static synchronized void init(); static synchronized void shutDown(); @Deprecated static MetricRegistry getMetricRegistry(); static Metric2Registry getMetric2Registry(); static HealthCheckRegistry getHealthCheckRegistry(); static ConfigurationRegistry getConfiguration(); static T getPlugin(Class<T> plugin); @Deprecated static T getConfiguration(Class<T> plugin); static MeasurementSession getMeasurementSession(); static boolean isStarted(); static List<String> getPathsOfWidgetTabPlugins(); static List<String> getPathsOfWidgetMetricTabPlugins(); @Deprecated static void reset(); @Deprecated static void reset(MeasurementSession measurementSession);  }