src/jdk.jfr/share/classes/jdk/jfr/consumer/EventDirectoryStream.java
branchJEP-349-branch
changeset 57432 ba454a26d2c1
parent 57428 ef3e241c420f
child 57433 83e4343a6984
equal deleted inserted replaced
57428:ef3e241c420f 57432:ba454a26d2c1
    52 import jdk.jfr.internal.Repository;
    52 import jdk.jfr.internal.Repository;
    53 import jdk.jfr.internal.consumer.ChunkHeader;
    53 import jdk.jfr.internal.consumer.ChunkHeader;
    54 import jdk.jfr.internal.consumer.EventConsumer;
    54 import jdk.jfr.internal.consumer.EventConsumer;
    55 import jdk.jfr.internal.consumer.RecordingInput;
    55 import jdk.jfr.internal.consumer.RecordingInput;
    56 
    56 
       
    57 /**
       
    58  * Implementation of an {@code EventStream}} that operates against a directory
       
    59  * with chunk files.
       
    60  *
       
    61  */
    57 final class EventDirectoryStream implements EventStream {
    62 final class EventDirectoryStream implements EventStream {
    58 
    63 
    59     private static final class RepositoryFiles {
    64     private static final class RepositoryFiles {
    60         private final Path repostory;
    65         private final Path repostory;
    61         private final SortedMap<Long, Path> pathSet = new TreeMap<>();
    66         private final SortedMap<Long, Path> pathSet = new TreeMap<>();
    65         public RepositoryFiles(Path repostory) {
    70         public RepositoryFiles(Path repostory) {
    66             this.repostory = repostory;
    71             this.repostory = repostory;
    67         }
    72         }
    68 
    73 
    69         long getTimestamp(Path p) {
    74         long getTimestamp(Path p) {
    70             return  pathLookup.get(p);
    75             return pathLookup.get(p);
    71         }
    76         }
    72 
    77 
    73         Path nextPath(long startTimeNanos) {
    78         Path nextPath(long startTimeNanos) {
    74             while (!closed) {
    79             while (!closed) {
    75                 SortedMap<Long, Path> after = pathSet.tailMap(startTimeNanos);
    80                 SortedMap<Long, Path> after = pathSet.tailMap(startTimeNanos);
   166 
   171 
   167         private static final Comparator<? super RecordedEvent> END_TIME = (e1, e2) -> Long.compare(e1.endTime, e2.endTime);
   172         private static final Comparator<? super RecordedEvent> END_TIME = (e1, e2) -> Long.compare(e1.endTime, e2.endTime);
   168         private static final int DEFAULT_ARRAY_SIZE = 10_000;
   173         private static final int DEFAULT_ARRAY_SIZE = 10_000;
   169         private final RepositoryFiles repositoryFiles;
   174         private final RepositoryFiles repositoryFiles;
   170         private ChunkParser chunkParser;
   175         private ChunkParser chunkParser;
   171         private boolean reuse = true;
       
   172         private RecordedEvent[] sortedList;
   176         private RecordedEvent[] sortedList;
   173         private boolean ordered = true;
       
   174 
   177 
   175         public ParserConsumer(AccessControlContext acc, Path p) throws IOException {
   178         public ParserConsumer(AccessControlContext acc, Path p) throws IOException {
   176             super(acc);
   179             super(acc);
   177             repositoryFiles = new RepositoryFiles(p);
   180             repositoryFiles = new RepositoryFiles(p);
   178         }
   181         }
   198                         }
   201                         }
   199                         runFlushActions();
   202                         runFlushActions();
   200                     }
   203                     }
   201 
   204 
   202                     path = repositoryFiles.nextPath(startNanos);
   205                     path = repositoryFiles.nextPath(startNanos);
       
   206                     if (path == null) {
       
   207                         return; // stream closed
       
   208                     }
   203                     startNanos = repositoryFiles.getTimestamp(path) + 1;
   209                     startNanos = repositoryFiles.getTimestamp(path) + 1;
   204                     input.setFile(path);
   210                     input.setFile(path);
   205                     chunkParser = chunkParser.newChunkParser();
   211                     chunkParser = chunkParser.newChunkParser();
   206                 }
   212                 }
   207             }
   213             }