src/jdk.jfr/share/classes/jdk/jfr/consumer/EventFileStream.java
branchJEP-349-branch
changeset 57376 8e8a06a3059c
parent 57374 41f0051285e0
child 57380 6a7e7743b82f
--- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventFileStream.java	Fri May 24 20:51:28 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventFileStream.java	Mon May 27 18:33:13 2019 +0200
@@ -45,8 +45,7 @@
     private final static class FileEventConsumer extends EventConsumer {
         private final RecordingInput input;
         private ChunkParser chunkParser;
-        private RecordedEvent event;
-        private boolean moreEvents = true;
+        private boolean reuse = true;
 
         public FileEventConsumer(AccessControlContext acc, RecordingInput input) throws IOException {
             super(acc);
@@ -55,12 +54,14 @@
 
         @Override
         public void process() throws Exception {
-            chunkParser = new ChunkParser(input);
-            while (moreEvents) {
+            chunkParser = new ChunkParser(input, reuse);
+            chunkParser.setReuse(reuse);
+            RecordedEvent event;
+            while (true) {
                 event = chunkParser.readEvent();
                 if (event == null) {
-                    findNext();
-                    if (!moreEvents) {
+                    event = findNext();
+                    if (event == null) {
                         return;
                     }
                 }
@@ -68,18 +69,24 @@
             }
         }
 
-        private void findNext() throws IOException {
+        private RecordedEvent findNext() throws IOException {
+            RecordedEvent event = null;
             while (event == null) {
-                if (chunkParser == null) {
-                    chunkParser = new ChunkParser(input);
-                } else if (!chunkParser.isLastChunk()) {
-                    chunkParser = chunkParser.nextChunkParser();
-                } else {
-                    moreEvents = false;
-                    return;
+                if (chunkParser.isLastChunk()) {
+                    return null;
                 }
+                chunkParser = chunkParser.nextChunkParser();
                 event = chunkParser.readEvent();
             }
+            return event;
+        }
+
+        public void setReuse(boolean reuse) {
+            if (chunkParser == null) {
+                this.reuse = reuse;
+            } else {
+                chunkParser.setReuse(reuse);
+            }
         }
     }
 
@@ -139,6 +146,10 @@
         eventConsumer.start(0);
     }
 
+    public void setReuse(boolean reuse) {
+        eventConsumer.setReuse(reuse);
+    }
+
     @Override
     public void startAsync() {
         eventConsumer.startAsync(0);