Class AnnotationElement
The following example shows how AnnotationElement
can be used to dynamically define events.
List<AnnotationElement> typeAnnotations = new ArrayList<>();
typeAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld"));
typeAnnotations.add(new AnnotationElement(Label.class, "Hello World"));
typeAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started"));
List<AnnotationElement> fieldAnnotations = new ArrayList<>();
fieldAnnotations.add(new AnnotationElement(Label.class, "Message"));
List<ValueDescriptor> fields = new ArrayList<>();
fields.add(new ValueDescriptor(String.class, "message", fieldAnnotations));
EventFactory f = EventFactory.create(typeAnnotations, fields);
Event event = f.newEvent();
event.commit();
- Since:
- 9
-
Constructor Summary
ConstructorsConstructorDescriptionAnnotationElement
(Class<? extends Annotation> annotationType) Creates an annotation element to use for dynamically defined events.AnnotationElement
(Class<? extends Annotation> annotationType, Object value) Creates an annotation element to use for dynamically defined events.AnnotationElement
(Class<? extends Annotation> annotationType, Map<String, Object> values) Creates an annotation element to use for dynamically defined events. -
Method Summary
Modifier and TypeMethodDescriptionfinal <A> A
getAnnotation
(Class<? extends Annotation> annotationType) Returns the first annotation for the specified type if anAnnotationElement
with the same name exists, elsenull
.Returns an immutable list of annotation elements for thisAnnotationElement
.long
Returns the type ID for thisAnnotationElement
.Returns the fully qualified name of the annotation type that corresponds to thisAnnotationElement
(for example,"jdk.jfr.Label"
).Returns a value for thisAnnotationElement
.Returns an immutable list of descriptors that describes the annotation values for thisAnnotationElement
.Returns an immutable list of annotation values in an order that matches the value descriptors for thisAnnotationElement
.boolean
Returnstrue
if an annotation value with the specified name exists in thisAnnotationElement
.
-
Constructor Details
-
AnnotationElement
Creates an annotation element to use for dynamically defined events.Supported value types are
byte
,int
,short
,long
,double
,float
,boolean
,char
, andString
. Enums, arrays and classes, are not supported.If
annotationType
has annotations (directly present, indirectly present, or associated), then those annotation are recursively included. However, both theannotationType
and any annotation found recursively must have theMetadataDefinition
annotation.To statically define events, see
Event
class.- Parameters:
annotationType
- interface extendingjava.lang.annotation.Annotation
, notnull
values
- aMap
with keys that match method names of the specified annotation interface- Throws:
IllegalArgumentException
- if value/key isnull
, an unsupported value type is used, or a value/key is used that doesn't match the signatures in theannotationType
-
AnnotationElement
Creates an annotation element to use for dynamically defined events.Supported value types are
byte
,int
,short
,long
,double
,float
,boolean
,char
, andString
. Enums, arrays, and classes are not supported.If
annotationType
has annotations (directly present, indirectly present, or associated), then those annotations are recursively included. However, bothannotationType
and any annotation found recursively must have the
-