Java Code Examples for jdk.jfr.EventFactory#getEventType()

The following examples show how to use jdk.jfr.EventFactory#getEventType() . 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: TestEventFactoryRegistration.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Create an unregistered event
    List<AnnotationElement> annotations = new ArrayList<>();
    annotations.add(new AnnotationElement(Registered.class, false));
    EventFactory factory = EventFactory.create(annotations, Collections.emptyList());

    try {
        factory.getEventType();
        Asserts.fail("Should not be able to get event type from an unregistered event");
    } catch(IllegalStateException ise) {
        // OK as expected
    }

    // Now, register the event
    factory.register();
    EventType eventType = factory.getEventType();
    verifyRegistered(factory.getEventType());


    // Now, unregister the event
    factory.unregister();

    verifyUnregistered(eventType);

    // Create a registered event
    factory = EventFactory.create(Collections.emptyList(), Collections.emptyList());

    eventType = factory.getEventType();
    Asserts.assertNotNull(eventType);

    verifyRegistered(eventType);

}
 
Example 2
Source File: TestDynamicAnnotations.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void testECID() throws Exception {
    List<ValueDescriptor> fields = new ArrayList<>();

    List<AnnotationElement> fieldAnnotations = new ArrayList<>();
    fieldAnnotations.add(new AnnotationElement(ECID.class));
    ValueDescriptor ecidField = new ValueDescriptor(String.class, "ecid", fieldAnnotations);
    fields.add(ecidField);

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

    String ecidValue = "131739871298371279812";
    try (Recording r = new Recording()) {
        r.start();
        Event event = f.newEvent();
        event.set(0, ecidValue);
        event.commit();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        Events.hasEvents(events);
        Events.assertField(events.get(0), "ecid").equal(ecidValue);
    }
    EventType type = f.getEventType();
    ECID e = type.getAnnotation(ECID.class);
    if (e == null) {
        throw new Exception("Missing ECID annotation");
    }
}
 
Example 3
Source File: TestEventFactoryRegistration.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Create an unregistered event
    List<AnnotationElement> annotations = new ArrayList<>();
    annotations.add(new AnnotationElement(Registered.class, false));
    EventFactory factory = EventFactory.create(annotations, Collections.emptyList());

    try {
        factory.getEventType();
        Asserts.fail("Should not be able to get event type from an unregistered event");
    } catch(IllegalStateException ise) {
        // OK as expected
    }

    // Now, register the event
    factory.register();
    EventType eventType = factory.getEventType();
    verifyRegistered(factory.getEventType());


    // Now, unregister the event
    factory.unregister();

    verifyUnregistered(eventType);

    // Create a registered event
    factory = EventFactory.create(Collections.emptyList(), Collections.emptyList());

    eventType = factory.getEventType();
    Asserts.assertNotNull(eventType);

    verifyRegistered(eventType);

}
 
Example 4
Source File: TestDynamicAnnotations.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void testECID() throws Exception {
    List<ValueDescriptor> fields = new ArrayList<>();

    List<AnnotationElement> fieldAnnotations = new ArrayList<>();
    fieldAnnotations.add(new AnnotationElement(ECID.class));
    ValueDescriptor ecidField = new ValueDescriptor(String.class, "ecid", fieldAnnotations);
    fields.add(ecidField);

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

    String ecidValue = "131739871298371279812";
    try (Recording r = new Recording()) {
        r.start();
        Event event = f.newEvent();
        event.set(0, ecidValue);
        event.commit();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        Events.hasEvents(events);
        Events.assertField(events.get(0), "ecid").equal(ecidValue);
    }
    EventType type = f.getEventType();
    ECID e = type.getAnnotation(ECID.class);
    if (e == null) {
        throw new Exception("Missing ECID annotation");
    }
}
 
Example 5
Source File: TestEventFactoryRegistration.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Create an unregistered event
    List<AnnotationElement> annotations = new ArrayList<>();
    annotations.add(new AnnotationElement(Registered.class, false));
    EventFactory factory = EventFactory.create(annotations, Collections.emptyList());

    try {
        factory.getEventType();
        Asserts.fail("Should not be able to get event type from an unregistered event");
    } catch(IllegalStateException ise) {
        // OK as expected
    }

    // Now, register the event
    factory.register();
    EventType eventType = factory.getEventType();
    verifyRegistered(factory.getEventType());


    // Now, unregister the event
    factory.unregister();

    verifyUnregistered(eventType);

    // Create a registered event
    factory = EventFactory.create(Collections.emptyList(), Collections.emptyList());

    eventType = factory.getEventType();
    Asserts.assertNotNull(eventType);

    verifyRegistered(eventType);

}
 
Example 6
Source File: TestDynamicAnnotations.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void testECID() throws Exception {
    List<ValueDescriptor> fields = new ArrayList<>();

    List<AnnotationElement> fieldAnnotations = new ArrayList<>();
    fieldAnnotations.add(new AnnotationElement(ECID.class));
    ValueDescriptor ecidField = new ValueDescriptor(String.class, "ecid", fieldAnnotations);
    fields.add(ecidField);

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

    String ecidValue = "131739871298371279812";
    try (Recording r = new Recording()) {
        r.start();
        Event event = f.newEvent();
        event.set(0, ecidValue);
        event.commit();
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        Events.hasEvents(events);
        Events.assertField(events.get(0), "ecid").equal(ecidValue);
    }
    EventType type = f.getEventType();
    ECID e = type.getAnnotation(ECID.class);
    if (e == null) {
        throw new Exception("Missing ECID annotation");
    }
}
 
Example 7
Source File: TestEventFactoryRegisterTwice.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventFactory factory = EventFactory.create(Collections.emptyList(), Collections.emptyList());

    EventType eventType = factory.getEventType();
    Asserts.assertNotNull(eventType);

    // Now, register the event
    factory.register();

    verifyRegistered(eventType);

    // Now, register the event again
    factory.register();

    verifyRegistered(eventType);
}
 
Example 8
Source File: TestEventFactoryRegisterTwice.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventFactory factory = EventFactory.create(Collections.emptyList(), Collections.emptyList());

    EventType eventType = factory.getEventType();
    Asserts.assertNotNull(eventType);

    // Now, register the event
    factory.register();

    verifyRegistered(eventType);

    // Now, register the event again
    factory.register();

    verifyRegistered(eventType);
}
 
Example 9
Source File: TestEventFactoryRegisterTwice.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventFactory factory = EventFactory.create(Collections.emptyList(), Collections.emptyList());

    EventType eventType = factory.getEventType();
    Asserts.assertNotNull(eventType);

    // Now, register the event
    factory.register();

    verifyRegistered(eventType);

    // Now, register the event again
    factory.register();

    verifyRegistered(eventType);
}