HIGUCHI Yuta
Committed by Gerrit Code Review

Fix synchronization issue

- synchronizedMultiMaps needs to be synchronized,
  when iterating over it's contents.
  See:
   http://static.javadoc.io/com.google.guava/guava/18.0/com/google/common/collect/Multimaps.html#synchronizedMultimap(com.google.common.collect.Multimap)

Change-Id: I398079a67e9fab58edc9d6f0295169939e640ba2
......@@ -375,7 +375,12 @@ public class ObjectiveTracker implements ObjectiveTrackerService {
}
// TODO should we recompile on available==true?
delegate.triggerCompile(ImmutableSet.copyOf(intentsByDevice.get(id)), available);
final ImmutableSet<Key> snapshot;
synchronized (intentsByDevice) {
snapshot = ImmutableSet.copyOf(intentsByDevice.get(id));
}
delegate.triggerCompile(snapshot, available);
}
}
......
......@@ -443,7 +443,10 @@ public class DatabaseManager implements StorageService, StorageAdminService {
public void event(ApplicationEvent event) {
if (event.type() == APP_UNINSTALLED || event.type() == APP_DEACTIVATED) {
ApplicationId appId = event.subject().id();
List<DefaultAsyncConsistentMap> mapsToRemove = ImmutableList.copyOf(mapsByApplication.get(appId));
List<DefaultAsyncConsistentMap> mapsToRemove;
synchronized (mapsByApplication) {
mapsToRemove = ImmutableList.copyOf(mapsByApplication.get(appId));
}
mapsToRemove.forEach(DatabaseManager.this::unregisterMap);
if (event.type() == APP_UNINSTALLED) {
mapsToRemove.stream().filter(map -> map.purgeOnUninstall()).forEach(map -> map.clear());
......