jdk.jfr.Label Java Examples

The following examples show how to use jdk.jfr.Label. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestConstructor.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    ValueDescriptor vdSimple = new ValueDescriptor(String.class, "message");
    Asserts.assertNull(vdSimple.getAnnotation(Label.class), "Expected getAnnotation()==null");
    Asserts.assertEquals(0, vdSimple.getAnnotationElements().size(), "Expected getAnnotations().size() == 0");

    // Add labelA and verify we can read it back
    List<AnnotationElement> annos = new ArrayList<>();
    AnnotationElement labelA = new AnnotationElement(Label.class, "labelA");
    annos.add(labelA);
    System.out.println("labelA.getClass()" + labelA.getClass());
    ValueDescriptor vdComplex = new ValueDescriptor(String.class, "message", annos);

    final Label outLabel = vdComplex.getAnnotation(Label.class);
    Asserts.assertFalse(outLabel == null, "getLabel(Label.class) was null");
    System.out.println("outLabel.value() = " + outLabel.value());

    // Get labelA from getAnnotations() list
    Asserts.assertEquals(1, vdComplex.getAnnotationElements().size(), "Expected getAnnotations().size() == 1");
    final AnnotationElement outAnnotation = vdComplex.getAnnotationElements().get(0);
    Asserts.assertNotNull(outAnnotation, "outAnnotation was null");
    System.out.printf("Annotation: %s = %s%n", outAnnotation.getTypeName(), outAnnotation.getValue("value"));
    Asserts.assertEquals(outAnnotation, labelA, "Expected firstAnnotation == labelA");

}
 
Example #2
Source File: TestGetAnnotation.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Label al = annotatedType.getAnnotation(Label.class);
    Asserts.assertNull(al); // we should not inherit annotation from type

    Description ad = annotatedType.getAnnotation(Description.class);
    Asserts.assertNull(ad); // we should not inherit annotation from type

    Timestamp at = annotatedType.getAnnotation(Timestamp.class);
    Asserts.assertNull(at); // we should not inherit annotation from type

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Label nl = newName.getAnnotation(Label.class);
    Asserts.assertEquals(nl.value(), "Annotated Method");

    Description nd = newName.getAnnotation(Description.class);
    Asserts.assertEquals(nd.value(), "Description of an annotated method");

    Timespan nt = newName.getAnnotation(Timespan.class);
    Asserts.assertEquals(nt.value(), Timespan.NANOSECONDS);
}
 
Example #3
Source File: TestLabel.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Event
    EventType t = EventType.getEventType(LabelEvent.class);
    Asserts.assertEquals(t.getLabel(), "Event Label", "Incorrect label for event");

    // Field
    ValueDescriptor field = t.getField("labledField");
    Asserts.assertEquals(field.getLabel(), "Field Label", "Incorrect label for field");

    // Annotation
    AnnotationElement awl = Events.getAnnotationByName(t, AnnotionWithLabel.class.getName());
    Label label = awl.getAnnotation(Label.class);
    Asserts.assertEquals(label.value(), "Annotation Label", "Incorrect label for annotation");

    // Setting
    for (SettingDescriptor v: t.getSettingDescriptors()) {
        if (v.getName().equals("dummy")) {
            Label settingLabel = v.getAnnotation(Label.class);
            Asserts.assertEquals(settingLabel.value(), "Setting Label", "Incorrect label for setting");
        }
    }
}
 
