private static void printModule(final PrintStream out, final ModuleConfig moduleConfig) { printComponents(out, moduleConfig.getName(), moduleConfig.getComponentConfigs()); }
/** * Registers all methods annotated with @Metrics */ public static List<MetricDefinition> createMetricDefinitions(final String componentId, final Component component, final AopPlugin aopPlugin) { Assertion.checkNotNull(component); //-- we construct a map of feature by componentId final Map<String, String> featureByComponentId = new HashMap<>(); Home.getApp().getConfig().getModuleConfigs() .forEach(moduleConfig -> moduleConfig.getComponentConfigs() .forEach(componentConfig -> featureByComponentId.put(componentConfig.getId(), moduleConfig.getName()))); //----- //1. search all methods return Stream.of(aopPlugin.unwrap(component).getClass().getMethods()) .filter(method -> method.isAnnotationPresent(Metrics.class)) .map(method -> { Assertion.checkArgument(List.class.isAssignableFrom(method.getReturnType()), "metrics supplier methods of class {0} must return a List of Metric instead of {1}", component.getClass(), method.getReturnType()); Assertion.checkArgument(method.getParameterTypes().length == 0, "metrics supplier methods of class {0} must not have any parameter", component.getClass()); //----- //2. For each method register a listener // we remove # because it doesn't comply with definition naming rule final String metricDefinitionName = "MET_" + StringUtil.camelToConstCase(componentId.replaceAll("#", "")) + "$" + StringUtil.camelToConstCase(method.getName()); return new MetricDefinition( metricDefinitionName, () -> (List<Metric>) ClassUtil.invoke(component, method)); }) .collect(Collectors.toList()); }
.forEach(moduleConfig -> moduleConfig.getComponentConfigs() .forEach(componentConfig -> featureByComponentId.put(componentConfig.getId(), moduleConfig.getName())));
/** * Add all the components defined in the moduleConfigs into the componentSpace. * @param paramManagerOpt optional paramManager * @param moduleConfigs the config of the module to add. */ public void registerAllComponentsAndAspects(final Optional<ParamManager> paramManagerOpt, final List<ModuleConfig> moduleConfigs) { Assertion.checkNotNull(moduleConfigs); //----- for (final ModuleConfig moduleConfig : moduleConfigs) { registerComponents(paramManagerOpt, moduleConfig.getName(), moduleConfig.getComponentConfigs()); registerAspects(moduleConfig.getAspectConfigs()); registerProxyMethods(moduleConfig.getProxyMethodConfigs()); } }