Jonathan Hart
Committed by Thomas Vachuska

Allow registering multiple pre-deactivate hooks for a single app ID.

Applications can be comprised of multiple components and may want to have
each component register its own pre-deactivate hook.

Change-Id: I64f1e5fe95bd50e7b7549685c7da7b1b193087f2
(cherry picked from commit c32585fd)
...@@ -15,10 +15,8 @@ ...@@ -15,10 +15,8 @@
15 */ 15 */
16 package org.onosproject.app.impl; 16 package org.onosproject.app.impl;
17 17
18 -import java.io.InputStream; 18 +import com.google.common.collect.HashMultimap;
19 -import java.util.Map; 19 +import com.google.common.collect.Multimap;
20 -import java.util.Set;
21 -
22 import org.apache.felix.scr.annotations.Activate; 20 import org.apache.felix.scr.annotations.Activate;
23 import org.apache.felix.scr.annotations.Component; 21 import org.apache.felix.scr.annotations.Component;
24 import org.apache.felix.scr.annotations.Deactivate; 22 import org.apache.felix.scr.annotations.Deactivate;
...@@ -41,7 +39,8 @@ import org.onosproject.security.Permission; ...@@ -41,7 +39,8 @@ import org.onosproject.security.Permission;
41 import org.onosproject.security.SecurityUtil; 39 import org.onosproject.security.SecurityUtil;
42 import org.slf4j.Logger; 40 import org.slf4j.Logger;
43 41
44 -import com.google.common.collect.Maps; 42 +import java.io.InputStream;
43 +import java.util.Set;
45 44
46 import static com.google.common.base.Preconditions.checkNotNull; 45 import static com.google.common.base.Preconditions.checkNotNull;
47 import static org.onosproject.app.ApplicationEvent.Type.APP_ACTIVATED; 46 import static org.onosproject.app.ApplicationEvent.Type.APP_ACTIVATED;
...@@ -76,7 +75,7 @@ public class ApplicationManager ...@@ -76,7 +75,7 @@ public class ApplicationManager
76 private boolean initializing; 75 private boolean initializing;
77 76
78 // Application supplied hooks for pre-activation processing. 77 // Application supplied hooks for pre-activation processing.
79 - private final Map<String, Runnable> deactivateHooks = Maps.newConcurrentMap(); 78 + private final Multimap<String, Runnable> deactivateHooks = HashMultimap.create();
80 79
81 @Activate 80 @Activate
82 public void activate() { 81 public void activate() {
...@@ -266,7 +265,7 @@ public class ApplicationManager ...@@ -266,7 +265,7 @@ public class ApplicationManager
266 // Uninstalls all features that define the specified app. 265 // Uninstalls all features that define the specified app.
267 private synchronized boolean uninstallAppFeatures(Application app) throws Exception { 266 private synchronized boolean uninstallAppFeatures(Application app) throws Exception {
268 boolean changed = false; 267 boolean changed = false;
269 - invokeHook(deactivateHooks.get(app.id().name()), app.id()); 268 + deactivateHooks.removeAll(app.id().name()).forEach(hook -> invokeHook(hook, app.id()));
270 for (String name : app.features()) { 269 for (String name : app.features()) {
271 Feature feature = featuresService.getFeature(name); 270 Feature feature = featuresService.getFeature(name);
272 if (feature != null && featuresService.isInstalled(feature)) { 271 if (feature != null && featuresService.isInstalled(feature)) {
......