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