equal
deleted
inserted
replaced
32 import java.util.Collections; |
32 import java.util.Collections; |
33 import java.util.HashMap; |
33 import java.util.HashMap; |
34 import java.util.HashSet; |
34 import java.util.HashSet; |
35 import java.util.List; |
35 import java.util.List; |
36 import java.util.Map; |
36 import java.util.Map; |
|
37 import java.util.Map.Entry; |
|
38 import java.util.NavigableMap; |
37 import java.util.Set; |
39 import java.util.Set; |
38 import java.util.SortedMap; |
40 import java.util.SortedMap; |
39 import java.util.TreeMap; |
41 import java.util.TreeMap; |
40 |
42 |
41 import jdk.jfr.internal.LogLevel; |
43 import jdk.jfr.internal.LogLevel; |
43 import jdk.jfr.internal.Logger; |
45 import jdk.jfr.internal.Logger; |
44 import jdk.jfr.internal.Repository; |
46 import jdk.jfr.internal.Repository; |
45 |
47 |
46 public final class RepositoryFiles { |
48 public final class RepositoryFiles { |
47 private final Path repostory; |
49 private final Path repostory; |
48 private final SortedMap<Long, Path> pathSet = new TreeMap<>(); |
50 private final NavigableMap<Long, Path> pathSet = new TreeMap<>(); |
49 private final Map<Path, Long> pathLookup = new HashMap<>(); |
51 private final Map<Path, Long> pathLookup = new HashMap<>(); |
50 private volatile boolean closed; |
52 private volatile boolean closed; |
51 |
53 |
52 public RepositoryFiles(Path repostory) { |
54 public RepositoryFiles(Path repostory) { |
53 this.repostory = repostory; |
55 this.repostory = repostory; |
55 |
57 |
56 public long getTimestamp(Path p) { |
58 public long getTimestamp(Path p) { |
57 return pathLookup.get(p); |
59 return pathLookup.get(p); |
58 } |
60 } |
59 |
61 |
|
62 public Path lastPath() { |
|
63 return nextPath(-1); |
|
64 } |
|
65 |
60 public Path nextPath(long startTimeNanos) { |
66 public Path nextPath(long startTimeNanos) { |
61 while (!closed) { |
67 while (!closed) { |
|
68 if (startTimeNanos == -1) { |
|
69 Entry<Long, Path> e = pathSet.lastEntry(); |
|
70 if (e != null) { |
|
71 return e.getValue(); |
|
72 } |
|
73 } |
62 SortedMap<Long, Path> after = pathSet.tailMap(startTimeNanos); |
74 SortedMap<Long, Path> after = pathSet.tailMap(startTimeNanos); |
63 if (!after.isEmpty()) { |
75 if (!after.isEmpty()) { |
64 Path path = after.get(after.firstKey()); |
76 Path path = after.get(after.firstKey()); |
65 Logger.log(LogTag.JFR_SYSTEM_STREAMING, LogLevel.TRACE, "Return path " + path + " for start time nanos " + startTimeNanos); |
77 Logger.log(LogTag.JFR_SYSTEM_STREAMING, LogLevel.TRACE, "Return path " + path + " for start time nanos " + startTimeNanos); |
66 return path; |
78 return path; |
145 synchronized (pathSet) { |
157 synchronized (pathSet) { |
146 this.closed = true; |
158 this.closed = true; |
147 pathSet.notify(); |
159 pathSet.notify(); |
148 } |
160 } |
149 } |
161 } |
|
162 |
|
163 |
150 } |
164 } |