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> AgetAnnotation(Class<? extends Annotation> annotationType) Returns the first annotation for the specified type if anAnnotationElementwith the same name exists, elsenull.Returns an immutable list of annotation elements for thisAnnotationElement.longReturns 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.booleanReturnstrueif an annotation value with the specified name exists in thisAnnotationElement.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
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
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 extendingjava.lang.annotation.Annotation, notnullvalues- aMapwith 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
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 extendingjava.lang.annotation.Annotation,notnullvalue- the value that matches thevaluemethod of the specifiedannotationType- 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,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, notnull
-
-
Method Details
-
getValues
-
getValueDescriptors
Returns an immutable list of descriptors that describes the annotation values for thisAnnotationElement.- Returns:
- the list of value descriptors for this
Annotation, notnull
-
getAnnotationElements
Returns an immutable list of annotation elements for thisAnnotationElement.- Returns:
- a list of meta annotation, not
null
-
getTypeName
Returns the fully qualified name of the annotation type that corresponds to thisAnnotationElement(for example,"jdk.jfr.Label").- Returns:
- type name, not
null
-
getValue
Returns a value for thisAnnotationElement.- Parameters:
name- the name of the method in the annotation interface, notnull.- Returns:
- the annotation value, not
null. - Throws:
IllegalArgumentException- if a method with the specified name does not exist in the annotation
-
hasValue
Returnstrueif an annotation value with the specified name exists in thisAnnotationElement.- Parameters:
name- name of the method in the annotation interface to find, notnull- Returns:
trueif method exists,falseotherwise
-
getAnnotation
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- theClass objectcorresponding to the annotation type, notnull- Returns:
- this element's annotation for the specified annotation type if
it exists, else
null
-
getTypeId
public 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
-