Example #4
Source File: TestConstructor.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    ValueDescriptor vdSimple = new ValueDescriptor(String.class, "message");
    Asserts.assertNull(vdSimple.getAnnotation(Label.class), "Expected getAnnotation()==null");
    Asserts.assertEquals(0, vdSimple.getAnnotationElements().size(), "Expected getAnnotations().size() == 0");

    // Add labelA and verify we can read it back
    List<AnnotationElement> annos = new ArrayList<>();
    AnnotationElement labelA = new AnnotationElement(Label.class, "labelA");
    annos.add(labelA);
    System.out.println("labelA.getClass()" + labelA.getClass());
    ValueDescriptor vdComplex = new ValueDescriptor(String.class, "message", annos);

    final Label outLabel = vdComplex.getAnnotation(Label.class);
    Asserts.assertFalse(outLabel == null, "getLabel(Label.class) was null");
    System.out.println("outLabel.value() = " + outLabel.value());

    // Get labelA from getAnnotations() list
    Asserts.assertEquals(1, vdComplex.getAnnotationElements().size(), "Expected getAnnotations().size() == 1");
    final AnnotationElement outAnnotation = vdComplex.getAnnotationElements().get(0);
    Asserts.assertNotNull(outAnnotation, "outAnnotation was null");
    System.out.printf("Annotation: %s = %s%n", outAnnotation.getTypeName(), outAnnotation.getValue("value"));
    Asserts.assertEquals(outAnnotation, labelA, "Expected firstAnnotation == labelA");

}
 
Example #5
Source File: TestDynamicAnnotations.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void testEventFactoryExample() throws IOException {
     List<ValueDescriptor> fields = new ArrayList<>();
     List<AnnotationElement> messageAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Message"));
     fields.add(new ValueDescriptor(String.class, "message", messageAnnotations));
     List<AnnotationElement> numberAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Number"));
     fields.add(new ValueDescriptor(int.class, "number", numberAnnotations));

     String[] category = { "Example", "Getting Started" };
     List<AnnotationElement> eventAnnotations = new ArrayList<>();
     eventAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld"));
     eventAnnotations.add(new AnnotationElement(Label.class, "Hello World"));
     eventAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started"));
     eventAnnotations.add(new AnnotationElement(Category.class, category));

     EventFactory f = EventFactory.create(eventAnnotations, fields);

     Event event = f.newEvent();
     event.set(0, "hello, world!");
     event.set(1, 4711);
     event.commit();
}
 
Example #6
Source File: TestDynamicAnnotations.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void testEventFactoryExample() throws IOException {
     List<ValueDescriptor> fields = new ArrayList<>();
     List<AnnotationElement> messageAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Message"));
     fields.add(new ValueDescriptor(String.class, "message", messageAnnotations));
     List<AnnotationElement> numberAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Number"));
     fields.add(new ValueDescriptor(int.class, "number", numberAnnotations));

     String[] category = { "Example", "Getting Started" };
     List<AnnotationElement> eventAnnotations = new ArrayList<>();
     eventAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld"));
     eventAnnotations.add(new AnnotationElement(Label.class, "Hello World"));
     eventAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started"));
     eventAnnotations.add(new AnnotationElement(Category.class, category));

     EventFactory f = EventFactory.create(eventAnnotations, fields);

     Event event = f.newEvent();
     event.set(0, "hello, world!");
     event.set(1, 4711);
     event.commit();
}
 
Example #7
Source File: TestLabel.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Event
    EventType t = EventType.getEventType(LabelEvent.class);
    Asserts.assertEquals(t.getLabel(), "Event Label", "Incorrect label for event");

    // Field
    ValueDescriptor field = t.getField("labledField");
    Asserts.assertEquals(field.getLabel(), "Field Label", "Incorrect label for field");

    // Annotation
    AnnotationElement awl = Events.getAnnotationByName(t, AnnotionWithLabel.class.getName());
    Label label = awl.getAnnotation(Label.class);
    Asserts.assertEquals(label.value(), "Annotation Label", "Incorrect label for annotation");

    // Setting
    for (SettingDescriptor v: t.getSettingDescriptors()) {
        if (v.getName().equals("dummy")) {
            Label settingLabel = v.getAnnotation(Label.class);
            Asserts.assertEquals(settingLabel.value(), "Setting Label", "Incorrect label for setting");
        }
    }
}
 
