Reuse chunk parser JEP-349-branch
authoregahlin
Tue, 25 Jun 2019 13:32:03 +0200
branchJEP-349-branch
changeset 57427 596f839ce88f
parent 57425 1da8552f0b59
child 57428 ef3e241c420f
Reuse chunk parser
src/jdk.jfr/share/classes/jdk/jfr/consumer/ChunkParser.java
src/jdk.jfr/share/classes/jdk/jfr/consumer/EventDirectoryStream.java
--- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/ChunkParser.java	Tue Jun 25 12:03:01 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/ChunkParser.java	Tue Jun 25 13:32:03 2019 +0200
@@ -66,10 +66,13 @@
     private boolean resetEventCache;
 
     public ChunkParser(RecordingInput input, boolean reuse) throws IOException {
-        this(new ChunkHeader(input), null, 500);
+       this(new ChunkHeader(input), null, 500);
        this.reuse = reuse;
     }
 
+    public ChunkParser(ChunkParser previous) throws IOException {
+        this(new ChunkHeader(previous.input), null, 500);
+     }
 
     private ChunkParser(ChunkHeader header, ChunkParser previous, long pollInterval) throws IOException {
         this.input = header.getInput();
@@ -334,6 +337,10 @@
         return chunkHeader.isLastChunk();
     }
 
+    public ChunkParser newChunkParser() throws IOException {
+        return new ChunkParser(this);
+    }
+
     public ChunkParser nextChunkParser() throws IOException {
         return new ChunkParser(chunkHeader.nextHeader(), this, pollInterval);
     }
--- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventDirectoryStream.java	Tue Jun 25 12:03:01 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventDirectoryStream.java	Tue Jun 25 13:32:03 2019 +0200
@@ -182,9 +182,8 @@
             Path path = repositoryFiles.nextPath(startNanos);
             startNanos = repositoryFiles.getTimestamp(path) + 1;
             try (RecordingInput input = new RecordingInput(path.toFile())) {
+                chunkParser = new ChunkParser(input, this.reuse);
                 while (!isClosed()) {
-                    // chunkParser = chunkParser.nextChunkParser();
-                    chunkParser = new ChunkParser(input, this.reuse);
                     boolean awaitnewEvent = false;
                     while (!isClosed() && !chunkParser.isChunkFinished()) {
                         chunkParser.setReuse(this.reuse);
@@ -202,6 +201,7 @@
                     path = repositoryFiles.nextPath(startNanos);
                     startNanos = repositoryFiles.getTimestamp(path) + 1;
                     input.setFile(path);
+                    chunkParser = chunkParser.newChunkParser();
                 }
             }
         }