Java Code Examples for jdk.jfr.FlightRecorder#addListener()

The following examples show how to use jdk.jfr.FlightRecorder#addListener() . 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: TestRecorderInitialized.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String...args) {
    Listener l1 = new Listener();

    FlightRecorder.addListener(l1);
    Asserts.assertFalse(l1.notified, "Listener shouldn't be notified unless Flight Recorder is initialized");
    // initialize Flight Recorder
    FlightRecorder.getFlightRecorder();
    Asserts.assertTrue(l1.notified, "Listener should be notified when Flight Recorder is initialized");
    l1.notified = false;

    Listener l2 = new Listener();
    FlightRecorder.addListener(l1);
    FlightRecorder.addListener(l2);
    Asserts.assertTrue(l2.notified, "Listener should be notified if Flight Recorder is already initialized");
    Asserts.assertTrue(l1.notified, "Only added listnener should be notified, if Flight Recorder is already initialized");

}
 
Example 2
Source File: TestRecorderInitialized.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String...args) {
    Listener l1 = new Listener();

    FlightRecorder.addListener(l1);
    Asserts.assertFalse(l1.notified, "Listener shouldn't be notified unless Flight Recorder is initialized");
    // initialize Flight Recorder
    FlightRecorder.getFlightRecorder();
    Asserts.assertTrue(l1.notified, "Listener should be notified when Flight Recorder is initialized");
    l1.notified = false;

    Listener l2 = new Listener();
    FlightRecorder.addListener(l1);
    FlightRecorder.addListener(l2);
    Asserts.assertTrue(l2.notified, "Listener should be notified if Flight Recorder is already initialized");
    Asserts.assertTrue(l1.notified, "Only added listnener should be notified, if Flight Recorder is already initialized");

}
 
Example 3
Source File: TestStateIdenticalListeners.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 {
    TestListener testListener = new TestListener();
    // Add the same listener twice
    FlightRecorder.addListener(testListener);
    FlightRecorder.addListener(testListener);

    // Start recording
    Recording recording = new Recording();
    recording.start();
    recording.stop();

    // We expect 4 notifications in total: 1 RUNNING and 1 STOPPED
    // notification for each listener registration
    // NOT 2 notifications: we have added the same listener again
    assertEquals(4, testListener.notificationCount, "Expected 2 notifications, got " + testListener.notificationCount);

    System.out.println("Test Passed");
    recording.close();
}
 
Example 4
Source File: TestAddListenerTwice.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 {
    MyListener listener = new MyListener();

    FlightRecorder.addListener(listener);
    FlightRecorder.addListener(listener);

    Recording r1 = new Recording();
    r1.start();
    listener.verifyState(2, RecordingState.RUNNING);

    FlightRecorder.removeListener(listener); // Should still get callback to one listener.
    r1.stop();
    listener.verifyState(3, RecordingState.STOPPED);
    r1.close();
    listener.verifyState(4, RecordingState.CLOSED);
}
 
Example 5
Source File: TestListener.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 {
    MyListener listener1 = new MyListener();
    MyListener listener2 = new MyListener();
    FlightRecorder.addListener(listener1);
    FlightRecorder.addListener(listener2);

    Recording r1 = new Recording();
    listener1.verifyState(0, RecordingState.NEW);
    listener2.verifyState(0, RecordingState.NEW);

    r1.start();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(1, RecordingState.RUNNING);

    FlightRecorder.removeListener(listener1); // listener1 should not get more callbacks.
    r1.stop();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(2, RecordingState.STOPPED);

    r1.close();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(3, RecordingState.CLOSED);
    FlightRecorder.removeListener(listener2);
}
 
Example 6
Source File: TestListener.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 {
    MyListener listener1 = new MyListener();
    MyListener listener2 = new MyListener();
    FlightRecorder.addListener(listener1);
    FlightRecorder.addListener(listener2);

    Recording r1 = new Recording();
    listener1.verifyState(0, RecordingState.NEW);
    listener2.verifyState(0, RecordingState.NEW);

    r1.start();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(1, RecordingState.RUNNING);

    FlightRecorder.removeListener(listener1); // listener1 should not get more callbacks.
    r1.stop();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(2, RecordingState.STOPPED);

    r1.close();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(3, RecordingState.CLOSED);
    FlightRecorder.removeListener(listener2);
}
 
