Merge JEP-349-branch
authormgronlun
Mon, 16 Sep 2019 15:54:29 +0200
branchJEP-349-branch
changeset 58169 95274a695261
parent 58168 945212abbac0 (current diff)
parent 58153 0f7562601338 (diff)
child 58170 2bcc33884590
Merge
--- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java	Mon Sep 16 14:58:38 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java	Mon Sep 16 15:54:29 2019 +0200
@@ -86,13 +86,35 @@
  * default behavior is to print the exception and its backtrace to the standard
  * error stream.
  * <p>
- * The following example demonstrates how an {@code EventStream} can be used to
- * listen to garbage collection and CPU Load events
+ * The following example shows how an {@code EventStream} can be used to
+ * listen to events on a JVM running Flight Recorder
+ * <pre>
+ * <code>
+ * try (EventStream es = EventStream.openRepository()) {
+ *   es.onEvent("jdk.CPULoad", event -> {
+ *     System.out.println("CPU Load " + event.getEndTime());
+ *     System.out.println(" Machine total: " + 100 * event.getFloat("machineTotal") + "%");
+ *     System.out.println(" JVM User: " + 100 * event.getFloat("jvmUser") + "%");
+ *     System.out.println(" JVM System: " + 100 * event.getFloat("jvmSystem") + "%");
+ *     System.out.println();
+ *     System.gc();
+ *   });
+ *   es.onEvent("jdk.GarbageCollection", event -> {
+ *     System.out.println("Garbage collection: " + event.getLong("gcId"));
+ *     System.out.println(" Cause: " + event.getString("cause"));
+ *     System.out.println(" Total pause: " + event.getDuration("sumOfPauses"));
+ *     System.out.println(" Longest pause: " + event.getDuration("longestPause"));
+ *     System.out.println();
+ *   });
+ *   es.start();
+ * }
+ * </code>
+ * </pre>
  * <p>
+ * To start recording together with the stream, see {@link RecordingStream}.
  *
  */
 public interface EventStream extends AutoCloseable {
-
     /**
      * Creates a stream from the repository of the current Java Virtual Machine
      * (JVM).
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/AbstractEventStream.java	Mon Sep 16 14:58:38 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/AbstractEventStream.java	Mon Sep 16 15:54:29 2019 +0200
@@ -205,7 +205,7 @@
         }
     }
 
-    protected abstract void process() throws Exception;
+    protected abstract void process() throws IOException;
 
     protected final void setClosed(boolean closed) {
         this.closed = closed;
@@ -252,10 +252,7 @@
             // This can happen if a chunk file is removed, or
             // a file is access that has been closed
             // This is "normal" behavior for streaming and the
-            // stream will be closed when this happens
-        } catch (Exception e) {
-            // TODO: Remove before integrating
-            e.printStackTrace();
+            // stream will be closed when this happens.
         } finally {
             Logger.log(LogTag.JFR_SYSTEM_STREAMING, LogLevel.DEBUG, "Execution of stream ended.");
             try {
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/Dispatcher.java	Mon Sep 16 14:58:38 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/Dispatcher.java	Mon Sep 16 15:54:29 2019 +0200
@@ -94,6 +94,24 @@
             }
             cacheDispatchers = dispatchers;
         }
+        // Expected behavior if exception occurs in onEvent:
+        //
+        // Synchronous:
+        //  - User has added onError action:
+        //     Catch exception, call onError and continue with next event
+        //     Let Errors propagate to caller of EventStream::start
+        //  - Default action
+        //     Catch exception, e.printStackTrace() and continue with next event
+        //     Let Errors propagate to caller of EventStream::start
+        //
+        // Asynchronous
+        //  - User has added onError action
+        //     Catch exception, call onError and continue with next event
+        //     Let Errors propagate, shutdown thread and stream
+        //  - Default action
+        //    Catch exception, e.printStackTrace() and continue with next event
+        //    Let Errors propagate and shutdown thread and stream
+        //
         for (int i = 0; i < dispatchers.length; i++) {
             try {
                 dispatchers[i].offer(event);
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/EventDirectoryStream.java	Mon Sep 16 14:58:38 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/EventDirectoryStream.java	Mon Sep 16 15:54:29 2019 +0200
@@ -79,7 +79,7 @@
     }
 
     @Override
-    protected void process() throws Exception {
+    protected void process() throws IOException {
         Dispatcher disp = dispatcher();
 
         Path path;
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/Health.java	Mon Sep 16 14:58:38 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/Health.java	Mon Sep 16 15:54:29 2019 +0200
@@ -42,6 +42,8 @@
 import jdk.jfr.consumer.RecordedStackTrace;
 import jdk.jfr.consumer.RecordingStream;
 
+// TODO: This file is to be deleted before integration
+
 /**
  *
  * HEALTH REPORT
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/Monitor.java	Mon Sep 16 14:58:38 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/Monitor.java	Mon Sep 16 15:54:29 2019 +0200
@@ -28,6 +28,8 @@
 import jdk.jfr.consumer.EventStream;
 import jdk.jfr.consumer.RecordingStream;
 
+// TODO: This file is to be deleted before integration
+
 public class Monitor {
 
     private static EventStream stream;