src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RepositoryFiles.java
branchJEP-349-branch
changeset 57628 f5f590eaecf5
parent 57604 838f9a7635b6
child 57638 3b41affae2d2
equal deleted inserted replaced
57627:b38c7a822244 57628:f5f590eaecf5
    42 
    42 
    43 import jdk.jfr.internal.LogLevel;
    43 import jdk.jfr.internal.LogLevel;
    44 import jdk.jfr.internal.LogTag;
    44 import jdk.jfr.internal.LogTag;
    45 import jdk.jfr.internal.Logger;
    45 import jdk.jfr.internal.Logger;
    46 import jdk.jfr.internal.Repository;
    46 import jdk.jfr.internal.Repository;
       
    47 import jdk.jfr.internal.SecuritySupport.SafePath;
    47 
    48 
    48 public final class RepositoryFiles {
    49 public final class RepositoryFiles {
    49     private final Path repostory;
    50     private final Path repository;
    50     private final NavigableMap<Long, Path> pathSet = new TreeMap<>();
    51     private final NavigableMap<Long, Path> pathSet = new TreeMap<>();
    51     private final Map<Path, Long> pathLookup = new HashMap<>();
    52     private final Map<Path, Long> pathLookup = new HashMap<>();
    52     private volatile boolean closed;
    53     private volatile boolean closed;
    53 
    54 
    54     public RepositoryFiles(Path repostory) {
    55     public RepositoryFiles(SafePath repository) {
    55         this.repostory = repostory;
    56         this.repository = repository.toPath();
    56     }
    57     }
    57 
    58 
    58     public long getTimestamp(Path p) {
    59     public long getTimestamp(Path p) {
    59         return pathLookup.get(p);
    60         return pathLookup.get(p);
    60     }
    61     }
    69                 Entry<Long, Path> e = pathSet.lastEntry();
    70                 Entry<Long, Path> e = pathSet.lastEntry();
    70                 if (e != null) {
    71                 if (e != null) {
    71                     return e.getValue();
    72                     return e.getValue();
    72                 }
    73                 }
    73             }
    74             }
    74             SortedMap<Long, Path> after = pathSet.tailMap(startTimeNanos);
    75             Long f = pathSet.floorKey(startTimeNanos);
    75             if (!after.isEmpty()) {
    76             if (f != null) {
    76                 Path path = after.get(after.firstKey());
    77                 SortedMap<Long, Path> after = pathSet.tailMap(f);
    77                 Logger.log(LogTag.JFR_SYSTEM_STREAMING, LogLevel.TRACE, "Return path " + path + " for start time nanos " + startTimeNanos);
    78                 if (!after.isEmpty()) {
    78                 return path;
    79                     Path path = after.get(after.firstKey());
       
    80                     Logger.log(LogTag.JFR_SYSTEM_STREAMING, LogLevel.TRACE, "Return path " + path + " for start time nanos " + startTimeNanos);
       
    81                     return path;
       
    82                 }
    79             }
    83             }
    80             try {
    84             try {
    81                 if (updatePaths(repostory)) {
    85                 if (updatePaths(repository)) {
    82                     continue;
    86                     continue;
    83                 }
    87                 }
    84             } catch (IOException e) {
    88             } catch (IOException e) {
    85                 Logger.log(LogTag.JFR_SYSTEM_STREAMING, LogLevel.DEBUG, "IOException during repository file scan " + e.getMessage());
    89                 Logger.log(LogTag.JFR_SYSTEM_STREAMING, LogLevel.DEBUG, "IOException during repository file scan " + e.getMessage());
    86                 // This can happen if a chunk is being removed
    90                 // This can happen if a chunk is being removed