Example 7
Source File: TestStateIdenticalListeners.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 {
    TestListener testListener = new TestListener();
    // Add the same listener twice
    FlightRecorder.addListener(testListener);
    FlightRecorder.addListener(testListener);

    // Start recording
    Recording recording = new Recording();
    recording.start();
    recording.stop();

    // We expect 4 notifications in total: 1 RUNNING and 1 STOPPED
    // notification for each listener registration
    // NOT 2 notifications: we have added the same listener again
    assertEquals(4, testListener.notificationCount, "Expected 2 notifications, got " + testListener.notificationCount);

    System.out.println("Test Passed");
    recording.close();
}
 
Example 8
Source File: TestAddListenerTwice.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 {
    MyListener listener = new MyListener();

    FlightRecorder.addListener(listener);
    FlightRecorder.addListener(listener);

    Recording r1 = new Recording();
    r1.start();
    listener.verifyState(2, RecordingState.RUNNING);

    FlightRecorder.removeListener(listener); // Should still get callback to one listener.
    r1.stop();
    listener.verifyState(3, RecordingState.STOPPED);
    r1.close();
    listener.verifyState(4, RecordingState.CLOSED);
}
 
Example 9
Source File: TestFlightRecorderListenerRecorderInitialized.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 {
    FlightRecorder.addListener(new FlightRecorderListener() {

        @Override
        public void recorderInitialized(FlightRecorder recorder) {
            log("Recorder initialized");
            Signal.signal();
        }

    });
    FlightRecorder.getFlightRecorder();

    Signal.waitFor(3, TimeUnit.SECONDS);

    assertTrue(Signal.signalled, "FlightRecorderListener.recorderInitialized has not been called");

}
 
Example 10
Source File: TestListener.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 {
    MyListener listener1 = new MyListener();
    MyListener listener2 = new MyListener();
    FlightRecorder.addListener(listener1);
    FlightRecorder.addListener(listener2);

    Recording r1 = new Recording();
    listener1.verifyState(0, RecordingState.NEW);
    listener2.verifyState(0, RecordingState.NEW);

    r1.start();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(1, RecordingState.RUNNING);

    FlightRecorder.removeListener(listener1); // listener1 should not get more callbacks.
    r1.stop();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(2, RecordingState.STOPPED);

    r1.close();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(3, RecordingState.CLOSED);
    FlightRecorder.removeListener(listener2);
}
 
Example 11
Source File: TestAddListenerTwice.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 {
    MyListener listener = new MyListener();

    FlightRecorder.addListener(listener);
    FlightRecorder.addListener(listener);

    Recording r1 = new Recording();
    r1.start();
    listener.verifyState(2, RecordingState.RUNNING);

    FlightRecorder.removeListener(listener); // Should still get callback to one listener.
    r1.stop();
    listener.verifyState(3, RecordingState.STOPPED);
    r1.close();
    listener.verifyState(4, RecordingState.CLOSED);
}
 
Example 12
Source File: TestIsInitialized.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 {
    Asserts.assertFalse(FlightRecorder.isInitialized());
    FlightRecorder.addListener(new FlightRecorderListener() {
        public void recorderInitialized(FlightRecorder recorder) {
            Asserts.assertTrue(FlightRecorder.isInitialized());
        }
    });
    FlightRecorder.getFlightRecorder();
    Asserts.assertTrue(FlightRecorder.isInitialized());
}
 
Example 13
Source File: TestRecorderInitializationCallback.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 {
    TestListener t = new TestListener();
    FlightRecorder.addListener(t);
    // trigger initialization
    FlightRecorder.getFlightRecorder();
    assertEquals(1, t.count.intValue(), "Expected 1 notification, got " + t.count);
}
 
