Committed by
Gerrit Code Review
Move cluster event handling off of event dispatcher thread to a background thread
Change-Id: I17261490898e51088e08ebd50c50c0ae962400d3
Showing
1 changed file
with
13 additions
and
0 deletions
| ... | @@ -16,12 +16,16 @@ | ... | @@ -16,12 +16,16 @@ |
| 16 | 16 | ||
| 17 | package org.onosproject.ui.impl.topo.model; | 17 | package org.onosproject.ui.impl.topo.model; |
| 18 | 18 | ||
| 19 | +import java.util.concurrent.ExecutorService; | ||
| 20 | +import java.util.concurrent.Executors; | ||
| 21 | + | ||
| 19 | import org.apache.felix.scr.annotations.Activate; | 22 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; | 23 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; | 24 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; | 25 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 26 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 24 | import org.apache.felix.scr.annotations.Service; | 27 | import org.apache.felix.scr.annotations.Service; |
| 28 | +import org.onlab.util.Tools; | ||
| 25 | import org.onosproject.cluster.ClusterEvent; | 29 | import org.onosproject.cluster.ClusterEvent; |
| 26 | import org.onosproject.cluster.ClusterEventListener; | 30 | import org.onosproject.cluster.ClusterEventListener; |
| 27 | import org.onosproject.cluster.ClusterService; | 31 | import org.onosproject.cluster.ClusterService; |
| ... | @@ -117,6 +121,8 @@ public final class UiSharedTopologyModel | ... | @@ -117,6 +121,8 @@ public final class UiSharedTopologyModel |
| 117 | private final FlowRuleListener flowRuleListener = | 121 | private final FlowRuleListener flowRuleListener = |
| 118 | new InternalFlowRuleListener(); | 122 | new InternalFlowRuleListener(); |
| 119 | 123 | ||
| 124 | + private ExecutorService eventHandler; | ||
| 125 | + | ||
| 120 | 126 | ||
| 121 | private ModelCache cache; | 127 | private ModelCache cache; |
| 122 | 128 | ||
| ... | @@ -124,6 +130,7 @@ public final class UiSharedTopologyModel | ... | @@ -124,6 +130,7 @@ public final class UiSharedTopologyModel |
| 124 | @Activate | 130 | @Activate |
| 125 | protected void activate() { | 131 | protected void activate() { |
| 126 | cache = new ModelCache(new DefaultServiceBundle(), eventDispatcher); | 132 | cache = new ModelCache(new DefaultServiceBundle(), eventDispatcher); |
| 133 | + eventHandler = Executors.newSingleThreadExecutor(Tools.groupedThreads("onos/ui/topo", "event-handler")); | ||
| 127 | 134 | ||
| 128 | eventDispatcher.addSink(UiModelEvent.class, listenerRegistry); | 135 | eventDispatcher.addSink(UiModelEvent.class, listenerRegistry); |
| 129 | 136 | ||
| ... | @@ -154,6 +161,8 @@ public final class UiSharedTopologyModel | ... | @@ -154,6 +161,8 @@ public final class UiSharedTopologyModel |
| 154 | intentService.removeListener(intentListener); | 161 | intentService.removeListener(intentListener); |
| 155 | flowService.removeListener(flowRuleListener); | 162 | flowService.removeListener(flowRuleListener); |
| 156 | 163 | ||
| 164 | + eventHandler.shutdown(); | ||
| 165 | + | ||
| 157 | cache.clear(); | 166 | cache.clear(); |
| 158 | cache = null; | 167 | cache = null; |
| 159 | 168 | ||
| ... | @@ -231,6 +240,10 @@ public final class UiSharedTopologyModel | ... | @@ -231,6 +240,10 @@ public final class UiSharedTopologyModel |
| 231 | private class InternalClusterListener implements ClusterEventListener { | 240 | private class InternalClusterListener implements ClusterEventListener { |
| 232 | @Override | 241 | @Override |
| 233 | public void event(ClusterEvent event) { | 242 | public void event(ClusterEvent event) { |
| 243 | + eventHandler.execute(() -> handleEvent(event)); | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + private void handleEvent(ClusterEvent event) { | ||
| 234 | ControllerNode cnode = event.subject(); | 247 | ControllerNode cnode = event.subject(); |
| 235 | 248 | ||
| 236 | switch (event.type()) { | 249 | switch (event.type()) { | ... | ... |
-
Please register or login to post a comment