Madan Jampani
Committed by Gerrit Code Review

Remove map listener when caching async consistent map is destroyed

Change-Id: I924609fa484d469c6ea290e9c8879d1ab49cf9fa
...@@ -21,6 +21,7 @@ import java.util.function.BiFunction; ...@@ -21,6 +21,7 @@ import java.util.function.BiFunction;
21 import java.util.function.Predicate; 21 import java.util.function.Predicate;
22 22
23 import org.onosproject.store.service.AsyncConsistentMap; 23 import org.onosproject.store.service.AsyncConsistentMap;
24 +import org.onosproject.store.service.MapEventListener;
24 import org.onosproject.store.service.Versioned; 25 import org.onosproject.store.service.Versioned;
25 26
26 import com.google.common.cache.CacheBuilder; 27 import com.google.common.cache.CacheBuilder;
...@@ -51,9 +52,16 @@ public class CachingAsyncConsistentMap<K, V> extends DelegatingAsyncConsistentMa ...@@ -51,9 +52,16 @@ public class CachingAsyncConsistentMap<K, V> extends DelegatingAsyncConsistentMa
51 } 52 }
52 }); 53 });
53 54
55 + private final MapEventListener<K, V> cacheInvalidator = event -> cache.invalidate(event.key());
56 +
54 public CachingAsyncConsistentMap(AsyncConsistentMap<K, V> backingMap) { 57 public CachingAsyncConsistentMap(AsyncConsistentMap<K, V> backingMap) {
55 super(backingMap); 58 super(backingMap);
56 - super.addListener(event -> cache.invalidate(event.key())); 59 + super.addListener(cacheInvalidator);
60 + }
61 +
62 + @Override
63 + public CompletableFuture<Void> destroy() {
64 + return super.destroy().thenCompose(v -> removeListener(cacheInvalidator));
57 } 65 }
58 66
59 @Override 67 @Override
......