Example #8
Source File: TestGetAnnotation.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Label al = annotatedType.getAnnotation(Label.class);
    Asserts.assertNull(al); // we should not inherit annotation from type

    Description ad = annotatedType.getAnnotation(Description.class);
    Asserts.assertNull(ad); // we should not inherit annotation from type

    Timestamp at = annotatedType.getAnnotation(Timestamp.class);
    Asserts.assertNull(at); // we should not inherit annotation from type

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Label nl = newName.getAnnotation(Label.class);
    Asserts.assertEquals(nl.value(), "Annotated Method");

    Description nd = newName.getAnnotation(Description.class);
    Asserts.assertEquals(nd.value(), "Description of an annotated method");

    Timespan nt = newName.getAnnotation(Timespan.class);
    Asserts.assertEquals(nt.value(), Timespan.NANOSECONDS);
}
 
Example #9
Source File: TestGetAnnotation.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Label al = annotatedType.getAnnotation(Label.class);
    Asserts.assertNull(al); // we should not inherit annotation from type

    Description ad = annotatedType.getAnnotation(Description.class);
    Asserts.assertNull(ad); // we should not inherit annotation from type

    Timestamp at = annotatedType.getAnnotation(Timestamp.class);
    Asserts.assertNull(at); // we should not inherit annotation from type

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Label nl = newName.getAnnotation(Label.class);
    Asserts.assertEquals(nl.value(), "Annotated Method");

    Description nd = newName.getAnnotation(Description.class);
    Asserts.assertEquals(nd.value(), "Description of an annotated method");

    Timespan nt = newName.getAnnotation(Timespan.class);
    Asserts.assertEquals(nt.value(), Timespan.NANOSECONDS);
}
 
Example #10
Source File: TestLabel.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Event
    EventType t = EventType.getEventType(LabelEvent.class);
    Asserts.assertEquals(t.getLabel(), "Event Label", "Incorrect label for event");

    // Field
    ValueDescriptor field = t.getField("labledField");
    Asserts.assertEquals(field.getLabel(), "Field Label", "Incorrect label for field");

    // Annotation
    AnnotationElement awl = Events.getAnnotationByName(t, AnnotionWithLabel.class.getName());
    Label label = awl.getAnnotation(Label.class);
    Asserts.assertEquals(label.value(), "Annotation Label", "Incorrect label for annotation");

    // Setting
    for (SettingDescriptor v: t.getSettingDescriptors()) {
        if (v.getName().equals("dummy")) {
            Label settingLabel = v.getAnnotation(Label.class);
            Asserts.assertEquals(settingLabel.value(), "Setting Label", "Incorrect label for setting");
        }
    }
}
 
Example #11
Source File: TestConstructor.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    ValueDescriptor vdSimple = new ValueDescriptor(String.class, "message");
    Asserts.assertNull(vdSimple.getAnnotation(Label.class), "Expected getAnnotation()==null");
    Asserts.assertEquals(0, vdSimple.getAnnotationElements().size(), "Expected getAnnotations().size() == 0");

    // Add labelA and verify we can read it back
    List<AnnotationElement> annos = new ArrayList<>();
    AnnotationElement labelA = new AnnotationElement(Label.class, "labelA");
    annos.add(labelA);
    System.out.println("labelA.getClass()" + labelA.getClass());
    ValueDescriptor vdComplex = new ValueDescriptor(String.class, "message", annos);

    final Label outLabel = vdComplex.getAnnotation(Label.class);
    Asserts.assertFalse(outLabel == null, "getLabel(Label.class) was null");
    System.out.println("outLabel.value() = " + outLabel.value());

    // Get labelA from getAnnotations() list
    Asserts.assertEquals(1, vdComplex.getAnnotationElements().size(), "Expected getAnnotations().size() == 1");
    final AnnotationElement outAnnotation = vdComplex.getAnnotationElements().get(0);
    Asserts.assertNotNull(outAnnotation, "outAnnotation was null");
    System.out.printf("Annotation: %s = %s%n", outAnnotation.getTypeName(), outAnnotation.getValue("value"));
    Asserts.assertEquals(outAnnotation, labelA, "Expected firstAnnotation == labelA");

}
 
