public final class AnnotationElement
extends java.lang.Object
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();
| Constructor and Description |
|---|
AnnotationElement(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Creates an annotation element to use for dynamically defined events.
|
AnnotationElement(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.util.Map<java.lang.String,java.lang.Object> values)
Creates an annotation element to use for dynamically defined events.
|
AnnotationElement(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.Object value)
Creates an annotation element to use for dynamically defined events.
|
| Modifier and Type | Method and Description |
|---|---|
<A> A |
getAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns the first annotation for the specified type if an
AnnotationElement with the same name exists, else null. |
java.util.List<AnnotationElement> |
getAnnotationElements()
Returns an immutable list of annotation elements for this
AnnotationElement. |
long |
getTypeId()
Returns the type ID for this
AnnotationElement. |
java.lang.String |
getTypeName()
Returns the fully qualified name of the annotation type that corresponds to
this
AnnotationElement (for example, "jdk.jfr.Label"). |
java.lang.Object |
getValue(java.lang.String name)
Returns a value for this
AnnotationElement. |
java.util.List<ValueDescriptor> |
getValueDescriptors()
Returns an immutable list of descriptors that describes the annotation values
for this
AnnotationElement. |
java.util.List<java.lang.Object> |
getValues()
Returns an immutable list of annotation values in an order that matches the
value descriptors for this
AnnotationElement. |
boolean |
hasValue(java.lang.String name)
Returns
true if an annotation value with the specified name exists in
this AnnotationElement. |
public AnnotationElement(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.util.Map<java.lang.String,java.lang.Object> values)
Supported value types are byte, int, short,
long, double, float, boolean, char,
and String. 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 the annotationType and any annotation found recursively
must have the MetadataDefinition annotation.
To statically define events, see Event class.
annotationType - interface extending
java.lang.annotation.Annotation, not nullvalues - a Map with keys that match method names of the specified
annotation interfacejava.lang.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 annotationTypepublic AnnotationElement(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType,
java.lang.Object value)
Supported value types are byte, int, short,
long, double, float, boolean, char,
and String. Enums, arrays, and classes are not supported.
If annotationType has annotations (directly present, indirectly
present, or associated), then those annotations are recursively included.
However, both annotationType and any annotation found recursively
must have the MetadataDefinition annotation.
To statically define events, see Event class.
annotationType - interface extending
java.lang.annotation.Annotation, not nullvalue - the value that matches the value method of the specified
annotationTypejava.lang.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 annotationTypepublic AnnotationElement(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Supported value types are byte, short, int,
long, double, float, boolean, char,
and String. 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 annotationType and any annotation found recursively
must have the MetadataDefinition annotation.
To statically define events, see Event class.
annotationType - interface extending java.lang.annotation.Annotation,
not nullpublic java.util.List<java.lang.Object> getValues()
AnnotationElement.nullpublic java.util.List<ValueDescriptor> getValueDescriptors()
AnnotationElement.Annotation, not
nullpublic java.util.List<AnnotationElement> getAnnotationElements()
AnnotationElement.nullpublic java.lang.String getTypeName()
AnnotationElement (for example, "jdk.jfr.Label").nullpublic java.lang.Object getValue(java.lang.String name)
AnnotationElement.name - the name of the method in the annotation interface, not
null.null.java.lang.IllegalArgumentException - if a method with the specified name does
not exist in the annotationpublic boolean hasValue(java.lang.String name)
true if an annotation value with the specified name exists in
this AnnotationElement.name - name of the method in the annotation interface to find, not
nulltrue if method exists, false otherwisepublic final <A> A getAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
AnnotationElement with the same name exists, else null.A - the type of the annotation to query for and return if it existsannotationType - the Class object corresponding to the annotation type,
not nullnullpublic long getTypeId()
AnnotationElement.
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.