diff options
author | PatrikBuhr <patrik.buhr@est.tech> | 2019-06-03 06:59:50 +0000 |
---|---|---|
committer | PatrikBuhr <patrik.buhr@est.tech> | 2019-06-03 06:59:50 +0000 |
commit | 20b9271b8c93e9911ba49851d0bf6099eef1d97d (patch) | |
tree | 5a598b9f4a0142a6917f6892fcd4cdaf8c5dd6ea /datafile-app-server | |
parent | 4229afc64d82cbd1ea1e43c92fcd6c9bed9e5137 (diff) |
DFC, Purging the cache of published files occasionally fails
Solved a threading issue.
Change-Id: I1272cadd5d8bc8bb8ffc4c3d33c9b5c706470864
Issue-ID: DCAEGEN2-1588
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Diffstat (limited to 'datafile-app-server')
-rw-r--r-- | datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java index ff267815..475e0224 100644 --- a/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java +++ b/datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java @@ -28,7 +28,7 @@ import java.util.Map; * the key was last used. */ public class PublishedFileCache { - private final Map<Path, Instant> publishedFiles = Collections.synchronizedMap(new HashMap<Path, Instant>()); + private final Map<Path, Instant> publishedFiles = new HashMap<Path, Instant>(); /** * Adds a file to the cache. @@ -36,7 +36,7 @@ public class PublishedFileCache { * @param path the name of the file to add. * @return <code>null</code> if the file is not already in the cache. */ - public Instant put(Path path) { + public synchronized Instant put(Path path) { return publishedFiles.put(path, Instant.now()); } @@ -45,7 +45,7 @@ public class PublishedFileCache { * * @param localFileName name of the file to remove. */ - public void remove(Path localFileName) { + public synchronized void remove(Path localFileName) { publishedFiles.remove(localFileName); } @@ -54,7 +54,7 @@ public class PublishedFileCache { * * @param now the instant will determine which files that will be purged. */ - public void purge(Instant now) { + public synchronized void purge(Instant now) { for (Iterator<Map.Entry<Path, Instant>> it = publishedFiles.entrySet().iterator(); it.hasNext();) { Map.Entry<Path, Instant> pair = it.next(); if (isCachedPublishedFileOutdated(now, pair.getValue())) { @@ -63,7 +63,7 @@ public class PublishedFileCache { } } - public int size() { + public synchronized int size() { return publishedFiles.size(); } |