DFC, Purging the cache of published files occasionally fails 20/89120/1
authorPatrikBuhr <patrik.buhr@est.tech>
Mon, 3 Jun 2019 06:59:50 +0000 (06:59 +0000)
committerPatrikBuhr <patrik.buhr@est.tech>
Mon, 3 Jun 2019 06:59:50 +0000 (06:59 +0000)
Solved a threading issue.

Change-Id: I1272cadd5d8bc8bb8ffc4c3d33c9b5c706470864
Issue-ID: DCAEGEN2-1588
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
datafile-app-server/src/main/java/org/onap/dcaegen2/collectors/datafile/service/PublishedFileCache.java

index ff26781..475e022 100644 (file)
@@ -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();
     }