Class AnnotationElement

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 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 Details

    • AnnotationElement

      public 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, 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.

      Parameters:
      annotationType - interface extending java.lang.annotation.Annotation, not null
      values - a Map with 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
    • AnnotationElement

      public 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, 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