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 metricsAnnotation
s from different annotated abstractions providing a common interface to allow generic handling and a common logic independent of the source of theAnnotation
. Supported are:AnnotatedElement
Annotated
InjectionPoint
Annotated
andInjectionPoint
have to be used as a source when available as they allow to add or removeAnnotation
effectively 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_GAUGE
static AnnotationReader<org.eclipse.microprofile.metrics.annotation.Counted>
COUNTED
static AnnotationReader<org.eclipse.microprofile.metrics.annotation.Gauge>
GAUGE
static AnnotationReader<org.eclipse.microprofile.metrics.annotation.Metered>
METERED
static AnnotationReader<org.eclipse.microprofile.metrics.annotation.Metric>
METRIC
static AnnotationReader<org.eclipse.microprofile.metrics.annotation.SimplyTimed>
SIMPLY_TIMED
static AnnotationReader<org.eclipse.microprofile.metrics.annotation.Timed>
TIMED
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
absolute(T annotation)
Returns the metric absolute flag as defined by the providedAnnotation
T
annotation(jakarta.enterprise.inject.spi.InjectionPoint point)
Reads the effectiveAnnotation
for 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 thisAnnotationReader
readsMetric
Annotation
it can be associated with differentMetricType
so that the provided type is used when creatingMetadata
using theAnnotationReader
.String
description(T annotation)
Returns the metric description as defined by the providedAnnotation
String
displayName(T annotation)
Returns the metric display name as defined by the providedAnnotation
boolean
equals(Object obj)
static <T extends Annotation>
AnnotationReader<T>forAnnotation(Class<T> annotationType)
GetAnnotationReader
for 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 theMetric
referred to by the providedInjectionPoint
.int
hashCode()
<E extends Member & AnnotatedElement>
booleanisPresent(Class<?> bean, E element)
Checks if thisAnnotationReader
'sannotationType()
is present either at the providedAnnotatedElement
or the provided beanClass
.boolean
isReference(T annotation)
Checks if anAnnotation
does not provide any information beyond the required name and tags.org.eclipse.microprofile.metrics.Metadata
metadata(jakarta.enterprise.inject.spi.AnnotatedMember<?> member)
Returns the metricMetadata
as defined by the MP specification for the annotation situation at hand for the providedInjectionPoint
.org.eclipse.microprofile.metrics.Metadata
metadata(jakarta.enterprise.inject.spi.InjectionPoint point)
Returns the metricMetadata
as 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.Metadata
metadata(T annotation)
Returns the fullMetadata
as defined by the providedAnnotation
org.eclipse.microprofile.metrics.MetricID
metricID(jakarta.enterprise.inject.spi.AnnotatedMember<?> member)
Returns the metricMetricID
as defined by the MP specification for the annotation situation at hand for the providedInjectionPoint
.org.eclipse.microprofile.metrics.MetricID
metricID(jakarta.enterprise.inject.spi.InjectionPoint point)
Returns the metricMetricID
as 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.MetricID
metricID(T annotation)
Returns theMetricID
as defined by the providedAnnotation
's name and tags attributes.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
.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
.<E extends Member & AnnotatedElement>
Stringname(Class<?> bean, E element)
Reads the effective name for the provided beanClass
andAnnotatedElement
.String
name(T annotation)
Returns the metric name as defined by the providedAnnotation
static Iterable<AnnotationReader<?>>
readers()
org.eclipse.microprofile.metrics.Tag[]
tags(T annotation)
Returns the metric tags as defined by the providedAnnotation
static org.eclipse.microprofile.metrics.Tag[]
tagsFromString(String[] tags)
String
toString()
org.eclipse.microprofile.metrics.MetricType
type()
String
unit(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)
GetAnnotationReader
for a providedAnnotation
.- Parameters:
annotationType
-- Returns:
- The
AnnotationReader
for the providedAnnotation
type - Throws:
IllegalAccessException
- In case no such reader exists
-
readers
public static Iterable<AnnotationReader<?>> readers()
- Returns:
- all available
AnnotationReader
s
-
asType
public AnnotationReader<T> asType(org.eclipse.microprofile.metrics.MetricType type)
If thisAnnotationReader
readsMetric
Annotation
it can be associated with differentMetricType
so that the provided type is used when creatingMetadata
using theAnnotationReader
.- Parameters:
type
- anyMetricType
- Returns:
- A new
AnnotationReader
using the providedMetricType
- Throws:
IllegalStateException
- In case this method is called onAnnotationReader
that is not readingMetric
Annotation
.
-
type
public org.eclipse.microprofile.metrics.MetricType type()
- Returns:
- the
MetricType
used by thisAnnotationReader
when generating aMetadata
object any of the variants of themetadata(Annotation)
methods. Usually eachAnnotation
is associated with a particularMetricType
but forMetric
Annotation
the 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
- aAnnotatedElement
possibly 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 effectiveAnnotation
for the providedInjectionPoint
.- Parameters:
point
- sourceInjectionPoint
for an annotated element having thisAnnotationReader
'sannotationType()
, notnull
- Returns:
- the effective annotation for the provided
InjectionPoint
, nevernull
- Throws:
IllegalArgumentException
- In case the providedInjectionPoint
isn'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 providedAnnotatedElement
or the provided beanClass
.- Parameters:
bean
- type of the bean that declared the provided elementelement
- aAnnotatedElement
possibly 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
- sourceInjectionPoint
for an annotated element having thisAnnotationReader
'sannotationType()
, notnull
- Returns:
- full metric name as required by the MP specification
- Throws:
IllegalArgumentException
- In case the providedInjectionPoint
isn'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
- sourceAnnotatedMember
for an annotated element having thisAnnotationReader
'sannotationType()
, notnull
- Returns:
- full metric name as required by the MP specification
- Throws:
IllegalArgumentException
- In case the providedAnnotatedMember
isn'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 beanClass
andAnnotatedElement
. 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
- aAnnotatedElement
possibly annotated with thisAnnotationReader
'sannotationType()
- Returns:
- full metric name as required by the MP specification
- Throws:
IllegalArgumentException
- In case neither theAnnotatedElement
or theClass
isn'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 theMetricID
as defined by the providedAnnotation
's name and tags attributes.- Parameters:
annotation
- source annotation to read, notnull
- Returns:
MetricID
value of the provided source annotation
-
metricID
public org.eclipse.microprofile.metrics.MetricID metricID(jakarta.enterprise.inject.spi.InjectionPoint point)
Returns the metricMetricID
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
- sourceInjectionPoint
for an annotated element having thisAnnotationReader
'sannotationType()
, notnull
- Returns:
MetricID
with full metric name as required by the MP specification- Throws:
IllegalArgumentException
- In case the providedInjectionPoint
isn't effectively annotated with thisAnnotationReader
'sAnnotation
.
-
metricID
public org.eclipse.microprofile.metrics.MetricID metricID(jakarta.enterprise.inject.spi.AnnotatedMember<?> member)
Returns the metricMetricID
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
- sourceAnnotatedMember
for an annotated element having thisAnnotationReader
'sannotationType()
, notnull
- Returns:
MetricID
with full metric name as required by the MP specification- Throws:
IllegalArgumentException
- In case the providedAnnotatedMember
isn't effectively annotated with thisAnnotationReader
'sAnnotation
.
-
metricID
public <E extends Member & AnnotatedElement> org.eclipse.microprofile.metrics.MetricID metricID(Class<?> bean, E element)
Reads the effectiveMetricID
for the provided beanClass
andAnnotatedElement
. 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
- aAnnotatedElement
possibly annotated with thisAnnotationReader
'sannotationType()
- Returns:
MetricID
with full metric name as required by the MP specification- Throws:
IllegalArgumentException
- In case neither theAnnotatedElement
or theClass
isn'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 fullMetadata
as defined by the providedAnnotation
- Parameters:
annotation
- source annotation to read, notnull
- Returns:
Metadata
of the provided source annotation
-
metadata
public org.eclipse.microprofile.metrics.Metadata metadata(jakarta.enterprise.inject.spi.InjectionPoint point)
Returns the metricMetadata
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
- sourceInjectionPoint
for an annotated element having thisAnnotationReader
'sannotationType()
, notnull
- Returns:
Metadata
with full metric name as required by the MP specification- Throws:
IllegalArgumentException
- In case the providedInjectionPoint
isn't effectively annotated with thisAnnotationReader
'sAnnotation
.
-
metadata
public org.eclipse.microprofile.metrics.Metadata metadata(jakarta.enterprise.inject.spi.AnnotatedMember<?> member)
Returns the metricMetadata
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
- sourceAnnotatedMember
for an annotated element having thisAnnotationReader
'sannotationType()
, notnull
- Returns:
Metadata
with full metric name as required by the MP specification- Throws:
IllegalArgumentException
- In case the providedAnnotatedMember
isn't effectively annotated with thisAnnotationReader
'sAnnotation
.
-
metadata
public <E extends Member & AnnotatedElement> org.eclipse.microprofile.metrics.Metadata metadata(Class<?> bean, E element)
Reads the effectiveMetadata
for the provided beanClass
andAnnotatedElement
. 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
- aAnnotatedElement
possibly annotated with thisAnnotationReader
'sannotationType()
- Returns:
Metadata
with full metric name as required by the MP specification- Throws:
IllegalArgumentException
- In case neither theAnnotatedElement
or theClass
isn't annotated with thisAnnotationReader
'sAnnotation
.
-
isReference
public boolean isReference(T annotation)
Checks if anAnnotation
does 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
Metadata
when 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 theMetric
referred 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 effectiveAnnotation
for the providedInjectionPoint
the metric is resolved or registered usingMetadata
, name andTag
s or just its name. AGauge
can only be resolved, not created.- Parameters:
point
- sourceInjectionPoint
for an annotated element having thisAnnotationReader
'sannotationType()
, notnull
metric
- type of theMetric
to find or create, notnull
registry
-MetricRegistry
to use, notnull
- Returns:
- the resolved or registered metric, or
null
if aGauge
did not exist
-
tagsFromString
public static org.eclipse.microprofile.metrics.Tag[] tagsFromString(String[] tags)
-
-