Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 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.link.impl; |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 17 | |
Simon Hunt | ff66374 | 2015-05-14 13:33:05 -0700 | [diff] [blame] | 18 | import com.google.common.base.Predicate; |
| 19 | import com.google.common.collect.FluentIterable; |
| 20 | import com.google.common.collect.Sets; |
tom | db0d03f | 2014-08-27 16:34:15 -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; |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 24 | import org.apache.felix.scr.annotations.Reference; |
| 25 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 26 | import org.apache.felix.scr.annotations.Service; |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame^] | 27 | import org.onosproject.core.Permission; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 28 | import org.onosproject.event.EventDeliveryService; |
Simon Hunt | ff66374 | 2015-05-14 13:33:05 -0700 | [diff] [blame] | 29 | import org.onosproject.event.ListenerRegistry; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 30 | import org.onosproject.net.ConnectPoint; |
| 31 | import org.onosproject.net.DeviceId; |
| 32 | import org.onosproject.net.Link; |
| 33 | import org.onosproject.net.Link.State; |
| 34 | import org.onosproject.net.MastershipRole; |
| 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.link.LinkAdminService; |
| 39 | import org.onosproject.net.link.LinkDescription; |
| 40 | import org.onosproject.net.link.LinkEvent; |
| 41 | import org.onosproject.net.link.LinkListener; |
| 42 | import org.onosproject.net.link.LinkProvider; |
| 43 | import org.onosproject.net.link.LinkProviderRegistry; |
| 44 | import org.onosproject.net.link.LinkProviderService; |
| 45 | import org.onosproject.net.link.LinkService; |
| 46 | import org.onosproject.net.link.LinkStore; |
| 47 | import org.onosproject.net.link.LinkStoreDelegate; |
| 48 | import org.onosproject.net.provider.AbstractProviderRegistry; |
| 49 | import org.onosproject.net.provider.AbstractProviderService; |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 50 | import org.slf4j.Logger; |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 51 | |
Simon Hunt | ff66374 | 2015-05-14 13:33:05 -0700 | [diff] [blame] | 52 | import java.util.Set; |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 53 | |
Ray Milkey | 7bbeb3f | 2014-12-11 14:59:26 -0800 | [diff] [blame] | 54 | import static com.google.common.base.Preconditions.checkNotNull; |
| 55 | import static org.slf4j.LoggerFactory.getLogger; |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame^] | 56 | import static org.onosproject.security.AppGuard.checkPermission; |
| 57 | |
Ray Milkey | 7bbeb3f | 2014-12-11 14:59:26 -0800 | [diff] [blame] | 58 | |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 59 | /** |
| 60 | * Provides basic implementation of the link SB & NB APIs. |
| 61 | */ |
| 62 | @Component(immediate = true) |
| 63 | @Service |
tom | 35c0dc3 | 2014-09-19 10:00:58 -0700 | [diff] [blame] | 64 | public class LinkManager |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 65 | extends AbstractProviderRegistry<LinkProvider, LinkProviderService> |
| 66 | implements LinkService, LinkAdminService, LinkProviderRegistry { |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 67 | |
| 68 | private static final String DEVICE_ID_NULL = "Device ID cannot be null"; |
| 69 | private static final String LINK_DESC_NULL = "Link description cannot be null"; |
| 70 | private static final String CONNECT_POINT_NULL = "Connection point cannot be null"; |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 71 | |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 72 | private final Logger log = getLogger(getClass()); |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 73 | |
Simon Hunt | ff66374 | 2015-05-14 13:33:05 -0700 | [diff] [blame] | 74 | protected final ListenerRegistry<LinkEvent, LinkListener> |
| 75 | listenerRegistry = new ListenerRegistry<>(); |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 76 | |
alshabib | b5522ff | 2014-09-29 19:20:00 -0700 | [diff] [blame] | 77 | private final LinkStoreDelegate delegate = new InternalStoreDelegate(); |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 78 | |
| 79 | private final DeviceListener deviceListener = new InternalDeviceListener(); |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 80 | |
| 81 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
tom | 35c0dc3 | 2014-09-19 10:00:58 -0700 | [diff] [blame] | 82 | protected LinkStore store; |
| 83 | |
| 84 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 85 | protected DeviceService deviceService; |
tom | 4c6606f | 2014-09-07 11:11:21 -0700 | [diff] [blame] | 86 | |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 87 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
tom | 0d39526 | 2014-09-07 16:53:40 -0700 | [diff] [blame] | 88 | protected EventDeliveryService eventDispatcher; |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 89 | |
| 90 | @Activate |
| 91 | public void activate() { |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 92 | store.setDelegate(delegate); |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 93 | eventDispatcher.addSink(LinkEvent.class, listenerRegistry); |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 94 | deviceService.addListener(deviceListener); |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 95 | log.info("Started"); |
| 96 | } |
| 97 | |
| 98 | @Deactivate |
| 99 | public void deactivate() { |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 100 | store.unsetDelegate(delegate); |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 101 | eventDispatcher.removeSink(LinkEvent.class); |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 102 | deviceService.removeListener(deviceListener); |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 103 | log.info("Stopped"); |
| 104 | } |
| 105 | |
| 106 | @Override |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 107 | public int getLinkCount() { |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame^] | 108 | checkPermission(Permission.LINK_READ); |
| 109 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 110 | return store.getLinkCount(); |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public Iterable<Link> getLinks() { |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame^] | 115 | checkPermission(Permission.LINK_READ); |
| 116 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 117 | return store.getLinks(); |
| 118 | } |
| 119 | |
| 120 | @Override |
Yuta HIGUCHI | f1f2ac0 | 2014-11-26 14:02:22 -0800 | [diff] [blame] | 121 | public Iterable<Link> getActiveLinks() { |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame^] | 122 | checkPermission(Permission.LINK_READ); |
| 123 | |
Yuta HIGUCHI | f1f2ac0 | 2014-11-26 14:02:22 -0800 | [diff] [blame] | 124 | return FluentIterable.from(getLinks()) |
| 125 | .filter(new Predicate<Link>() { |
| 126 | |
| 127 | @Override |
| 128 | public boolean apply(Link input) { |
| 129 | return input.state() == State.ACTIVE; |
| 130 | } |
| 131 | }); |
| 132 | } |
| 133 | |
| 134 | @Override |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 135 | public Set<Link> getDeviceLinks(DeviceId deviceId) { |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame^] | 136 | checkPermission(Permission.LINK_READ); |
| 137 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 138 | checkNotNull(deviceId, DEVICE_ID_NULL); |
| 139 | return Sets.union(store.getDeviceEgressLinks(deviceId), |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 140 | store.getDeviceIngressLinks(deviceId)); |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public Set<Link> getDeviceEgressLinks(DeviceId deviceId) { |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame^] | 145 | checkPermission(Permission.LINK_READ); |
| 146 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 147 | checkNotNull(deviceId, DEVICE_ID_NULL); |
| 148 | return store.getDeviceEgressLinks(deviceId); |
| 149 | } |
| 150 | |
| 151 | @Override |
tom | d176fc4 | 2014-09-08 00:12:30 -0700 | [diff] [blame] | 152 | public Set<Link> getDeviceIngressLinks(DeviceId deviceId) { |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame^] | 153 | checkPermission(Permission.LINK_READ); |
| 154 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 155 | checkNotNull(deviceId, DEVICE_ID_NULL); |
| 156 | return store.getDeviceIngressLinks(deviceId); |
| 157 | } |
| 158 | |
| 159 | @Override |
| 160 | public Set<Link> getLinks(ConnectPoint connectPoint) { |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame^] | 161 | checkPermission(Permission.LINK_READ); |
| 162 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 163 | checkNotNull(connectPoint, CONNECT_POINT_NULL); |
| 164 | return Sets.union(store.getEgressLinks(connectPoint), |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 165 | store.getIngressLinks(connectPoint)); |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public Set<Link> getEgressLinks(ConnectPoint connectPoint) { |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame^] | 170 | checkPermission(Permission.LINK_READ); |
| 171 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 172 | checkNotNull(connectPoint, CONNECT_POINT_NULL); |
| 173 | return store.getEgressLinks(connectPoint); |
| 174 | } |
| 175 | |
| 176 | @Override |
tom | d176fc4 | 2014-09-08 00:12:30 -0700 | [diff] [blame] | 177 | public Set<Link> getIngressLinks(ConnectPoint connectPoint) { |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame^] | 178 | checkPermission(Permission.LINK_READ); |
| 179 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 180 | checkNotNull(connectPoint, CONNECT_POINT_NULL); |
| 181 | return store.getIngressLinks(connectPoint); |
| 182 | } |
| 183 | |
| 184 | @Override |
tom | d176fc4 | 2014-09-08 00:12:30 -0700 | [diff] [blame] | 185 | public Link getLink(ConnectPoint src, ConnectPoint dst) { |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame^] | 186 | checkPermission(Permission.LINK_READ); |
| 187 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 188 | checkNotNull(src, CONNECT_POINT_NULL); |
| 189 | checkNotNull(dst, CONNECT_POINT_NULL); |
tom | d176fc4 | 2014-09-08 00:12:30 -0700 | [diff] [blame] | 190 | return store.getLink(src, dst); |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public void removeLinks(ConnectPoint connectPoint) { |
Ayaka Koshibe | b5c63a0 | 2014-10-18 18:42:27 -0700 | [diff] [blame] | 195 | if (deviceService.getRole(connectPoint.deviceId()) != MastershipRole.MASTER) { |
| 196 | return; |
| 197 | } |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 198 | removeLinks(getLinks(connectPoint), false); |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public void removeLinks(DeviceId deviceId) { |
Ayaka Koshibe | b5c63a0 | 2014-10-18 18:42:27 -0700 | [diff] [blame] | 203 | if (deviceService.getRole(deviceId) != MastershipRole.MASTER) { |
| 204 | return; |
| 205 | } |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 206 | removeLinks(getDeviceLinks(deviceId), false); |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public void addListener(LinkListener listener) { |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame^] | 211 | checkPermission(Permission.LINK_EVENT); |
| 212 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 213 | listenerRegistry.addListener(listener); |
| 214 | } |
| 215 | |
| 216 | @Override |
| 217 | public void removeListener(LinkListener listener) { |
Changhoon Yoon | 541ef71 | 2015-05-23 17:18:34 +0900 | [diff] [blame^] | 218 | checkPermission(Permission.LINK_EVENT); |
| 219 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 220 | listenerRegistry.removeListener(listener); |
| 221 | } |
| 222 | |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 223 | // Auxiliary interceptor for device remove events to prune links that |
| 224 | // are associated with the removed device or its port. |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 225 | private class InternalDeviceListener implements DeviceListener { |
tom | 89b63c5 | 2014-09-16 09:19:51 -0700 | [diff] [blame] | 226 | @Override |
| 227 | public void event(DeviceEvent event) { |
| 228 | if (event.type() == DeviceEvent.Type.DEVICE_REMOVED) { |
| 229 | removeLinks(event.subject().id()); |
| 230 | } else if (event.type() == DeviceEvent.Type.PORT_REMOVED) { |
| 231 | removeLinks(new ConnectPoint(event.subject().id(), |
| 232 | event.port().number())); |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 237 | @Override |
| 238 | protected LinkProviderService createProviderService(LinkProvider provider) { |
| 239 | return new InternalLinkProviderService(provider); |
| 240 | } |
| 241 | |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 242 | // Personalized link provider service issued to the supplied provider. |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 243 | private class InternalLinkProviderService |
| 244 | extends AbstractProviderService<LinkProvider> |
| 245 | implements LinkProviderService { |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 246 | |
tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 247 | InternalLinkProviderService(LinkProvider provider) { |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 248 | super(provider); |
| 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public void linkDetected(LinkDescription linkDescription) { |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 253 | checkNotNull(linkDescription, LINK_DESC_NULL); |
| 254 | checkValidity(); |
Ayaka Koshibe | b5c63a0 | 2014-10-18 18:42:27 -0700 | [diff] [blame] | 255 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 256 | LinkEvent event = store.createOrUpdateLink(provider().id(), |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 257 | linkDescription); |
| 258 | if (event != null) { |
Thomas Vachuska | 0e752bd | 2014-10-22 22:33:41 -0700 | [diff] [blame] | 259 | log.info("Link {} detected", linkDescription); |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 260 | post(event); |
| 261 | } |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | @Override |
| 265 | public void linkVanished(LinkDescription linkDescription) { |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 266 | checkNotNull(linkDescription, LINK_DESC_NULL); |
| 267 | checkValidity(); |
Ayaka Koshibe | b5c63a0 | 2014-10-18 18:42:27 -0700 | [diff] [blame] | 268 | |
| 269 | ConnectPoint src = linkDescription.src(); |
| 270 | ConnectPoint dst = linkDescription.dst(); |
alshabib | dfc7afb | 2014-10-21 20:13:27 -0700 | [diff] [blame] | 271 | |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 272 | LinkEvent event = store.removeOrDownLink(src, dst); |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 273 | if (event != null) { |
| 274 | log.info("Link {} vanished", linkDescription); |
| 275 | post(event); |
| 276 | } |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | @Override |
| 280 | public void linksVanished(ConnectPoint connectPoint) { |
| 281 | checkNotNull(connectPoint, "Connect point cannot be null"); |
| 282 | checkValidity(); |
alshabib | 12288c8 | 2014-10-23 10:24:23 -0700 | [diff] [blame] | 283 | |
Yuta HIGUCHI | ddb7772 | 2014-12-11 19:39:04 -0800 | [diff] [blame] | 284 | log.debug("Links for connection point {} vanished", connectPoint); |
Yuta HIGUCHI | e794cbe | 2014-10-17 13:21:23 -0700 | [diff] [blame] | 285 | // FIXME: This will remove links registered by other providers |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 286 | removeLinks(getLinks(connectPoint), true); |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | @Override |
| 290 | public void linksVanished(DeviceId deviceId) { |
| 291 | checkNotNull(deviceId, DEVICE_ID_NULL); |
| 292 | checkValidity(); |
alshabib | 12288c8 | 2014-10-23 10:24:23 -0700 | [diff] [blame] | 293 | |
Yuta HIGUCHI | ddb7772 | 2014-12-11 19:39:04 -0800 | [diff] [blame] | 294 | log.debug("Links for device {} vanished", deviceId); |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 295 | removeLinks(getDeviceLinks(deviceId), true); |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 296 | } |
| 297 | } |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 298 | |
| 299 | // Removes all links in the specified set and emits appropriate events. |
Praseed Balakrishnan | 00dd1f9 | 2014-11-19 17:12:36 -0800 | [diff] [blame] | 300 | private void removeLinks(Set<Link> links, boolean isSoftRemove) { |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 301 | for (Link link : links) { |
Thomas Vachuska | 57126fe | 2014-11-11 17:13:24 -0800 | [diff] [blame] | 302 | LinkEvent event = isSoftRemove ? |
| 303 | store.removeOrDownLink(link.src(), link.dst()) : |
| 304 | store.removeLink(link.src(), link.dst()); |
Yuta HIGUCHI | ddb7772 | 2014-12-11 19:39:04 -0800 | [diff] [blame] | 305 | if (event != null) { |
| 306 | log.info("Link {} removed/vanished", event.subject()); |
| 307 | post(event); |
| 308 | } |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
| 312 | // Posts the specified event to the local event dispatcher. |
| 313 | private void post(LinkEvent event) { |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 314 | if (event != null) { |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 315 | eventDispatcher.post(event); |
| 316 | } |
| 317 | } |
| 318 | |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 319 | // Store delegate to re-post events emitted from the store. |
| 320 | private class InternalStoreDelegate implements LinkStoreDelegate { |
| 321 | @Override |
| 322 | public void notify(LinkEvent event) { |
| 323 | post(event); |
| 324 | } |
| 325 | } |
tom | db0d03f | 2014-08-27 16:34:15 -0700 | [diff] [blame] | 326 | } |