Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 1 | /* |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Laboratory |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -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 | */ |
| 16 | |
| 17 | package org.onosproject.incubator.net.routing.impl; |
| 18 | |
| 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 24 | import org.apache.felix.scr.annotations.Service; |
| 25 | import org.onlab.packet.IpAddress; |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 26 | import org.onosproject.event.ListenerService; |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 27 | import org.onosproject.incubator.net.routing.InternalRouteEvent; |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 28 | import org.onosproject.incubator.net.routing.NextHop; |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 29 | import org.onosproject.incubator.net.routing.ResolvedRoute; |
| 30 | import org.onosproject.incubator.net.routing.Route; |
| 31 | import org.onosproject.incubator.net.routing.RouteAdminService; |
| 32 | import org.onosproject.incubator.net.routing.RouteEvent; |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 33 | import org.onosproject.incubator.net.routing.RouteInfo; |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 34 | import org.onosproject.incubator.net.routing.RouteListener; |
| 35 | import org.onosproject.incubator.net.routing.RouteService; |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 36 | import org.onosproject.incubator.net.routing.RouteSet; |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 37 | import org.onosproject.incubator.net.routing.RouteStore; |
| 38 | import org.onosproject.incubator.net.routing.RouteStoreDelegate; |
| 39 | import org.onosproject.incubator.net.routing.RouteTableId; |
| 40 | import org.onosproject.net.Host; |
| 41 | import org.onosproject.net.host.HostEvent; |
| 42 | import org.onosproject.net.host.HostListener; |
| 43 | import org.onosproject.net.host.HostService; |
| 44 | import org.slf4j.Logger; |
| 45 | import org.slf4j.LoggerFactory; |
| 46 | |
| 47 | import javax.annotation.concurrent.GuardedBy; |
| 48 | import java.util.Collection; |
| 49 | import java.util.Collections; |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 50 | import java.util.Comparator; |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 51 | import java.util.HashMap; |
| 52 | import java.util.Map; |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 53 | import java.util.Objects; |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 54 | import java.util.Optional; |
| 55 | import java.util.Set; |
| 56 | import java.util.concurrent.BlockingQueue; |
| 57 | import java.util.concurrent.ExecutorService; |
| 58 | import java.util.concurrent.LinkedBlockingQueue; |
| 59 | import java.util.concurrent.ThreadFactory; |
| 60 | import java.util.function.Function; |
| 61 | import java.util.stream.Collectors; |
| 62 | |
| 63 | import static java.util.concurrent.Executors.newSingleThreadExecutor; |
| 64 | import static org.onlab.util.Tools.groupedThreads; |
| 65 | |
| 66 | /** |
| 67 | * Implementation of the unicast route service. |
| 68 | */ |
| 69 | @Service |
| 70 | @Component |
| 71 | public class RouteManager implements ListenerService<RouteEvent, RouteListener>, |
| 72 | RouteService, RouteAdminService { |
| 73 | |
| 74 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 75 | |
| 76 | private RouteStoreDelegate delegate = new InternalRouteStoreDelegate(); |
| 77 | private InternalHostListener hostListener = new InternalHostListener(); |
| 78 | |
| 79 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 80 | protected RouteStore routeStore; |
| 81 | |
| 82 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 83 | protected HostService hostService; |
| 84 | |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 85 | private ResolvedRouteStore resolvedRouteStore; |
| 86 | |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 87 | @GuardedBy(value = "this") |
| 88 | private Map<RouteListener, ListenerQueue> listeners = new HashMap<>(); |
| 89 | |
| 90 | private ThreadFactory threadFactory; |
| 91 | |
| 92 | @Activate |
| 93 | protected void activate() { |
Yuta HIGUCHI | 1624df1 | 2016-07-21 16:54:33 -0700 | [diff] [blame] | 94 | threadFactory = groupedThreads("onos/route", "listener-%d", log); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 95 | |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 96 | resolvedRouteStore = new DefaultResolvedRouteStore(); |
| 97 | |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 98 | routeStore.setDelegate(delegate); |
| 99 | hostService.addListener(hostListener); |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 100 | |
| 101 | routeStore.getRouteTables().stream() |
| 102 | .flatMap(id -> routeStore.getRoutes(id).stream()) |
| 103 | .forEach(this::resolve); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | @Deactivate |
| 107 | protected void deactivate() { |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 108 | listeners.values().forEach(ListenerQueue::stop); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 109 | |
| 110 | routeStore.unsetDelegate(delegate); |
| 111 | hostService.removeListener(hostListener); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * {@inheritDoc} |
| 116 | * |
| 117 | * In a departure from other services in ONOS, calling addListener will |
| 118 | * cause all current routes to be pushed to the listener before any new |
| 119 | * events are sent. This allows a listener to easily get the exact set of |
| 120 | * routes without worrying about missing any. |
| 121 | * |
| 122 | * @param listener listener to be added |
| 123 | */ |
| 124 | @Override |
| 125 | public void addListener(RouteListener listener) { |
| 126 | synchronized (this) { |
| 127 | log.debug("Synchronizing current routes to new listener"); |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 128 | ListenerQueue l = createListenerQueue(listener); |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 129 | resolvedRouteStore.getRouteTables().stream() |
| 130 | .map(resolvedRouteStore::getRoutes) |
| 131 | .flatMap(Collection::stream) |
| 132 | .map(route -> new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)) |
| 133 | .forEach(l::post); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 134 | |
| 135 | listeners.put(listener, l); |
| 136 | |
| 137 | l.start(); |
| 138 | log.debug("Route synchronization complete"); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public void removeListener(RouteListener listener) { |
| 144 | synchronized (this) { |
| 145 | ListenerQueue l = listeners.remove(listener); |
| 146 | if (l != null) { |
| 147 | l.stop(); |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Posts an event to all listeners. |
| 154 | * |
| 155 | * @param event event |
| 156 | */ |
| 157 | private void post(RouteEvent event) { |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 158 | if (event != null) { |
| 159 | log.debug("Sending event {}", event); |
| 160 | synchronized (this) { |
| 161 | listeners.values().forEach(l -> l.post(event)); |
| 162 | } |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public Map<RouteTableId, Collection<Route>> getAllRoutes() { |
| 168 | return routeStore.getRouteTables().stream() |
| 169 | .collect(Collectors.toMap(Function.identity(), |
| 170 | table -> (table == null) ? |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 171 | Collections.emptySet() : reformatRoutes(routeStore.getRoutes(table)))); |
| 172 | } |
| 173 | |
| 174 | private Collection<Route> reformatRoutes(Collection<RouteSet> routeSets) { |
| 175 | return routeSets.stream().flatMap(r -> r.routes().stream()).collect(Collectors.toList()); |
| 176 | } |
| 177 | |
| 178 | public Collection<RouteTableId> getRouteTables() { |
| 179 | return routeStore.getRouteTables(); |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | public Collection<RouteInfo> getRoutes(RouteTableId id) { |
| 184 | return routeStore.getRoutes(id).stream() |
| 185 | .map(routeSet -> new RouteInfo(routeSet.prefix(), |
| 186 | resolvedRouteStore.getRoute(routeSet.prefix()).orElse(null), resolveRouteSet(routeSet))) |
| 187 | .collect(Collectors.toList()); |
| 188 | } |
| 189 | |
| 190 | private Set<ResolvedRoute> resolveRouteSet(RouteSet routeSet) { |
| 191 | return routeSet.routes().stream() |
| 192 | .map(this::tryResolve) |
| 193 | .collect(Collectors.toSet()); |
| 194 | } |
| 195 | |
| 196 | private ResolvedRoute tryResolve(Route route) { |
| 197 | ResolvedRoute resolvedRoute = resolve(route); |
| 198 | if (resolvedRoute == null) { |
| 199 | resolvedRoute = new ResolvedRoute(route, null, null); |
| 200 | } |
| 201 | return resolvedRoute; |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public Route longestPrefixMatch(IpAddress ip) { |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 206 | return longestPrefixLookup(ip) |
| 207 | .map(r -> new Route(Route.Source.STATIC, r.prefix(), r.nextHop())) |
| 208 | .orElse(null); |
| 209 | } |
| 210 | |
| 211 | @Override |
| 212 | public Optional<ResolvedRoute> longestPrefixLookup(IpAddress ip) { |
| 213 | return resolvedRouteStore.longestPrefixMatch(ip); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | @Override |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 217 | public Collection<Route> getRoutesForNextHop(IpAddress nextHop) { |
| 218 | return routeStore.getRoutesForNextHop(nextHop); |
| 219 | } |
| 220 | |
| 221 | @Override |
| 222 | public Set<NextHop> getNextHops() { |
| 223 | return routeStore.getNextHops().entrySet().stream() |
Charles Chan | c78a098 | 2016-11-09 16:52:11 -0800 | [diff] [blame] | 224 | .map(entry -> new NextHop(entry.getKey(), entry.getValue())) |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 225 | .collect(Collectors.toSet()); |
| 226 | } |
| 227 | |
| 228 | @Override |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 229 | public void update(Collection<Route> routes) { |
| 230 | synchronized (this) { |
| 231 | routes.forEach(route -> { |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 232 | log.debug("Received update {}", route); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 233 | routeStore.updateRoute(route); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 234 | }); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | @Override |
| 239 | public void withdraw(Collection<Route> routes) { |
| 240 | synchronized (this) { |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 241 | routes.forEach(route -> { |
Charles Chan | b21d69a | 2016-11-11 17:46:14 -0800 | [diff] [blame] | 242 | log.debug("Received withdraw {}", route); |
Jonathan Hart | fd17661 | 2016-04-11 10:42:10 -0700 | [diff] [blame] | 243 | routeStore.removeRoute(route); |
| 244 | }); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 248 | private ResolvedRoute resolve(Route route) { |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 249 | hostService.startMonitoringIp(route.nextHop()); |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 250 | Set<Host> hosts = hostService.getHostsByIp(route.nextHop()); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 251 | |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 252 | Optional<Host> host = hosts.stream().findFirst(); |
| 253 | if (host.isPresent()) { |
Charles Chan | 92ca94d | 2017-03-17 18:05:22 -0700 | [diff] [blame] | 254 | return new ResolvedRoute(route, host.get().mac(), host.get().vlan(), |
| 255 | host.get().location()); |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 256 | } else { |
| 257 | return null; |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 258 | } |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 259 | } |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 260 | |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 261 | private ResolvedRoute decide(ResolvedRoute route1, ResolvedRoute route2) { |
| 262 | return Comparator.<ResolvedRoute, IpAddress>comparing(route -> route.nextHop()) |
| 263 | .compare(route1, route2) <= 0 ? route1 : route2; |
| 264 | } |
| 265 | |
| 266 | private void store(ResolvedRoute route) { |
| 267 | post(resolvedRouteStore.updateRoute(route)); |
| 268 | } |
| 269 | |
| 270 | private void resolve(RouteSet routes) { |
| 271 | Optional<ResolvedRoute> resolvedRoute = |
| 272 | routes.routes().stream() |
| 273 | .map(this::resolve) |
| 274 | .filter(Objects::nonNull) |
| 275 | .reduce(this::decide); |
| 276 | |
| 277 | if (resolvedRoute.isPresent()) { |
| 278 | this.store(resolvedRoute.get()); |
| 279 | } else { |
| 280 | post(resolvedRouteStore.removeRoute(routes.prefix())); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
| 284 | private void hostUpdated(Host host) { |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 285 | hostChanged(host); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | private void hostRemoved(Host host) { |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 289 | hostChanged(host); |
| 290 | } |
| 291 | |
| 292 | private void hostChanged(Host host) { |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 293 | synchronized (this) { |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 294 | host.ipAddresses().stream() |
| 295 | .flatMap(ip -> routeStore.getRoutesForNextHop(ip).stream()) |
| 296 | .map(route -> routeStore.getRoutes(route.prefix())) |
| 297 | .forEach(this::resolve); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
| 301 | /** |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 302 | * Creates a new listener queue. |
| 303 | * |
| 304 | * @param listener route listener |
| 305 | * @return listener queue |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 306 | */ |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 307 | ListenerQueue createListenerQueue(RouteListener listener) { |
| 308 | return new DefaultListenerQueue(listener); |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * Default route listener queue. |
| 313 | */ |
| 314 | private class DefaultListenerQueue implements ListenerQueue { |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 315 | |
| 316 | private final ExecutorService executorService; |
| 317 | private final BlockingQueue<RouteEvent> queue; |
| 318 | private final RouteListener listener; |
| 319 | |
| 320 | /** |
| 321 | * Creates a new listener queue. |
| 322 | * |
| 323 | * @param listener route listener to queue updates for |
| 324 | */ |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 325 | public DefaultListenerQueue(RouteListener listener) { |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 326 | this.listener = listener; |
| 327 | queue = new LinkedBlockingQueue<>(); |
| 328 | executorService = newSingleThreadExecutor(threadFactory); |
| 329 | } |
| 330 | |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 331 | @Override |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 332 | public void post(RouteEvent event) { |
| 333 | queue.add(event); |
| 334 | } |
| 335 | |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 336 | @Override |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 337 | public void start() { |
| 338 | executorService.execute(this::poll); |
| 339 | } |
| 340 | |
Jonathan Hart | 6c2e796 | 2016-04-11 13:54:09 -0700 | [diff] [blame] | 341 | @Override |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 342 | public void stop() { |
| 343 | executorService.shutdown(); |
| 344 | } |
| 345 | |
| 346 | private void poll() { |
Jonathan Hart | f79ab48 | 2016-08-19 14:20:50 -0700 | [diff] [blame] | 347 | while (true) { |
| 348 | try { |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 349 | listener.event(queue.take()); |
Jonathan Hart | f79ab48 | 2016-08-19 14:20:50 -0700 | [diff] [blame] | 350 | } catch (InterruptedException e) { |
| 351 | log.info("Route listener event thread shutting down: {}", e.getMessage()); |
| 352 | break; |
| 353 | } catch (Exception e) { |
| 354 | log.warn("Exception during route event handler", e); |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 355 | } |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 356 | } |
| 357 | } |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Delegate to receive events from the route store. |
| 362 | */ |
| 363 | private class InternalRouteStoreDelegate implements RouteStoreDelegate { |
| 364 | @Override |
Jonathan Hart | 96c146b | 2017-02-24 16:32:00 -0800 | [diff] [blame] | 365 | public void notify(InternalRouteEvent event) { |
| 366 | switch (event.type()) { |
| 367 | case ROUTE_ADDED: |
| 368 | resolve(event.subject()); |
| 369 | break; |
| 370 | case ROUTE_REMOVED: |
| 371 | resolve(event.subject()); |
| 372 | break; |
| 373 | default: |
| 374 | break; |
| 375 | } |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
| 379 | /** |
| 380 | * Internal listener for host events. |
| 381 | */ |
| 382 | private class InternalHostListener implements HostListener { |
| 383 | @Override |
| 384 | public void event(HostEvent event) { |
| 385 | switch (event.type()) { |
| 386 | case HOST_ADDED: |
| 387 | case HOST_UPDATED: |
| 388 | hostUpdated(event.subject()); |
| 389 | break; |
| 390 | case HOST_REMOVED: |
| 391 | hostRemoved(event.subject()); |
| 392 | break; |
| 393 | case HOST_MOVED: |
| 394 | break; |
| 395 | default: |
| 396 | break; |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
Jonathan Hart | bfc5c48 | 2016-04-05 18:57:00 -0700 | [diff] [blame] | 401 | } |