ONOS-3586: Move event handling in HostLocationProvider to a background thread to…
… avoid hogging event dispatcher thread Change-Id: I41ada7a946743854228594345cb636d1c336a2af
Showing
2 changed files
with
15 additions
and
1 deletions
... | @@ -67,8 +67,11 @@ import org.slf4j.Logger; | ... | @@ -67,8 +67,11 @@ import org.slf4j.Logger; |
67 | 67 | ||
68 | import java.util.Dictionary; | 68 | import java.util.Dictionary; |
69 | import java.util.Set; | 69 | import java.util.Set; |
70 | +import java.util.concurrent.ExecutorService; | ||
70 | 71 | ||
71 | import static com.google.common.base.Strings.isNullOrEmpty; | 72 | import static com.google.common.base.Strings.isNullOrEmpty; |
73 | +import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; | ||
74 | +import static org.onlab.util.Tools.groupedThreads; | ||
72 | import static org.slf4j.LoggerFactory.getLogger; | 75 | import static org.slf4j.LoggerFactory.getLogger; |
73 | 76 | ||
74 | /** | 77 | /** |
... | @@ -117,6 +120,8 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -117,6 +120,8 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
117 | "Host Location Provider; default is false") | 120 | "Host Location Provider; default is false") |
118 | private boolean ipv6NeighborDiscovery = false; | 121 | private boolean ipv6NeighborDiscovery = false; |
119 | 122 | ||
123 | + protected ExecutorService eventHandler; | ||
124 | + | ||
120 | /** | 125 | /** |
121 | * Creates an OpenFlow host provider. | 126 | * Creates an OpenFlow host provider. |
122 | */ | 127 | */ |
... | @@ -128,7 +133,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -128,7 +133,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
128 | public void activate(ComponentContext context) { | 133 | public void activate(ComponentContext context) { |
129 | cfgService.registerProperties(getClass()); | 134 | cfgService.registerProperties(getClass()); |
130 | appId = coreService.registerApplication("org.onosproject.provider.host"); | 135 | appId = coreService.registerApplication("org.onosproject.provider.host"); |
131 | - | 136 | + eventHandler = newSingleThreadScheduledExecutor(groupedThreads("onos/host-loc-provider", "event-handler")); |
132 | providerService = providerRegistry.register(this); | 137 | providerService = providerRegistry.register(this); |
133 | packetService.addProcessor(processor, PacketProcessor.advisor(1)); | 138 | packetService.addProcessor(processor, PacketProcessor.advisor(1)); |
134 | deviceService.addListener(deviceListener); | 139 | deviceService.addListener(deviceListener); |
... | @@ -147,6 +152,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -147,6 +152,7 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
147 | providerRegistry.unregister(this); | 152 | providerRegistry.unregister(this); |
148 | packetService.removeProcessor(processor); | 153 | packetService.removeProcessor(processor); |
149 | deviceService.removeListener(deviceListener); | 154 | deviceService.removeListener(deviceListener); |
155 | + eventHandler.shutdown(); | ||
150 | providerService = null; | 156 | providerService = null; |
151 | log.info("Stopped"); | 157 | log.info("Stopped"); |
152 | } | 158 | } |
... | @@ -392,6 +398,10 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid | ... | @@ -392,6 +398,10 @@ public class HostLocationProvider extends AbstractProvider implements HostProvid |
392 | private class InternalDeviceListener implements DeviceListener { | 398 | private class InternalDeviceListener implements DeviceListener { |
393 | @Override | 399 | @Override |
394 | public void event(DeviceEvent event) { | 400 | public void event(DeviceEvent event) { |
401 | + eventHandler.execute(() -> handleEvent(event)); | ||
402 | + } | ||
403 | + | ||
404 | + private void handleEvent(DeviceEvent event) { | ||
395 | Device device = event.subject(); | 405 | Device device = event.subject(); |
396 | switch (event.type()) { | 406 | switch (event.type()) { |
397 | case DEVICE_ADDED: | 407 | case DEVICE_ADDED: | ... | ... |
... | @@ -16,6 +16,8 @@ | ... | @@ -16,6 +16,8 @@ |
16 | package org.onosproject.provider.host.impl; | 16 | package org.onosproject.provider.host.impl; |
17 | 17 | ||
18 | import com.google.common.collect.ImmutableSet; | 18 | import com.google.common.collect.ImmutableSet; |
19 | +import com.google.common.util.concurrent.MoreExecutors; | ||
20 | + | ||
19 | import org.junit.After; | 21 | import org.junit.After; |
20 | import org.junit.Before; | 22 | import org.junit.Before; |
21 | import org.junit.Test; | 23 | import org.junit.Test; |
... | @@ -170,6 +172,8 @@ public class HostLocationProviderTest { | ... | @@ -170,6 +172,8 @@ public class HostLocationProviderTest { |
170 | provider.hostService = hostService; | 172 | provider.hostService = hostService; |
171 | 173 | ||
172 | provider.activate(CTX_FOR_NO_REMOVE); | 174 | provider.activate(CTX_FOR_NO_REMOVE); |
175 | + | ||
176 | + provider.eventHandler = MoreExecutors.newDirectExecutorService(); | ||
173 | } | 177 | } |
174 | 178 | ||
175 | @Test | 179 | @Test | ... | ... |
-
Please register or login to post a comment