- java.lang.Object
- 
- jdk.jfr.AnnotationElement
 
- 
 public final class AnnotationElement extends Object Describes event metadata, such as labels, descriptions and units.The following example shows how AnnotationElementcan 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 SummaryConstructors Constructor Description AnnotationElement(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 SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description <A> AgetAnnotation(Class<? extends Annotation> annotationType)Returns the first annotation for the specified type if anAnnotationElementwith the same name exists, elsenull.List<AnnotationElement>getAnnotationElements()Returns an immutable list of annotation elements for thisAnnotationElement.longgetTypeId()Returns the type ID for thisAnnotationElement.StringgetTypeName()Returns the fully qualified name of the annotation type that corresponds to thisAnnotationElement(for example,"jdk.jfr.Label").ObjectgetValue(String name)Returns a value for thisAnnotationElement.List<ValueDescriptor>getValueDescriptors()Returns an immutable list of descriptors that describes the annotation values for thisAnnotationElement.List<Object>getValues()Returns an immutable list of annotation values in an order that matches the value descriptors for thisAnnotationElement.booleanhasValue(String name)Returnstrueif an annotation value with the specified name exists in thisAnnotationElement.
 
- 
- 
- 
Constructor Detail- 
AnnotationElementpublic AnnotationElement(Class<? extends Annotation> annotationType, Map<String,Object> values) 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 annotationTypehas annotations (directly present, indirectly present, or associated), then those annotation are recursively included. However, both theannotationTypeand any annotation found recursively must have theMetadataDefinitionannotation.To statically define events, see Eventclass.- Parameters:
- annotationType- interface extending- java.lang.annotation.Annotation, not- null
- values- a- Mapwith keys that match method names of the specified annotation interface
- Throws:
- IllegalArgumentException- if value/key is- null, an unsupported value type is used, or a value/key is used that doesn't match the signatures in the- annotationType
 
 - 
AnnotationElementpublic AnnotationElement(Class<? extends Annotation> annotationType, Object value) 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 annotationTypehas annotations (directly present, indirectly present, or associated), then those annotations are recursively included. However, bothannotationTypeand any annotation found recursively must have theMetadataDefinitionannotation.To statically define events, see Eventclass.- Parameters:
- annotationType- interface extending- java.lang.annotation.Annotation,not- null
- value- the value that matches the- valuemethod of the specified- annotationType
- Throws:
- IllegalArgumentException- if value/key is- null, an unsupported value type is used, or a value/key is used that doesn't match the signatures in the- annotationType
 
 - 
AnnotationElementpublic AnnotationElement(Class<? extends Annotation> annotationType) Creates an annotation element to use for dynamically defined events.Supported value types are byte,short,int,long,double,float,boolean,char, andString. Enums, arrays, and classes are not supported.If annotationTypehas annotations (directly present, indirectly present or associated), then those annotation are recursively included. However, bothannotationTypeand any annotation found recursively must have theMetadataDefinitionannotation.To statically define events, see Eventclass.- Parameters:
- annotationType- interface extending java.lang.annotation.Annotation, not- null
 
 
- 
 - 
Method Detail- 
getValuespublic List<Object> getValues() Returns an immutable list of annotation values in an order that matches the value descriptors for thisAnnotationElement.- Returns:
- list of values, not null
 
 - 
getValueDescriptorspublic List<ValueDescriptor> getValueDescriptors() Returns an immutable list of descriptors that describes the annotation values for thisAnnotationElement.- Returns:
- the list of value descriptors for this Annotation, notnull
 
 - 
getAnnotationElementspublic List<AnnotationElement> getAnnotationElements() Returns an immutable list of annotation elements for thisAnnotationElement.- Returns:
- a list of meta annotation, not null
 
 - 
getTypeNamepublic String getTypeName() Returns the fully qualified name of the annotation type that corresponds to thisAnnotationElement(for example,"jdk.jfr.Label").- Returns:
- type name, not null
 
 - 
getValuepublic Object getValue(String name) Returns a value for thisAnnotationElement.- Parameters:
- name- the name of the method in the annotation interface, not- null.
- Returns:
- the annotation value, not null.
- Throws:
- IllegalArgumentException- if a method with the specified name does not exist in the annotation
 
 - 
hasValuepublic boolean hasValue(String name) Returnstrueif an annotation value with the specified name exists in thisAnnotationElement.- Parameters:
- name- name of the method in the annotation interface to find, not- null
- Returns:
- trueif method exists,- falseotherwise
 
 - 
getAnnotationpublic final <A> A getAnnotation(Class<? extends Annotation> annotationType) Returns the first annotation for the specified type if anAnnotationElementwith the same name exists, elsenull.- Type Parameters:
- A- the type of the annotation to query for and return if it exists
- Parameters:
- annotationType- the- Class objectcorresponding to the annotation type, not- null
- Returns:
- this element's annotation for the specified annotation type if
         it it exists, else null
 
 - 
getTypeIdpublic long getTypeId() Returns the type ID for thisAnnotationElement.The ID is a unique identifier for the type in the Java Virtual Machine (JVM). The ID might not be the same between JVM instances. - Returns:
- the type ID, not negative
 
 
- 
 
-