private static List<String> getSkills(final App app) { return app.getConfig().getModuleConfigs().stream() .map(ModuleConfig::getName) .collect(Collectors.toList()); }
@Override public Optional<Node> find(final String nodeId) { if (Home.getApp().getConfig().getNodeConfig().getNodeId().equals(nodeId)) { return Optional.of(localNode); } return Optional.empty(); }
/** * Constructor. * @param appNameOpt the app name * @param hostNameOpt hostName of the remote server * @param portOpt port of the remote server */ @Inject public SocketLoggerAnalyticsConnectorPlugin( @Named("appName") final Optional<String> appNameOpt, @Named("hostName") final Optional<String> hostNameOpt, @Named("port") final Optional<Integer> portOpt) { Assertion.checkNotNull(appNameOpt); Assertion.checkNotNull(hostNameOpt); Assertion.checkNotNull(portOpt); // --- appName = appNameOpt.orElse(Home.getApp().getConfig().getNodeConfig().getAppName()); hostName = hostNameOpt.orElse("analytica.part.klee.lan.net"); port = portOpt.orElse(DEFAULT_SERVER_PORT); localHostName = retrieveHostName(); }
/** * 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()); }
@Override public Node getCurrentNode() { final String currentNodeId = Home.getApp().getConfig().getNodeConfig().getNodeId(); return find(currentNodeId) .orElseThrow(() -> new VSystemException("Current node with '{0}' cannot be found in the registry", currentNodeId)); }
@Override public List<? extends Definition> provideDefinitions(final DefinitionSpace definitionSpace) { // we need to unwrap the component to scan the real class and not the enhanced version final AopPlugin aopPlugin = Home.getApp().getConfig().getBootConfig().getAopPlugin(); return Home.getApp().getComponentSpace().keySet() .stream() .flatMap(id -> createDaemonDefinitions(Home.getApp().getComponentSpace().resolve(id, Component.class), aopPlugin).stream()) .collect(Collectors.toList()); }
@Override public List<? extends Definition> provideDefinitions(final DefinitionSpace definitionSpace) { // we need to unwrap the component to scan the real class and not the enhanced version final AopPlugin aopPlugin = Home.getApp().getConfig().getBootConfig().getAopPlugin(); return Home.getApp().getComponentSpace().keySet() .stream() .flatMap(id -> createEventSubscriptions(id, Home.getApp().getComponentSpace().resolve(id, Component.class), aopPlugin).stream()) .collect(Collectors.toList()); }
Home.getApp().getConfig().getModuleConfigs() .forEach(moduleConfig -> moduleConfig.getComponentConfigs() .forEach(componentConfig -> featureByComponentId.put(componentConfig.getId(), moduleConfig.getName())));
@Override public List<? extends Definition> provideDefinitions(final DefinitionSpace definitionSpace) { // here all // we need to unwrap the component to scan the real class and not the enhanced version final AopPlugin aopPlugin = Home.getApp().getConfig().getBootConfig().getAopPlugin(); return Home.getApp().getComponentSpace().keySet() .stream() .flatMap(id -> Stream.concat( //health HealthAnalyticsUtil.createHealthCheckDefinitions(id, Home.getApp().getComponentSpace().resolve(id, Component.class), aopPlugin).stream(), //metrics MetricAnalyticsUtil.createMetricDefinitions(id, Home.getApp().getComponentSpace().resolve(id, Component.class), aopPlugin).stream())) .collect(Collectors.toList()); }
@Test public final void testUnwrapp() { final AopPlugin aopPlugin = getApp().getConfig().getBootConfig().getAopPlugin(); final F f = getApp().getComponentSpace().resolve(F.class); // Il y a des aspects sur la classe donc elle doit être dewrappable assertNotEquals(F.class.getName(), f.getClass().getName()); assertEquals(F.class.getName(), aopPlugin.unwrap(f).getClass().getName()); // Il y a pas d'aspect final A myA = getApp().getComponentSpace().resolve(A.class); assertEquals(A.class.getName(), myA.getClass().getName()); assertEquals(A.class.getName(), aopPlugin.unwrap(myA).getClass().getName()); }