use of io.vertigo.commons.analytics.metric.MetricDefinition in project vertigo by KleeGroup.
the class MetricAnalyticsUtil method createMetricDefinitions.
/**
* 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());
}
Aggregations