Brian O'Connor
Committed by Gerrit Code Review

Moving host mobility event handler to separate thread

Change-Id: Ie394bf5b6025752df70e32d624df8dd497bfc736
...@@ -14,10 +14,13 @@ ...@@ -14,10 +14,13 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 package org.onosproject.mobility; 16 package org.onosproject.mobility;
17 +import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
18 +import static org.onlab.util.Tools.groupedThreads;
17 import static org.slf4j.LoggerFactory.getLogger; 19 import static org.slf4j.LoggerFactory.getLogger;
18 20
19 import java.util.Collection; 21 import java.util.Collection;
20 import java.util.List; 22 import java.util.List;
23 +import java.util.concurrent.ExecutorService;
21 24
22 import org.apache.felix.scr.annotations.Activate; 25 import org.apache.felix.scr.annotations.Activate;
23 import org.apache.felix.scr.annotations.Component; 26 import org.apache.felix.scr.annotations.Component;
...@@ -64,22 +67,26 @@ public class HostMobility { ...@@ -64,22 +67,26 @@ public class HostMobility {
64 protected CoreService coreService; 67 protected CoreService coreService;
65 68
66 private ApplicationId appId; 69 private ApplicationId appId;
70 + private ExecutorService eventHandler;
67 71
68 @Activate 72 @Activate
69 public void activate() { 73 public void activate() {
70 appId = coreService.registerApplication("org.onosproject.mobility"); 74 appId = coreService.registerApplication("org.onosproject.mobility");
75 + eventHandler = newSingleThreadScheduledExecutor(groupedThreads("onos/app-mobility", "event-handler"));
71 hostService.addListener(new InternalHostListener()); 76 hostService.addListener(new InternalHostListener());
72 log.info("Started with Application ID {}", appId.id()); 77 log.info("Started with Application ID {}", appId.id());
73 } 78 }
74 79
75 @Deactivate 80 @Deactivate
76 public void deactivate() { 81 public void deactivate() {
82 + // TODO we never actually add any flow rules
77 flowRuleService.removeFlowRulesById(appId); 83 flowRuleService.removeFlowRulesById(appId);
84 + eventHandler.shutdown();
78 log.info("Stopped"); 85 log.info("Stopped");
79 } 86 }
80 87
81 public class InternalHostListener 88 public class InternalHostListener
82 - implements HostListener { 89 + implements HostListener {
83 90
84 @Override 91 @Override
85 public void event(HostEvent event) { 92 public void event(HostEvent event) {
...@@ -91,14 +98,12 @@ public class HostMobility { ...@@ -91,14 +98,12 @@ public class HostMobility {
91 break; 98 break;
92 case HOST_MOVED: 99 case HOST_MOVED:
93 log.info("Host {} has moved; cleaning up.", event.subject()); 100 log.info("Host {} has moved; cleaning up.", event.subject());
94 - cleanup(event.subject()); 101 + eventHandler.execute(() -> cleanup(event.subject()));
95 break; 102 break;
96 103
97 default: 104 default:
98 break; 105 break;
99 -
100 } 106 }
101 -
102 } 107 }
103 108
104 /** 109 /**
...@@ -129,12 +134,9 @@ public class HostMobility { ...@@ -129,12 +134,9 @@ public class HostMobility {
129 } 134 }
130 } 135 }
131 } 136 }
132 -
133 return flowRules; 137 return flowRules;
134 } 138 }
135 -
136 } 139 }
137 -
138 } 140 }
139 141
140 142
......