First stab at EventFileStream JEP-349-branch
authoregahlin
Fri, 24 May 2019 20:45:11 +0200
branchJEP-349-branch
changeset 57374 41f0051285e0
parent 57373 400db63e4937
child 57375 3efa9b992c4d
First stab at EventFileStream
src/jdk.jfr/share/classes/jdk/jfr/consumer/EventFileStream.java
--- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventFileStream.java	Fri May 24 20:30:12 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventFileStream.java	Fri May 24 20:45:11 2019 +0200
@@ -42,8 +42,11 @@
  */
 final class EventFileStream implements EventStream {
 
-    final static class FileEventConsumer extends EventConsumer {
+    private final static class FileEventConsumer extends EventConsumer {
         private final RecordingInput input;
+        private ChunkParser chunkParser;
+        private RecordedEvent event;
+        private boolean moreEvents = true;
 
         public FileEventConsumer(AccessControlContext acc, RecordingInput input) throws IOException {
             super(acc);
@@ -52,11 +55,30 @@
 
         @Override
         public void process() throws Exception {
-            // TODO This need more work; filter, multiple chunk etc
-            ChunkParser cp = new ChunkParser(input);
-            while (true) {
-                RecordedEvent e = cp.readEvent();
-                dispatch(e);
+            chunkParser = new ChunkParser(input);
+            while (moreEvents) {
+                event = chunkParser.readEvent();
+                if (event == null) {
+                    findNext();
+                    if (!moreEvents) {
+                        return;
+                    }
+                }
+                dispatch(event);
+            }
+        }
+
+        private void findNext() throws IOException {
+            while (event == null) {
+                if (chunkParser == null) {
+                    chunkParser = new ChunkParser(input);
+                } else if (!chunkParser.isLastChunk()) {
+                    chunkParser = chunkParser.nextChunkParser();
+                } else {
+                    moreEvents = false;
+                    return;
+                }
+                event = chunkParser.readEvent();
             }
         }
     }