Example #12
Source File: TestDynamicAnnotations.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void testEventFactoryExample() throws IOException {
     List<ValueDescriptor> fields = new ArrayList<>();
     List<AnnotationElement> messageAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Message"));
     fields.add(new ValueDescriptor(String.class, "message", messageAnnotations));
     List<AnnotationElement> numberAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Number"));
     fields.add(new ValueDescriptor(int.class, "number", numberAnnotations));

     String[] category = { "Example", "Getting Started" };
     List<AnnotationElement> eventAnnotations = new ArrayList<>();
     eventAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld"));
     eventAnnotations.add(new AnnotationElement(Label.class, "Hello World"));
     eventAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started"));
     eventAnnotations.add(new AnnotationElement(Category.class, category));

     EventFactory f = EventFactory.create(eventAnnotations, fields);

     Event event = f.newEvent();
     event.set(0, "hello, world!");
     event.set(1, 4711);
     event.commit();
}
 
Example #13
Source File: CustomEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SettingDefinition
@Name("newName")
@Label(ANNOTATED_METHOD)
@Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD)
@Timespan(Timespan.NANOSECONDS)
public boolean whatever(AnnotatedSetting s) {
    return true;
}
 
Example #14
Source File: BaseEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SettingDefinition
@Name("protectedBase")
@Label("Protected Base")
@Description("Description of protected base")
@Frequency
protected boolean something(PlainSetting control) {
    return true;
}
 
Example #15
Source File: BaseEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Name("baseName")
@Label("Base Label")
@Description("Base description")
@SettingDefinition
public boolean overridden(AnnotatedSetting control) {
    return true;
}
 
Example #16
Source File: AnnotationConstruct.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public String getLabel() {
    Label label = getAnnotation(Label.class);
    if (label == null) {
        return null;
    }
    return label.value();
}
 
Example #17
Source File: TypeLibrary.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void addImplicitFields(Type type, boolean requestable, boolean hasDuration, boolean hasThread, boolean hasStackTrace, boolean hasCutoff) {
    createAnnotationType(Timespan.class);
    createAnnotationType(Timestamp.class);
    createAnnotationType(Label.class);
    defineType(long.class, null,false);
    addFields(type, requestable, hasDuration, hasThread, hasStackTrace, hasCutoff);
}
 
Example #18
Source File: TestGetAnnotation.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    EventType type = EventType.getEventType(MyEvent.class);

    Label label = type.getAnnotation(Label.class);
    if (label == null) {
        Asserts.fail("Annotation label was null");
    }
    Asserts.assertEquals(label.value(), "myLabel", "Wrong value for annotation label");

    Category category = type.getAnnotation(Category.class);
    if (category == null) {
        Asserts.fail("Annotation @Description was null");
    }

    Asserts.assertTrue(Arrays.equals(category.value(), new String[] {"Stuff"}), "Wrong value for annotation enabled");

    Description description = type.getAnnotation(Description.class);
    if (description != null) {
        Asserts.fail("Annotation description should be null");
    }

    try {
        type.getAnnotation(null);
        Asserts.fail("No exception when getAnnotation(null)");
    } catch(Exception e) {
        // Expected exception
    }
}
 
Example #19
Source File: TypeLibrary.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static List<AnnotationElement> createStandardAnnotations(String name, String description) {
    List<AnnotationElement> annotationElements = new ArrayList<>(2);
    annotationElements.add(new jdk.jfr.AnnotationElement(Label.class, name));
    if (description != null) {
        annotationElements.add(new jdk.jfr.AnnotationElement(Description.class, description));
    }
    return annotationElements;
}
 
Example #20
Source File: TypeLibrary.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void addImplicitFields(Type type, boolean requestable, boolean hasDuration, boolean hasThread, boolean hasStackTrace, boolean hasCutoff) {
    createAnnotationType(Timespan.class);
    createAnnotationType(Timestamp.class);
    createAnnotationType(Label.class);
    defineType(long.class, null,false);
    addFields(type, requestable, hasDuration, hasThread, hasStackTrace, hasCutoff);
}
 