Example 14
Source File: TestRecorderListener.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 {
    Listener recordingListener = new Listener(RecordingState.RUNNING);
    FlightRecorder.addListener(recordingListener);

    Listener stoppedListener = new Listener(RecordingState.STOPPED);
    FlightRecorder.addListener(stoppedListener);

    Listener finishedListener = new Listener(RecordingState.CLOSED);
    FlightRecorder.addListener(finishedListener);

    Recording recording = new Recording();
    if (recording.getState() != RecordingState.NEW) {
        recording.close();
        throw new Exception("New recording should be in NEW state");
    }

    recording.start();
    recordingListener.waitFor();

    recording.stop();
    stoppedListener.waitFor();

    recording.close();
    finishedListener.waitFor();

    testDefaultrecordingStateChangedListener();

}
 
Example 15
Source File: TestRecorderInitializationCallback.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 {
    TestListener t = new TestListener();
    FlightRecorder.addListener(t);
    // trigger initialization
    FlightRecorder.getFlightRecorder();
    assertEquals(1, t.count.intValue(), "Expected 1 notification, got " + t.count);
}
 
Example 16
Source File: TestRecorderInitializationCallback.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 {
    TestListener t = new TestListener();
    FlightRecorder.addListener(t);
    // trigger initialization
    FlightRecorder.getFlightRecorder();
    assertEquals(1, t.count.intValue(), "Expected 1 notification, got " + t.count);
}
 
Example 17
Source File: TestIsInitialized.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 {
    Asserts.assertFalse(FlightRecorder.isInitialized());
    FlightRecorder.addListener(new FlightRecorderListener() {
        public void recorderInitialized(FlightRecorder recorder) {
            Asserts.assertTrue(FlightRecorder.isInitialized());
        }
    });
    FlightRecorder.getFlightRecorder();
    Asserts.assertTrue(FlightRecorder.isInitialized());
}
 
Example 18
Source File: TestIsInitialized.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 {
    Asserts.assertFalse(FlightRecorder.isInitialized());
    FlightRecorder.addListener(new FlightRecorderListener() {
        public void recorderInitialized(FlightRecorder recorder) {
            Asserts.assertTrue(FlightRecorder.isInitialized());
        }
    });
    FlightRecorder.getFlightRecorder();
    Asserts.assertTrue(FlightRecorder.isInitialized());
}
 
Example 19
Source File: TestRecorderListener.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 {
    Listener recordingListener = new Listener(RecordingState.RUNNING);
    FlightRecorder.addListener(recordingListener);

    Listener stoppedListener = new Listener(RecordingState.STOPPED);
    FlightRecorder.addListener(stoppedListener);

    Listener finishedListener = new Listener(RecordingState.CLOSED);
    FlightRecorder.addListener(finishedListener);

    Recording recording = new Recording();
    if (recording.getState() != RecordingState.NEW) {
        recording.close();
        throw new Exception("New recording should be in NEW state");
    }

    recording.start();
    recordingListener.waitFor();

    recording.stop();
    stoppedListener.waitFor();

    recording.close();
    finishedListener.waitFor();

    testDefaultrecordingStateChangedListener();

}
 
Example 20
Source File: TestRecorderListener.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 {
    Listener recordingListener = new Listener(RecordingState.RUNNING);
    FlightRecorder.addListener(recordingListener);

    Listener stoppedListener = new Listener(RecordingState.STOPPED);
    FlightRecorder.addListener(stoppedListener);

    Listener finishedListener = new Listener(RecordingState.CLOSED);
    FlightRecorder.addListener(finishedListener);

    Recording recording = new Recording();
    if (recording.getState() != RecordingState.NEW) {
        recording.close();
        throw new Exception("New recording should be in NEW state");
    }

    recording.start();
    recordingListener.waitFor();

    recording.stop();
    stoppedListener.waitFor();

    recording.close();
    finishedListener.waitFor();

    testDefaultrecordingStateChangedListener();

}