Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent.impl; |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 17 | |
Brian O'Connor | 86f6f7f | 2014-12-01 17:02:45 -0800 | [diff] [blame] | 18 | import com.google.common.collect.HashMultimap; |
| 19 | import com.google.common.collect.Lists; |
| 20 | import com.google.common.collect.SetMultimap; |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 21 | import org.apache.felix.scr.annotations.Activate; |
| 22 | import org.apache.felix.scr.annotations.Component; |
| 23 | import org.apache.felix.scr.annotations.Deactivate; |
| 24 | import org.apache.felix.scr.annotations.Reference; |
| 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 26 | import org.apache.felix.scr.annotations.Service; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 27 | import org.onosproject.core.ApplicationId; |
| 28 | import org.onosproject.event.Event; |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 29 | import org.onosproject.net.DeviceId; |
| 30 | import org.onosproject.net.ElementId; |
| 31 | import org.onosproject.net.HostId; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 32 | import org.onosproject.net.Link; |
| 33 | import org.onosproject.net.LinkKey; |
| 34 | import org.onosproject.net.NetworkResource; |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 35 | import org.onosproject.net.device.DeviceEvent; |
| 36 | import org.onosproject.net.device.DeviceListener; |
| 37 | import org.onosproject.net.device.DeviceService; |
| 38 | import org.onosproject.net.host.HostEvent; |
| 39 | import org.onosproject.net.host.HostListener; |
| 40 | import org.onosproject.net.host.HostService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 41 | import org.onosproject.net.intent.IntentService; |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 42 | import org.onosproject.net.intent.Key; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 43 | import org.onosproject.net.link.LinkEvent; |
Brian O'Connor | 6de2e20 | 2015-05-21 14:30:41 -0700 | [diff] [blame^] | 44 | import org.onosproject.net.resource.link.LinkResourceEvent; |
| 45 | import org.onosproject.net.resource.link.LinkResourceListener; |
| 46 | import org.onosproject.net.resource.link.LinkResourceService; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 47 | import org.onosproject.net.topology.TopologyEvent; |
| 48 | import org.onosproject.net.topology.TopologyListener; |
| 49 | import org.onosproject.net.topology.TopologyService; |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 50 | import org.slf4j.Logger; |
| 51 | |
Brian O'Connor | 86f6f7f | 2014-12-01 17:02:45 -0800 | [diff] [blame] | 52 | import java.util.Collection; |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 53 | import java.util.Collections; |
Brian O'Connor | 86f6f7f | 2014-12-01 17:02:45 -0800 | [diff] [blame] | 54 | import java.util.HashSet; |
| 55 | import java.util.Set; |
| 56 | import java.util.concurrent.ExecutorService; |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 57 | |
| 58 | import static com.google.common.base.Preconditions.checkArgument; |
| 59 | import static com.google.common.base.Preconditions.checkNotNull; |
| 60 | import static com.google.common.collect.Multimaps.synchronizedSetMultimap; |
| 61 | import static java.util.concurrent.Executors.newSingleThreadExecutor; |
Thomas Vachuska | 6f94ded | 2015-02-21 14:02:38 -0800 | [diff] [blame] | 62 | import static org.onlab.util.Tools.groupedThreads; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 63 | import static org.onosproject.net.LinkKey.linkKey; |
| 64 | import static org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED; |
| 65 | import static org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED; |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 66 | import static org.slf4j.LoggerFactory.getLogger; |
| 67 | |
| 68 | /** |
| 69 | * Entity responsible for tracking installed flows and for monitoring topology |
| 70 | * events to determine what flows are affected by topology changes. |
| 71 | */ |
Ray Milkey | e97ede9 | 2014-11-20 10:43:12 -0800 | [diff] [blame] | 72 | @Component(immediate = true) |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 73 | @Service |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 74 | public class ObjectiveTracker implements ObjectiveTrackerService { |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 75 | |
| 76 | private final Logger log = getLogger(getClass()); |
| 77 | |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 78 | private final SetMultimap<LinkKey, Key> intentsByLink = |
Brian O'Connor | 64a0369d | 2015-02-20 22:02:59 -0800 | [diff] [blame] | 79 | //TODO this could be slow as a point of synchronization |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 80 | synchronizedSetMultimap(HashMultimap.<LinkKey, Key>create()); |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 81 | |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 82 | private final SetMultimap<ElementId, Key> intentsByDevice = |
| 83 | synchronizedSetMultimap(HashMultimap.<ElementId, Key>create()); |
| 84 | |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 85 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 86 | protected TopologyService topologyService; |
| 87 | |
Ray Milkey | e97ede9 | 2014-11-20 10:43:12 -0800 | [diff] [blame] | 88 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 89 | protected LinkResourceService resourceManager; |
| 90 | |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 91 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 92 | protected DeviceService deviceService; |
| 93 | |
| 94 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 95 | protected HostService hostService; |
| 96 | |
Brian O'Connor | 5d55ed4 | 2014-12-01 18:27:47 -0800 | [diff] [blame] | 97 | @Reference(cardinality = ReferenceCardinality.OPTIONAL_UNARY) |
Brian O'Connor | 86f6f7f | 2014-12-01 17:02:45 -0800 | [diff] [blame] | 98 | protected IntentService intentService; |
| 99 | |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 100 | private ExecutorService executorService = |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 101 | newSingleThreadExecutor(groupedThreads("onos/intent", "objectivetracker")); |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 102 | |
| 103 | private TopologyListener listener = new InternalTopologyListener(); |
Ray Milkey | e97ede9 | 2014-11-20 10:43:12 -0800 | [diff] [blame] | 104 | private LinkResourceListener linkResourceListener = |
| 105 | new InternalLinkResourceListener(); |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 106 | private DeviceListener deviceListener = new InternalDeviceListener(); |
| 107 | private HostListener hostListener = new InternalHostListener(); |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 108 | private TopologyChangeDelegate delegate; |
| 109 | |
| 110 | @Activate |
| 111 | public void activate() { |
| 112 | topologyService.addListener(listener); |
Ray Milkey | e97ede9 | 2014-11-20 10:43:12 -0800 | [diff] [blame] | 113 | resourceManager.addListener(linkResourceListener); |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 114 | deviceService.addListener(deviceListener); |
| 115 | hostService.addListener(hostListener); |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 116 | log.info("Started"); |
| 117 | } |
| 118 | |
| 119 | @Deactivate |
| 120 | public void deactivate() { |
| 121 | topologyService.removeListener(listener); |
Ray Milkey | e97ede9 | 2014-11-20 10:43:12 -0800 | [diff] [blame] | 122 | resourceManager.removeListener(linkResourceListener); |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 123 | deviceService.removeListener(deviceListener); |
| 124 | hostService.removeListener(hostListener); |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 125 | log.info("Stopped"); |
| 126 | } |
| 127 | |
Brian O'Connor | 5d55ed4 | 2014-12-01 18:27:47 -0800 | [diff] [blame] | 128 | protected void bindIntentService(IntentService service) { |
| 129 | if (intentService == null) { |
| 130 | intentService = service; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | protected void unbindIntentService(IntentService service) { |
| 135 | if (intentService == service) { |
| 136 | intentService = null; |
| 137 | } |
| 138 | } |
| 139 | |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 140 | @Override |
| 141 | public void setDelegate(TopologyChangeDelegate delegate) { |
| 142 | checkNotNull(delegate, "Delegate cannot be null"); |
| 143 | checkArgument(this.delegate == null || this.delegate == delegate, |
| 144 | "Another delegate already set"); |
| 145 | this.delegate = delegate; |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public void unsetDelegate(TopologyChangeDelegate delegate) { |
| 150 | checkArgument(this.delegate == delegate, "Not the current delegate"); |
| 151 | this.delegate = null; |
| 152 | } |
| 153 | |
| 154 | @Override |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 155 | public void addTrackedResources(Key intentKey, |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 156 | Collection<NetworkResource> resources) { |
| 157 | for (NetworkResource resource : resources) { |
| 158 | if (resource instanceof Link) { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 159 | intentsByLink.put(linkKey((Link) resource), intentKey); |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 160 | } else if (resource instanceof ElementId) { |
| 161 | intentsByDevice.put((ElementId) resource, intentKey); |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 162 | } |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
| 166 | @Override |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 167 | public void removeTrackedResources(Key intentKey, |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 168 | Collection<NetworkResource> resources) { |
| 169 | for (NetworkResource resource : resources) { |
| 170 | if (resource instanceof Link) { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 171 | intentsByLink.remove(linkKey((Link) resource), intentKey); |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 172 | } else if (resource instanceof ElementId) { |
| 173 | intentsByDevice.remove((ElementId) resource, intentKey); |
Thomas Vachuska | b97cf28 | 2014-10-20 23:31:12 -0700 | [diff] [blame] | 174 | } |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
| 178 | // Internal re-actor to topology change events. |
| 179 | private class InternalTopologyListener implements TopologyListener { |
| 180 | @Override |
| 181 | public void event(TopologyEvent event) { |
| 182 | executorService.execute(new TopologyChangeHandler(event)); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | // Re-dispatcher of topology change events. |
| 187 | private class TopologyChangeHandler implements Runnable { |
| 188 | |
| 189 | private final TopologyEvent event; |
| 190 | |
| 191 | TopologyChangeHandler(TopologyEvent event) { |
| 192 | this.event = event; |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public void run() { |
Thomas Vachuska | 7b652ad | 2014-10-30 14:10:51 -0700 | [diff] [blame] | 197 | // If there is no delegate, why bother? Just bail. |
| 198 | if (delegate == null) { |
| 199 | return; |
| 200 | } |
| 201 | |
Ray Milkey | 7c44c05 | 2014-12-05 10:34:54 -0800 | [diff] [blame] | 202 | if (event.reasons() == null || event.reasons().isEmpty()) { |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 203 | delegate.triggerCompile(Collections.emptySet(), true); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 204 | |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 205 | } else { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 206 | Set<Key> toBeRecompiled = new HashSet<>(); |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 207 | boolean recompileOnly = true; |
| 208 | |
| 209 | // Scan through the list of reasons and keep accruing all |
| 210 | // intents that need to be recompiled. |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 211 | for (Event reason : event.reasons()) { |
| 212 | if (reason instanceof LinkEvent) { |
| 213 | LinkEvent linkEvent = (LinkEvent) reason; |
Praseed Balakrishnan | 00dd1f9 | 2014-11-19 17:12:36 -0800 | [diff] [blame] | 214 | if (linkEvent.type() == LINK_REMOVED |
| 215 | || (linkEvent.type() == LINK_UPDATED && |
| 216 | linkEvent.subject().isDurable())) { |
Yuta HIGUCHI | 56df70f | 2014-10-28 22:26:15 -0700 | [diff] [blame] | 217 | final LinkKey linkKey = linkKey(linkEvent.subject()); |
Yuta HIGUCHI | 82e5326 | 2014-11-27 10:28:51 -0800 | [diff] [blame] | 218 | synchronized (intentsByLink) { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 219 | Set<Key> intentKeys = intentsByLink.get(linkKey); |
| 220 | log.debug("recompile triggered by LinkDown {} {}", linkKey, intentKeys); |
| 221 | toBeRecompiled.addAll(intentKeys); |
Yuta HIGUCHI | 82e5326 | 2014-11-27 10:28:51 -0800 | [diff] [blame] | 222 | } |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 223 | } |
Praseed Balakrishnan | 00dd1f9 | 2014-11-19 17:12:36 -0800 | [diff] [blame] | 224 | recompileOnly = recompileOnly && |
| 225 | (linkEvent.type() == LINK_REMOVED || |
| 226 | (linkEvent.type() == LINK_UPDATED && |
| 227 | linkEvent.subject().isDurable())); |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 228 | } |
| 229 | } |
tom | 85258ee | 2014-10-07 00:10:02 -0700 | [diff] [blame] | 230 | delegate.triggerCompile(toBeRecompiled, !recompileOnly); |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
Ray Milkey | e97ede9 | 2014-11-20 10:43:12 -0800 | [diff] [blame] | 235 | /** |
| 236 | * Internal re-actor to resource available events. |
| 237 | */ |
| 238 | private class InternalLinkResourceListener implements LinkResourceListener { |
| 239 | @Override |
| 240 | public void event(LinkResourceEvent event) { |
| 241 | executorService.execute(new ResourceAvailableHandler(event)); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | /* |
| 246 | * Re-dispatcher of resource available events. |
| 247 | */ |
| 248 | private class ResourceAvailableHandler implements Runnable { |
| 249 | |
| 250 | private final LinkResourceEvent event; |
| 251 | |
| 252 | ResourceAvailableHandler(LinkResourceEvent event) { |
| 253 | this.event = event; |
| 254 | } |
| 255 | |
| 256 | @Override |
| 257 | public void run() { |
| 258 | // If there is no delegate, why bother? Just bail. |
| 259 | if (delegate == null) { |
| 260 | return; |
| 261 | } |
| 262 | |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 263 | delegate.triggerCompile(Collections.emptySet(), true); |
Ray Milkey | e97ede9 | 2014-11-20 10:43:12 -0800 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
Brian O'Connor | 72a034c | 2014-11-26 18:24:23 -0800 | [diff] [blame] | 267 | //TODO consider adding flow rule event tracking |
Ray Milkey | e97ede9 | 2014-11-20 10:43:12 -0800 | [diff] [blame] | 268 | |
Brian O'Connor | 86f6f7f | 2014-12-01 17:02:45 -0800 | [diff] [blame] | 269 | private void updateTrackedResources(ApplicationId appId, boolean track) { |
Brian O'Connor | 5d55ed4 | 2014-12-01 18:27:47 -0800 | [diff] [blame] | 270 | if (intentService == null) { |
| 271 | log.debug("Intent service is not bound yet"); |
| 272 | return; |
| 273 | } |
Brian O'Connor | 86f6f7f | 2014-12-01 17:02:45 -0800 | [diff] [blame] | 274 | intentService.getIntents().forEach(intent -> { |
| 275 | if (intent.appId().equals(appId)) { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 276 | Key key = intent.key(); |
Brian O'Connor | 86f6f7f | 2014-12-01 17:02:45 -0800 | [diff] [blame] | 277 | Collection<NetworkResource> resources = Lists.newArrayList(); |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 278 | intentService.getInstallableIntents(key).stream() |
Brian O'Connor | 86f6f7f | 2014-12-01 17:02:45 -0800 | [diff] [blame] | 279 | .map(installable -> installable.resources()) |
| 280 | .forEach(resources::addAll); |
| 281 | if (track) { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 282 | addTrackedResources(key, resources); |
Brian O'Connor | 86f6f7f | 2014-12-01 17:02:45 -0800 | [diff] [blame] | 283 | } else { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 284 | removeTrackedResources(key, resources); |
Brian O'Connor | 86f6f7f | 2014-12-01 17:02:45 -0800 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | }); |
| 288 | } |
Brian O'Connor | b5dcc51 | 2015-03-24 17:28:00 -0700 | [diff] [blame] | 289 | |
| 290 | /* |
| 291 | * Re-dispatcher of device and host events. |
| 292 | */ |
| 293 | private class DeviceAvailabilityHandler implements Runnable { |
| 294 | |
| 295 | private final ElementId id; |
| 296 | private final boolean available; |
| 297 | |
| 298 | DeviceAvailabilityHandler(ElementId id, boolean available) { |
| 299 | this.id = checkNotNull(id); |
| 300 | this.available = available; |
| 301 | } |
| 302 | |
| 303 | @Override |
| 304 | public void run() { |
| 305 | // If there is no delegate, why bother? Just bail. |
| 306 | if (delegate == null) { |
| 307 | return; |
| 308 | } |
| 309 | |
| 310 | // TODO should we recompile on available==true? |
| 311 | delegate.triggerCompile(intentsByDevice.get(id), available); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | |
| 316 | private class InternalDeviceListener implements DeviceListener { |
| 317 | @Override |
| 318 | public void event(DeviceEvent event) { |
| 319 | DeviceEvent.Type type = event.type(); |
| 320 | if (type == DeviceEvent.Type.PORT_ADDED || |
| 321 | type == DeviceEvent.Type.PORT_UPDATED || |
| 322 | type == DeviceEvent.Type.PORT_REMOVED) { |
| 323 | // skip port events for now |
| 324 | return; |
| 325 | } |
| 326 | DeviceId id = event.subject().id(); |
| 327 | // TODO we need to check whether AVAILABILITY_CHANGED means up or down |
| 328 | boolean available = (type == DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED || |
| 329 | type == DeviceEvent.Type.DEVICE_ADDED || |
| 330 | type == DeviceEvent.Type.DEVICE_UPDATED); |
| 331 | executorService.execute(new DeviceAvailabilityHandler(id, available)); |
| 332 | |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | private class InternalHostListener implements HostListener { |
| 337 | @Override |
| 338 | public void event(HostEvent event) { |
| 339 | HostId id = event.subject().id(); |
| 340 | HostEvent.Type type = event.type(); |
| 341 | boolean available = (type == HostEvent.Type.HOST_ADDED); |
| 342 | executorService.execute(new DeviceAvailabilityHandler(id, available)); |
| 343 | } |
| 344 | } |
tom | 95329eb | 2014-10-06 08:40:06 -0700 | [diff] [blame] | 345 | } |