Skip to content

Commit

Permalink
OAK-9467 implement comparable
Browse files Browse the repository at this point in the history
  • Loading branch information
smiroslav authored and dulceanu committed Jul 2, 2021
1 parent 6561c5c commit 4c6ca07
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor;
import org.apache.jackrabbit.oak.segment.spi.persistence.persistentcache.AbstractPersistentCache;
import org.apache.jackrabbit.oak.segment.spi.persistence.persistentcache.SegmentCacheStats;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -63,12 +64,6 @@ public class PersistentDiskCache extends AbstractPersistentCache {

final AtomicLong evictionCount = new AtomicLong();

private static final Comparator<SegmentCacheEntry> sortedByAccessTime = (segmentCacheEntry1, segmentCacheEntry2) -> {
FileTime lastAccessFile1 = segmentCacheEntry1.getLastAccessTime();
FileTime lastAccessFile2 = segmentCacheEntry2.getLastAccessTime();
return lastAccessFile1.compareTo(lastAccessFile2);
};

public PersistentDiskCache(File directory, int cacheMaxSizeMB, IOMonitor diskCacheIOMonitor) {
this.directory = directory;
this.maxCacheSizeBytes = cacheMaxSizeMB * 1024L * 1024L;
Expand Down Expand Up @@ -198,7 +193,7 @@ private void cleanUpInternal() {
return new SegmentCacheEntry(path, FileTime.fromMillis(Long.MAX_VALUE));
}
})
.sorted(sortedByAccessTime);
.sorted(Comparator.naturalOrder());

StreamConsumer.forEach(segmentCacheEntryStream, (segmentCacheEntry, breaker) -> {

Expand All @@ -217,7 +212,7 @@ private void cleanUpInternal() {
}
}

private static class SegmentCacheEntry {
private static class SegmentCacheEntry implements Comparable<SegmentCacheEntry>{
private Path path;
private FileTime lastAccessTime;

Expand All @@ -233,6 +228,11 @@ public Path getPath() {
public FileTime getLastAccessTime() {
return lastAccessTime;
}

@Override
public int compareTo(@NotNull SegmentCacheEntry segmentCacheEntry) {
return this.lastAccessTime.compareTo(segmentCacheEntry.lastAccessTime);
}
}
static class StreamConsumer {

Expand Down

0 comments on commit 4c6ca07

Please sign in to comment.