/** * Remove all the annotations. * * @return self */ default AnnotatedFieldConfigurator<T> removeAll() { return remove((a) -> true); }
/** * Remove all the annotations. * * @return self */ default AnnotatedParameterConfigurator<T> removeAll() { return remove((a) -> true); }
/** * Remove all the annotations. * * @return self */ default AnnotatedMethodConfigurator<T> removeAll() { return remove((a) -> true); }
Class<?> clazz = configurator.getAnnotated().getJavaClass(); configurator.filterMethods(method -> !Modifier.isPrivate(method.getJavaMember().getModifiers())) .forEach(method -> { METRIC_ANNOTATIONS.forEach(annotation -> { LookupResult<? extends Annotation> lookupResult = lookupAnnotation(method.getAnnotated().getJavaMember(), annotation, clazz); if (lookupResult != null) { registerMetric(method.getAnnotated().getJavaMember(), clazz, lookupResult); configurator.filterConstructors(constructor -> !Modifier.isPrivate(constructor.getJavaMember().getModifiers())) .forEach(constructor -> { METRIC_ANNOTATIONS.forEach(annotation -> { LookupResult<? extends Annotation> lookupResult = lookupAnnotation(constructor.getAnnotated().getJavaMember(), annotation, clazz); if (lookupResult != null) { registerMetric(constructor.getAnnotated().getJavaMember(), clazz, lookupResult);
/** * @param predicate Testing the original {@link AnnotatedMethod} * @return a sequence of {@link AnnotatedMethodConfigurator}s matching the given predicate * @see AnnotatedMethodConfigurator#getAnnotated() */ default Stream<AnnotatedMethodConfigurator<? super T>> filterMethods(Predicate<AnnotatedMethod<? super T>> predicate) { return methods().stream().filter(c -> predicate.test(c.getAnnotated())); }
/** * * @param predicate Testing the original {@link AnnotatedConstructor} * @return a sequence of {@link AnnotatedConstructorConfigurator}s matching the given predicate * @see AnnotatedConstructorConfigurator#getAnnotated() */ default Stream<AnnotatedConstructorConfigurator<T>> filterConstructors(Predicate<AnnotatedConstructor<T>> predicate) { return constructors().stream().filter(c -> predicate.test(c.getAnnotated())); }
/** * @param predicate Testing the original {@link AnnotatedField} * @return a sequence of {@link AnnotatedFieldConfigurator}s matching the given predicate * @see AnnotatedFieldConfigurator#getAnnotated() */ default Stream<AnnotatedFieldConfigurator<? super T>> filterFields(Predicate<AnnotatedField<? super T>> predicate) { return fields().stream().filter(f -> predicate.test(f.getAnnotated())); }
/** * * @param predicate Testing the original {@link AnnotatedParameter} * @return a sequence of {@link AnnotatedParameterConfigurator}s matching the given predicate * @see AnnotatedParameterConfigurator#getAnnotated() */ default Stream<AnnotatedParameterConfigurator<T>> filterParams(Predicate<AnnotatedParameter<T>> predicate) { return params().stream().filter(p -> predicate.test(p.getAnnotated())); }
/** * * @param predicate Testing the original {@link AnnotatedParameter} * @return a sequence of {@link AnnotatedParameterConfigurator}s matching the given predicate * @see AnnotatedParameterConfigurator#getAnnotated() */ default Stream<AnnotatedParameterConfigurator<T>> filterParams(Predicate<AnnotatedParameter<T>> predicate) { return params().stream().filter(p -> predicate.test(p.getAnnotated())); }
private void recordAnnotatedGaugeSite(@Observes @WithAnnotations(Gauge.class) ProcessAnnotatedType<?> pat) { LOGGER.log(Level.FINE, () -> "### recordAnnoatedGaugeSite for class " + pat.getAnnotatedType().getJavaClass()); AnnotatedType<?> type = pat.getAnnotatedType(); LOGGER.log(Level.FINE, () -> "### Processing annotations for " + type.getJavaClass().getName()); // Register metrics based on annotations AnnotatedTypeConfigurator<?> configurator = pat.configureAnnotatedType(); Class<?> clazz = configurator.getAnnotated().getJavaClass(); // If abstract class, then handled by concrete subclasses if (Modifier.isAbstract(clazz.getModifiers())) { return; } // Process @Gauge methods keeping non-private declared on this class configurator.filterMethods(method -> method.getJavaMember().getDeclaringClass().equals(clazz) && !Modifier.isPrivate(method.getJavaMember().getModifiers()) && method.isAnnotationPresent(Gauge.class)) .forEach(method -> { Method javaMethod = method.getAnnotated().getJavaMember(); String explicitGaugeName = method.getAnnotated().getAnnotation(Gauge.class).name(); String gaugeName = String.format("%s.%s", clazz.getName(), explicitGaugeName != null && explicitGaugeName.length() > 0 ? explicitGaugeName : javaMethod.getName()); annotatedGaugeSites.put(gaugeName, method); LOGGER.log(Level.FINE, () -> String.format("### Recorded annotated gauge with name %s", gaugeName)); }); }
/** * Register a config producer bean for each {@link ConfigProperty} injection. * * @param abd event from CDI container * @param bm bean manager */ public void registerConfigProducer(@Observes AfterBeanDiscovery abd, BeanManager bm) { // each injection point will have its own bean qualifiers.forEach(q -> abd.addBean(new ConfigPropertyProducer(q.qualifier, q.type, bm))); // we also must support injection of Config itself abd.addBean() .addType(Config.class) .createWith(creationalContext -> ((MpConfig) configResolver.getConfig()).helidonConfig()); abd.addBean() .addType(org.eclipse.microprofile.config.Config.class) .createWith(creationalContext -> { return new SerializableConfig(); }); }
private DelegatingGauge<?> buildDelegatingGauge(String gaugeName, AnnotatedMethodConfigurator<?> site, BeanManager bm) { Bean<?> bean = bm.getBeans(site.getAnnotated().getJavaMember().getDeclaringClass()) .stream() .findFirst() .orElseThrow(() -> new IllegalArgumentException("Cannot find bean for annotated gauge " + gaugeName)); return DelegatingGauge.newInstance( site.getAnnotated().getJavaMember(), getReference(bm, bean.getBeanClass(), bean), site.getAnnotated().getJavaMember().getReturnType()); }
/** * Remove all the annotations. * * @return self */ default AnnotatedConstructorConfigurator<T> removeAll() { return remove((a) -> true); }
/** * Remove all the annotations. * * @return self */ default AnnotatedTypeConfigurator<T> removeAll() { return remove((a) -> true); }
private void processInjectionPoints(@Observes ProcessInjectionPoint<?, ?> pip) { Type type = pip.getInjectionPoint().getType(); if (type.equals(Counter.class) || type.equals(Histogram.class) || type.equals(Meter.class) || type.equals(Timer.class)) { pip.configureInjectionPoint().addQualifier(VendorDefined.Literal.INSTANCE); } }
private void registerAnnotatedGauges(@Observes AfterDeploymentValidation adv, BeanManager bm) { LOGGER.log(Level.FINE, () -> "### registerGauges"); MetricRegistry registry = getMetricRegistry(); annotatedGaugeSites.entrySet().forEach(gaugeSite -> { LOGGER.log(Level.FINE, () -> "### gaugeSite " + gaugeSite.toString()); String gaugeName = gaugeSite.getKey(); AnnotatedMethodConfigurator<?> site = gaugeSite.getValue(); DelegatingGauge<?> dg = buildDelegatingGauge(gaugeName, site, bm); Gauge gaugeAnnotation = site.getAnnotated().getAnnotation(Gauge.class); Metadata md = new Metadata(gaugeName, gaugeAnnotation.displayName(), gaugeAnnotation.description(), MetricType.GAUGE, gaugeAnnotation.unit(), toTags(gaugeAnnotation.tags())); LOGGER.log(Level.FINE, () -> String.format("### Registering gauge with metadata %s", md.toString())); registry.register(md, dg); }); annotatedGaugeSites.clear(); }
/** * Remove all the annotations. * * @return self */ default AnnotatedParameterConfigurator<T> removeAll() { return remove((a) -> true); }
/** * Remove all the annotations. * * @return self */ default AnnotatedConstructorConfigurator<T> removeAll() { return remove((a) -> true); }