Example #21
Source File: ReflectionInformation.java    From teku with Apache License 2.0 5 votes vote down vote up
private Field[] getFields(Class classInfo) {
  return Arrays.stream(classInfo.getDeclaredFields())
      .filter(f -> !Modifier.isStatic(f.getModifiers()))
      .filter(
          f ->
              f.getAnnotation(Label.class) == null
                  || !"sos-ignore".equals(f.getAnnotation(Label.class).value()))
      .toArray(Field[]::new);
}
 
Example #22
Source File: TestGetAnnotation.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    EventType type = EventType.getEventType(MyEvent.class);

    Label label = type.getAnnotation(Label.class);
    if (label == null) {
        Asserts.fail("Annotation label was null");
    }
    Asserts.assertEquals(label.value(), "myLabel", "Wrong value for annotation label");

    Category category = type.getAnnotation(Category.class);
    if (category == null) {
        Asserts.fail("Annotation @Description was null");
    }

    Asserts.assertTrue(Arrays.equals(category.value(), new String[] {"Stuff"}), "Wrong value for annotation enabled");

    Description description = type.getAnnotation(Description.class);
    if (description != null) {
        Asserts.fail("Annotation description should be null");
    }

    try {
        type.getAnnotation(null);
        Asserts.fail("No exception when getAnnotation(null)");
    } catch(Exception e) {
        // Expected exception
    }
}
 
Example #23
Source File: BaseEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Name("baseName")
@Label("Base Label")
@Description("Base description")
@SettingDefinition
public boolean overridden(AnnotatedSetting control) {
    return true;
}
 
Example #24
Source File: BaseEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SettingDefinition
@Name("protectedBase")
@Label("Protected Base")
@Description("Description of protected base")
@Frequency
protected boolean something(PlainSetting control) {
    return true;
}
 
Example #25
Source File: TypeLibrary.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static List<AnnotationElement> createStandardAnnotations(String name, String description) {
    List<AnnotationElement> annotationElements = new ArrayList<>(2);
    annotationElements.add(new jdk.jfr.AnnotationElement(Label.class, name));
    if (description != null) {
        annotationElements.add(new jdk.jfr.AnnotationElement(Description.class, description));
    }
    return annotationElements;
}
 
Example #26
Source File: BaseEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Name("baseName")
@Label("Base Label")
@Description("Base description")
@SettingDefinition
public boolean overridden(AnnotatedSetting control) {
    return true;
}
 
Example #27
Source File: TestGetAnnotation.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    EventType type = EventType.getEventType(MyEvent.class);

    Label label = type.getAnnotation(Label.class);
    if (label == null) {
        Asserts.fail("Annotation label was null");
    }
    Asserts.assertEquals(label.value(), "myLabel", "Wrong value for annotation label");

    Category category = type.getAnnotation(Category.class);
    if (category == null) {
        Asserts.fail("Annotation @Description was null");
    }

    Asserts.assertTrue(Arrays.equals(category.value(), new String[] {"Stuff"}), "Wrong value for annotation enabled");

    Description description = type.getAnnotation(Description.class);
    if (description != null) {
        Asserts.fail("Annotation description should be null");
    }

    try {
        type.getAnnotation(null);
        Asserts.fail("No exception when getAnnotation(null)");
    } catch(Exception e) {
        // Expected exception
    }
}
 
Example #28
Source File: BaseEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SettingDefinition
@Name("protectedBase")
@Label("Protected Base")
@Description("Description of protected base")
@Frequency
protected boolean something(PlainSetting control) {
    return true;
}
 
Example #29
Source File: CustomEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SettingDefinition
@Name("newName")
@Label(ANNOTATED_METHOD)
@Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD)
@Timespan(Timespan.NANOSECONDS)
public boolean whatever(AnnotatedSetting s) {
    return true;
}
 
Example #30
Source File: CustomEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SettingDefinition
@Name("newName")
@Label(ANNOTATED_METHOD)
@Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD)
@Timespan(Timespan.NANOSECONDS)
public boolean whatever(AnnotatedSetting s) {
    return true;
}