diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-07-31 10:08:36 +0200 |
---|---|---|
committer | Duarte Meneses <duarte.meneses@sonarsource.com> | 2015-07-31 12:04:26 +0200 |
commit | 187b5f6f59454df662b29692fb86b0be552b6372 (patch) | |
tree | 678281b49bcf548a9ebcfffeeea0c42f5fabec4b /sonar-home/src/main/java/org/sonar/home/cache | |
parent | 6cd87655c83490cc9f80f10c71a12a09e05378f2 (diff) | |
download | sonarqube-187b5f6f59454df662b29692fb86b0be552b6372.tar.gz sonarqube-187b5f6f59454df662b29692fb86b0be552b6372.zip |
Improve quality
Diffstat (limited to 'sonar-home/src/main/java/org/sonar/home/cache')
-rw-r--r-- | sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java index 640d5c29401..b8fdca5d1d5 100644 --- a/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java +++ b/sonar-home/src/main/java/org/sonar/home/cache/PersistentCache.java @@ -142,7 +142,7 @@ public class PersistentCache { logger.info("cache: clearing"); try { lock(); - deleteCacheEntries(createClearFilter()); + deleteCacheEntries(new DirectoryClearFilter()); } catch (IOException e) { logger.error("Error clearing cache", e); } finally { @@ -157,7 +157,7 @@ public class PersistentCache { logger.info("cache: cleaning"); try { lock(); - deleteCacheEntries(createCleanFilter()); + deleteCacheEntries(new DirectoryCleanFilter(defaultDurationToExpireMs)); } catch (IOException e) { logger.error("Error cleaning cache", e); } finally { @@ -229,26 +229,28 @@ public class PersistentCache { } } - private DirectoryStream.Filter<Path> createClearFilter() throws IOException { - return new DirectoryStream.Filter<Path>() { - @Override - public boolean accept(Path entry) throws IOException { - return !LOCK_FNAME.equals(entry.getFileName().toString()); - } - }; + private static class DirectoryClearFilter implements DirectoryStream.Filter<Path> { + @Override + public boolean accept(Path entry) throws IOException { + return !LOCK_FNAME.equals(entry.getFileName().toString()); + } } - private DirectoryStream.Filter<Path> createCleanFilter() throws IOException { - return new DirectoryStream.Filter<Path>() { - @Override - public boolean accept(Path entry) throws IOException { - if (LOCK_FNAME.equals(entry.getFileName().toString())) { - return false; - } + private static class DirectoryCleanFilter implements DirectoryStream.Filter<Path> { + private long defaultDurationToExpireMs; - return isCacheEntryExpired(entry, PersistentCache.this.defaultDurationToExpireMs); + DirectoryCleanFilter(long defaultDurationToExpireMs) { + this.defaultDurationToExpireMs = defaultDurationToExpireMs; + } + + @Override + public boolean accept(Path entry) throws IOException { + if (LOCK_FNAME.equals(entry.getFileName().toString())) { + return false; } - }; + + return isCacheEntryExpired(entry, defaultDurationToExpireMs); + } } private void putCache(String key, byte[] value) throws IOException { @@ -280,7 +282,7 @@ public class PersistentCache { return true; } - private boolean isCacheEntryExpired(Path cacheEntryPath, long durationToExpireMs) throws IOException { + private static boolean isCacheEntryExpired(Path cacheEntryPath, long durationToExpireMs) throws IOException { BasicFileAttributes attr = Files.readAttributes(cacheEntryPath, BasicFileAttributes.class); long modTime = attr.lastModifiedTime().toMillis(); |