Class AnnotationReader<T extends Annotation>
- java.lang.Object
-
- fish.payara.microprofile.metrics.cdi.AnnotationReader<T>
-
- Type Parameters:
T- Type of the MP metrics annotation
public final class AnnotationReader<T extends Annotation> extends Object
Utility that allows reading the different MP metricsAnnotations from different annotated abstractions providing a common interface to allow generic handling and a common logic independent of the source of theAnnotation. Supported are:AnnotatedElementAnnotatedInjectionPoint
AnnotatedandInjectionPointhave to be used as a source when available as they allow to add or removeAnnotationeffectively acting as a runtime override of the compiled information provided byAnnotatedElement. This utility also encodes most of the logic as defined by the MP Metrics specification. This includes the logic of which annotation applied and how the metrics effective name if computed from annotation values and the annotated element. For this reason the methods are documented in great detail.- Since:
- 5.202
- Author:
- Jan Bernitt
-
-
Field Summary
Fields Modifier and Type Field Description static AnnotationReader<org.eclipse.microprofile.metrics.annotation.ConcurrentGauge>CONCURRENT_GAUGEstatic AnnotationReader<org.eclipse.microprofile.metrics.annotation.Counted>COUNTEDstatic AnnotationReader<org.eclipse.microprofile.metrics.annotation.Gauge>GAUGEstatic AnnotationReader<org.eclipse.microprofile.metrics.annotation.Metered>METEREDstatic AnnotationReader<org.eclipse.microprofile.metrics.annotation.Metric>METRICstatic AnnotationReader<org.eclipse.microprofile.metrics.annotation.SimplyTimed>SIMPLY_TIMEDstatic AnnotationReader<org.eclipse.microprofile.metrics.annotation.Timed>TIMED
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanabsolute(T annotation)Returns the metric absolute flag as defined by the providedAnnotationTannotation(jakarta.enterprise.inject.spi.InjectionPoint point)Reads the effectiveAnnotationfor the providedInjectionPoint.<E extends Member & AnnotatedElement>
Tannotation(Class<?> bean, E element)Returns the effective annotation for the provided bean and element.Class<T>annotationType()AnnotationReader<T>asType(org.eclipse.microprofile.metrics.MetricType type)If thisAnnotationReaderreadsMetricAnnotationit can be associated with differentMetricTypeso that the provided type is used when creatingMetadatausing theAnnotationReader.Stringdescription(T annotation)Returns the metric description as defined by the providedAnnotationStringdisplayName(T annotation)Returns the metric display name as defined by the providedAnnotationbooleanequals(Object obj)static <T extends Annotation>
AnnotationReader<T>forAnnotation(Class<T> annotationType)GetAnnotationReaderfor a providedAnnotation.<M extends org.eclipse.microprofile.metrics.Metric>
MgetOrRegister(jakarta.enterprise.inject.spi.InjectionPoint point, Class<M> metric, org.eclipse.microprofile.metrics.MetricRegistry registry)Resolves theMetricreferred to by the providedInjectionPoint.inthashCode()<E extends Member & AnnotatedElement>
booleanisPresent(Class<?> bean, E element)Checks if thisAnnotationReader'sannotationType()is present either at the providedAnnotatedElementor the provided beanClass.booleanisReference(T annotation)Checks if anAnnotationdoes not provide any information beyond the required name and tags.org.eclipse.microprofile.metrics.Metadatametadata(jakarta.enterprise.inject.spi.AnnotatedMember<?> member)Returns the metricMetadataas defined by the MP specification for the annotation situation at hand for the providedInjectionPoint.org.eclipse.microprofile.metrics.Metadatametadata(jakarta.enterprise.inject.spi.InjectionPoint point)Returns the metricMetadataas defined by the MP specification for the annotation situation at hand for the providedInjectionPoint.<E extends Member & AnnotatedElement>
org.eclipse.microprofile.metrics.Metadatametadata(Class<?> bean, E element)org.eclipse.microprofile.metrics.Metadatametadata(T annotation)Returns the fullMetadataas defined by the providedAnnotationorg.eclipse.microprofile.metrics.MetricIDmetricID(jakarta.enterprise.inject.spi.AnnotatedMember<?> member)Returns the metricMetricIDas defined by the MP specification for the annotation situation at hand for the providedInjectionPoint.org.eclipse.microprofile.metrics.MetricIDmetricID(jakarta.enterprise.inject.spi.InjectionPoint point)Returns the metricMetricIDas defined by the MP specification for the annotation situation at hand for the providedInjectionPoint.<E extends Member & AnnotatedElement>
org.eclipse.microprofile.metrics.MetricIDmetricID(Class<?> bean, E element)org.eclipse.microprofile.metrics.MetricIDmetricID(T annotation)Returns theMetricIDas defined by the providedAnnotation's name and tags attributes.Stringname(jakarta.enterprise.inject.spi.AnnotatedMember<?> member)Returns the metric name as defined by the MP specification for the annotation situation at hand for the providedAnnotatedMember.Stringname(jakarta.enterprise.inject.spi.InjectionPoint point)Returns the metric name as defined by the MP specification for the annotation situation at hand for the providedInjectionPoint.<E extends Member & AnnotatedElement>
Stringname(Class<?> bean, E element)Reads the effective name for the provided beanClassandAnnotatedElement.Stringname(T annotation)Returns the metric name as defined by the providedAnnotationstatic Iterable<AnnotationReader<?>>readers()org.eclipse.microprofile.metrics.Tag[]tags(T annotation)Returns the metric tags as defined by the providedAnnotationstatic org.eclipse.microprofile.metrics.Tag[]tagsFromString(String[] tags)StringtoString()org.eclipse.microprofile.metrics.MetricTypetype()Stringunit(T annotation)Returns the metric unit as defined by the providedAnnotation
-
-
-
Field Detail
-
CONCURRENT_GAUGE
public static final AnnotationReader<org.eclipse.microprofile.metrics.annotation.ConcurrentGauge> CONCURRENT_GAUGE
-
COUNTED
public static final AnnotationReader<org.eclipse.microprofile.metrics.annotation.Counted> COUNTED
-
GAUGE
public static final AnnotationReader<org.eclipse.microprofile.metrics.annotation.Gauge> GAUGE
-
METERED
public static final AnnotationReader<org.eclipse.microprofile.metrics.annotation.Metered> METERED
-
METRIC
public static final AnnotationReader<org.eclipse.microprofile.metrics.annotation.Metric> METRIC
-
TIMED
public static final AnnotationReader<org.eclipse.microprofile.metrics.annotation.Timed> TIMED
-
SIMPLY_TIMED
public static final AnnotationReader<org.eclipse.microprofile.metrics.annotation.SimplyTimed> SIMPLY_TIMED
-
-
Method Detail
-
forAnnotation
public static <T extends Annotation> AnnotationReader<T> forAnnotation(Class<T> annotationType)
GetAnnotationReaderfor a providedAnnotation.- Parameters:
annotationType-- Returns:
- The
AnnotationReaderfor the providedAnnotationtype - Throws:
IllegalAccessException- In case no such reader exists
-
readers
public static Iterable<AnnotationReader<?>> readers()
- Returns:
- all available
AnnotationReaders
-
asType
public AnnotationReader<T> asType(org.eclipse.microprofile.metrics.MetricType type)
If thisAnnotationReaderreadsMetricAnnotationit can be associated with differentMetricTypeso that the provided type is used when creatingMetadatausing theAnnotationReader.- Parameters:
type- anyMetricType- Returns:
- A new
AnnotationReaderusing the providedMetricType - Throws:
IllegalStateException- In case this method is called onAnnotationReaderthat is not readingMetricAnnotation.
-
type
public org.eclipse.microprofile.metrics.MetricType type()
- Returns:
- the
MetricTypeused by thisAnnotationReaderwhen generating aMetadataobject any of the variants of themetadata(Annotation)methods. Usually eachAnnotationis associated with a particularMetricTypebut forMetricAnnotationthe type can be changed using#asType(Class)methods.
-
annotation
public <E extends Member & AnnotatedElement> T annotation(Class<?> bean, E element)
Returns the effective annotation for the provided bean and element.- Parameters:
bean- type of the bean that declared the provided elementelement- aAnnotatedElementpossibly annotated with thisAnnotationReader'sannotationType()- Returns:
- the effective
Annotation, ornull. The element's annotations take precedence over the bean's annotations.
-
annotation
public T annotation(jakarta.enterprise.inject.spi.InjectionPoint point)
Reads the effectiveAnnotationfor the providedInjectionPoint.- Parameters:
point- sourceInjectionPointfor an annotated element having thisAnnotationReader'sannotationType(), notnull- Returns:
- the effective annotation for the provided
InjectionPoint, nevernull - Throws:
IllegalArgumentException- In case the providedInjectionPointisn't effectively annotated with thisAnnotationReader'sAnnotation.
-
isPresent
public <E extends Member & AnnotatedElement> boolean isPresent(Class<?> bean, E element)
Checks if thisAnnotationReader'sannotationType()is present either at the providedAnnotatedElementor the provided beanClass.- Parameters:
bean- type of the bean that declared the provided elementelement- aAnnotatedElementpossibly annotated with thisAnnotationReader'sannotationType()- Returns:
- true, if provided element or bean are annotated with this
AnnotationReader'sannotationType(), else false.
-
name
public String name(T annotation)
Returns the metric name as defined by the providedAnnotation- Parameters:
annotation- source annotation to read, notnull- Returns:
- name value of the provided source annotation
-
name
public String name(jakarta.enterprise.inject.spi.InjectionPoint point)
Returns the metric name as defined by the MP specification for the annotation situation at hand for the providedInjectionPoint. This does take into account that annotations might have been added or removed at runtime.- Parameters:
point- sourceInjectionPointfor an annotated element having thisAnnotationReader'sannotationType(), notnull- Returns:
- full metric name as required by the MP specification
- Throws:
IllegalArgumentException- In case the providedInjectionPointisn't effectively annotated with thisAnnotationReader'sAnnotation.
-
name
public String name(jakarta.enterprise.inject.spi.AnnotatedMember<?> member)
Returns the metric name as defined by the MP specification for the annotation situation at hand for the providedAnnotatedMember. This does take into account that annotations might have been added or removed at runtime.- Parameters:
member- sourceAnnotatedMemberfor an annotated element having thisAnnotationReader'sannotationType(), notnull- Returns:
- full metric name as required by the MP specification
- Throws:
IllegalArgumentException- In case the providedAnnotatedMemberisn't effectively annotated with thisAnnotationReader'sAnnotation.
-
name
public <E extends Member & AnnotatedElement> String name(Class<?> bean, E element)
Reads the effective name for the provided beanClassandAnnotatedElement. Either bean or element must have thisAnnotationReader'sAnnotation.- Parameters:
bean- type of the bean that declared the provided element possibly annotated with thisAnnotationReader'sannotationType()element- aAnnotatedElementpossibly annotated with thisAnnotationReader'sannotationType()- Returns:
- full metric name as required by the MP specification
- Throws:
IllegalArgumentException- In case neither theAnnotatedElementor theClassisn't annotated with thisAnnotationReader'sAnnotation.
-
tags
public org.eclipse.microprofile.metrics.Tag[] tags(T annotation)
Returns the metric tags as defined by the providedAnnotation- Parameters:
annotation- source annotation to read, notnull- Returns:
- tags value of the provided source annotation
-
metricID
public org.eclipse.microprofile.metrics.MetricID metricID(T annotation)
Returns theMetricIDas defined by the providedAnnotation's name and tags attributes.- Parameters:
annotation- source annotation to read, notnull- Returns:
MetricIDvalue of the provided source annotation
-
metricID
public org.eclipse.microprofile.metrics.MetricID metricID(jakarta.enterprise.inject.spi.InjectionPoint point)
Returns the metricMetricIDas defined by the MP specification for the annotation situation at hand for the providedInjectionPoint. This does take into account that annotations might have been added or removed at runtime.- Parameters:
point- sourceInjectionPointfor an annotated element having thisAnnotationReader'sannotationType(), notnull- Returns:
MetricIDwith full metric name as required by the MP specification- Throws:
IllegalArgumentException- In case the providedInjectionPointisn't effectively annotated with thisAnnotationReader'sAnnotation.
-
metricID
public org.eclipse.microprofile.metrics.MetricID metricID(jakarta.enterprise.inject.spi.AnnotatedMember<?> member)
Returns the metricMetricIDas defined by the MP specification for the annotation situation at hand for the providedInjectionPoint. This does take into account that annotations might have been added or removed at runtime.- Parameters:
point- sourceAnnotatedMemberfor an annotated element having thisAnnotationReader'sannotationType(), notnull- Returns:
MetricIDwith full metric name as required by the MP specification- Throws:
IllegalArgumentException- In case the providedAnnotatedMemberisn't effectively annotated with thisAnnotationReader'sAnnotation.
-
metricID
public <E extends Member & AnnotatedElement> org.eclipse.microprofile.metrics.MetricID metricID(Class<?> bean, E element)
Reads the effectiveMetricIDfor the provided beanClassandAnnotatedElement. Either bean or element must have thisAnnotationReader'sAnnotation.- Parameters:
bean- type of the bean that declared the provided element possibly annotated with thisAnnotationReader'sannotationType()element- aAnnotatedElementpossibly annotated with thisAnnotationReader'sannotationType()- Returns:
MetricIDwith full metric name as required by the MP specification- Throws:
IllegalArgumentException- In case neither theAnnotatedElementor theClassisn't annotated with thisAnnotationReader'sAnnotation.
-
displayName
public String displayName(T annotation)
Returns the metric display name as defined by the providedAnnotation- Parameters:
annotation- source annotation to read, notnull- Returns:
- display name value of the provided source annotation
-
description
public String description(T annotation)
Returns the metric description as defined by the providedAnnotation- Parameters:
annotation- source annotation to read, notnull- Returns:
- description of the provided source annotation
-
unit
public String unit(T annotation)
Returns the metric unit as defined by the providedAnnotation- Parameters:
annotation- source annotation to read, notnull- Returns:
- unit of the provided source annotation
-
absolute
public boolean absolute(T annotation)
Returns the metric absolute flag as defined by the providedAnnotation- Parameters:
annotation- source annotation to read, notnull- Returns:
- absolute flag of the provided source annotation
-
metadata
public org.eclipse.microprofile.metrics.Metadata metadata(T annotation)
Returns the fullMetadataas defined by the providedAnnotation- Parameters:
annotation- source annotation to read, notnull- Returns:
Metadataof the provided source annotation
-
metadata
public org.eclipse.microprofile.metrics.Metadata metadata(jakarta.enterprise.inject.spi.InjectionPoint point)
Returns the metricMetadataas defined by the MP specification for the annotation situation at hand for the providedInjectionPoint. This does take into account that annotations might have been added or removed at runtime.- Parameters:
point- sourceInjectionPointfor an annotated element having thisAnnotationReader'sannotationType(), notnull- Returns:
Metadatawith full metric name as required by the MP specification- Throws:
IllegalArgumentException- In case the providedInjectionPointisn't effectively annotated with thisAnnotationReader'sAnnotation.
-
metadata
public org.eclipse.microprofile.metrics.Metadata metadata(jakarta.enterprise.inject.spi.AnnotatedMember<?> member)
Returns the metricMetadataas defined by the MP specification for the annotation situation at hand for the providedInjectionPoint. This does take into account that annotations might have been added or removed at runtime.- Parameters:
point- sourceAnnotatedMemberfor an annotated element having thisAnnotationReader'sannotationType(), notnull- Returns:
Metadatawith full metric name as required by the MP specification- Throws:
IllegalArgumentException- In case the providedAnnotatedMemberisn't effectively annotated with thisAnnotationReader'sAnnotation.
-
metadata
public <E extends Member & AnnotatedElement> org.eclipse.microprofile.metrics.Metadata metadata(Class<?> bean, E element)
Reads the effectiveMetadatafor the provided beanClassandAnnotatedElement. Either bean or element must have thisAnnotationReader'sAnnotation.- Parameters:
bean- type of the bean that declared the provided element possibly annotated with thisAnnotationReader'sannotationType()element- aAnnotatedElementpossibly annotated with thisAnnotationReader'sannotationType()- Returns:
Metadatawith full metric name as required by the MP specification- Throws:
IllegalArgumentException- In case neither theAnnotatedElementor theClassisn't annotated with thisAnnotationReader'sAnnotation.
-
isReference
public boolean isReference(T annotation)
Checks if anAnnotationdoes not provide any information beyond the required name and tags.- Parameters:
annotation- source annotation to read, notnull- Returns:
- true, of no property is set to a value that would require using
Metadatawhen registering, else false.
-
getOrRegister
public <M extends org.eclipse.microprofile.metrics.Metric> M getOrRegister(jakarta.enterprise.inject.spi.InjectionPoint point, Class<M> metric, org.eclipse.microprofile.metrics.MetricRegistry registry)Resolves theMetricreferred to by the providedInjectionPoint. If it does not exist, the metric is created. Lookup and creation are one atomic operation. Depending on the provided information in the effectiveAnnotationfor the providedInjectionPointthe metric is resolved or registered usingMetadata, name andTags or just its name. AGaugecan only be resolved, not created.- Parameters:
point- sourceInjectionPointfor an annotated element having thisAnnotationReader'sannotationType(), notnullmetric- type of theMetricto find or create, notnullregistry-MetricRegistryto use, notnull- Returns:
- the resolved or registered metric, or
nullif aGaugedid not exist
-
tagsFromString
public static org.eclipse.microprofile.metrics.Tag[] tagsFromString(String[] tags)
-
-