Committed by
Gerrit Code Review
Move map event handling onto a background thread to unblock even dispatch loop
Change-Id: I171aea6ace67a94aeeefa7b1077dd4a96295c968
Showing
1 changed file
with
9 additions
and
0 deletions
... | @@ -39,6 +39,7 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -39,6 +39,7 @@ import org.apache.felix.scr.annotations.Deactivate; |
39 | import org.apache.felix.scr.annotations.Reference; | 39 | import org.apache.felix.scr.annotations.Reference; |
40 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 40 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
41 | import org.apache.felix.scr.annotations.Service; | 41 | import org.apache.felix.scr.annotations.Service; |
42 | +import org.onlab.util.Tools; | ||
42 | import org.onosproject.mastership.MastershipService; | 43 | import org.onosproject.mastership.MastershipService; |
43 | import org.onosproject.store.serializers.KryoNamespaces; | 44 | import org.onosproject.store.serializers.KryoNamespaces; |
44 | import org.onosproject.store.service.ConsistentMap; | 45 | import org.onosproject.store.service.ConsistentMap; |
... | @@ -60,6 +61,8 @@ import java.util.LinkedHashMap; | ... | @@ -60,6 +61,8 @@ import java.util.LinkedHashMap; |
60 | import java.util.List; | 61 | import java.util.List; |
61 | import java.util.Map; | 62 | import java.util.Map; |
62 | import java.util.Set; | 63 | import java.util.Set; |
64 | +import java.util.concurrent.ExecutorService; | ||
65 | +import java.util.concurrent.Executors; | ||
63 | 66 | ||
64 | import static com.google.common.collect.ImmutableList.of; | 67 | import static com.google.common.collect.ImmutableList.of; |
65 | import static java.util.stream.Collectors.toSet; | 68 | import static java.util.stream.Collectors.toSet; |
... | @@ -114,6 +117,9 @@ public class UiExtensionManager | ... | @@ -114,6 +117,9 @@ public class UiExtensionManager |
114 | 117 | ||
115 | private final ObjectMapper mapper = new ObjectMapper(); | 118 | private final ObjectMapper mapper = new ObjectMapper(); |
116 | 119 | ||
120 | + private final ExecutorService eventHandlingExecutor = | ||
121 | + Executors.newSingleThreadExecutor(Tools.groupedThreads("onos/ui-ext-manager", "event-handler", log)); | ||
122 | + | ||
117 | // Creates core UI extension | 123 | // Creates core UI extension |
118 | private UiExtension createCoreExtension() { | 124 | private UiExtension createCoreExtension() { |
119 | List<UiView> coreViews = of( | 125 | List<UiView> coreViews = of( |
... | @@ -189,6 +195,7 @@ public class UiExtensionManager | ... | @@ -189,6 +195,7 @@ public class UiExtensionManager |
189 | @Deactivate | 195 | @Deactivate |
190 | public void deactivate() { | 196 | public void deactivate() { |
191 | prefsConsistentMap.removeListener(prefsListener); | 197 | prefsConsistentMap.removeListener(prefsListener); |
198 | + eventHandlingExecutor.shutdown(); | ||
192 | UiWebSocketServlet.closeAll(); | 199 | UiWebSocketServlet.closeAll(); |
193 | unregister(core); | 200 | unregister(core); |
194 | log.info("Stopped"); | 201 | log.info("Stopped"); |
... | @@ -286,10 +293,12 @@ public class UiExtensionManager | ... | @@ -286,10 +293,12 @@ public class UiExtensionManager |
286 | implements MapEventListener<String, ObjectNode> { | 293 | implements MapEventListener<String, ObjectNode> { |
287 | @Override | 294 | @Override |
288 | public void event(MapEvent<String, ObjectNode> event) { | 295 | public void event(MapEvent<String, ObjectNode> event) { |
296 | + eventHandlingExecutor.execute(() -> { | ||
289 | String userName = userName(event.key()); | 297 | String userName = userName(event.key()); |
290 | if (event.type() == MapEvent.Type.INSERT || event.type() == MapEvent.Type.UPDATE) { | 298 | if (event.type() == MapEvent.Type.INSERT || event.type() == MapEvent.Type.UPDATE) { |
291 | UiWebSocketServlet.sendToUser(userName, UPDATE_PREFS, jsonPrefs()); | 299 | UiWebSocketServlet.sendToUser(userName, UPDATE_PREFS, jsonPrefs()); |
292 | } | 300 | } |
301 | + }); | ||
293 | } | 302 | } |
294 | 303 | ||
295 | private ObjectNode jsonPrefs() { | 304 | private ObjectNode jsonPrefs() { | ... | ... |
-
Please register or login to post a comment