src/jdk.jfr/share/classes/jdk/jfr/consumer/EventFileStream.java
branchJEP-349-branch
changeset 57376 8e8a06a3059c
parent 57374 41f0051285e0
child 57380 6a7e7743b82f
equal deleted inserted replaced
57375:3efa9b992c4d 57376:8e8a06a3059c
    43 final class EventFileStream implements EventStream {
    43 final class EventFileStream implements EventStream {
    44 
    44 
    45     private final static class FileEventConsumer extends EventConsumer {
    45     private final static class FileEventConsumer extends EventConsumer {
    46         private final RecordingInput input;
    46         private final RecordingInput input;
    47         private ChunkParser chunkParser;
    47         private ChunkParser chunkParser;
    48         private RecordedEvent event;
    48         private boolean reuse = true;
    49         private boolean moreEvents = true;
       
    50 
    49 
    51         public FileEventConsumer(AccessControlContext acc, RecordingInput input) throws IOException {
    50         public FileEventConsumer(AccessControlContext acc, RecordingInput input) throws IOException {
    52             super(acc);
    51             super(acc);
    53             this.input = input;
    52             this.input = input;
    54         }
    53         }
    55 
    54 
    56         @Override
    55         @Override
    57         public void process() throws Exception {
    56         public void process() throws Exception {
    58             chunkParser = new ChunkParser(input);
    57             chunkParser = new ChunkParser(input, reuse);
    59             while (moreEvents) {
    58             chunkParser.setReuse(reuse);
       
    59             RecordedEvent event;
       
    60             while (true) {
    60                 event = chunkParser.readEvent();
    61                 event = chunkParser.readEvent();
    61                 if (event == null) {
    62                 if (event == null) {
    62                     findNext();
    63                     event = findNext();
    63                     if (!moreEvents) {
    64                     if (event == null) {
    64                         return;
    65                         return;
    65                     }
    66                     }
    66                 }
    67                 }
    67                 dispatch(event);
    68                 dispatch(event);
    68             }
    69             }
    69         }
    70         }
    70 
    71 
    71         private void findNext() throws IOException {
    72         private RecordedEvent findNext() throws IOException {
       
    73             RecordedEvent event = null;
    72             while (event == null) {
    74             while (event == null) {
    73                 if (chunkParser == null) {
    75                 if (chunkParser.isLastChunk()) {
    74                     chunkParser = new ChunkParser(input);
    76                     return null;
    75                 } else if (!chunkParser.isLastChunk()) {
       
    76                     chunkParser = chunkParser.nextChunkParser();
       
    77                 } else {
       
    78                     moreEvents = false;
       
    79                     return;
       
    80                 }
    77                 }
       
    78                 chunkParser = chunkParser.nextChunkParser();
    81                 event = chunkParser.readEvent();
    79                 event = chunkParser.readEvent();
       
    80             }
       
    81             return event;
       
    82         }
       
    83 
       
    84         public void setReuse(boolean reuse) {
       
    85             if (chunkParser == null) {
       
    86                 this.reuse = reuse;
       
    87             } else {
       
    88                 chunkParser.setReuse(reuse);
    82             }
    89             }
    83         }
    90         }
    84     }
    91     }
    85 
    92 
    86     private final RecordingInput input;
    93     private final RecordingInput input;
   137     @Override
   144     @Override
   138     public void start() {
   145     public void start() {
   139         eventConsumer.start(0);
   146         eventConsumer.start(0);
   140     }
   147     }
   141 
   148 
       
   149     public void setReuse(boolean reuse) {
       
   150         eventConsumer.setReuse(reuse);
       
   151     }
       
   152 
   142     @Override
   153     @Override
   143     public void startAsync() {
   154     public void startAsync() {
   144         eventConsumer.startAsync(0);
   155         eventConsumer.startAsync(0);
   145     }
   156     }
   146 
   157