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 | */ |
tom | be98831 | 2014-09-19 18:38:47 -0700 | [diff] [blame] | 16 | package org.onlab.onos.net.device.impl; |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 17 | |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 19 | import static org.onlab.onos.net.MastershipRole.*; |
Yuta HIGUCHI | 63323fd | 2014-11-11 12:16:58 -0800 | [diff] [blame] | 20 | import static org.onlab.util.Tools.namedThreads; |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 21 | import static org.slf4j.LoggerFactory.getLogger; |
| 22 | |
| 23 | import java.util.List; |
Yuta HIGUCHI | 63323fd | 2014-11-11 12:16:58 -0800 | [diff] [blame] | 24 | import java.util.concurrent.Executors; |
| 25 | import java.util.concurrent.ScheduledExecutorService; |
| 26 | import java.util.concurrent.TimeUnit; |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 27 | |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 28 | import org.apache.felix.scr.annotations.Activate; |
| 29 | import org.apache.felix.scr.annotations.Component; |
| 30 | import org.apache.felix.scr.annotations.Deactivate; |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 31 | import org.apache.felix.scr.annotations.Reference; |
| 32 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 33 | import org.apache.felix.scr.annotations.Service; |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 34 | import org.onlab.onos.cluster.ClusterService; |
Yuta HIGUCHI | 8e939d8 | 2014-10-08 08:09:18 -0700 | [diff] [blame] | 35 | import org.onlab.onos.cluster.NodeId; |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 36 | import org.onlab.onos.event.AbstractListenerRegistry; |
| 37 | import org.onlab.onos.event.EventDeliveryService; |
Yuta HIGUCHI | 80912e6 | 2014-10-12 00:15:47 -0700 | [diff] [blame] | 38 | import org.onlab.onos.mastership.MastershipEvent; |
| 39 | import org.onlab.onos.mastership.MastershipListener; |
| 40 | import org.onlab.onos.mastership.MastershipService; |
| 41 | import org.onlab.onos.mastership.MastershipTerm; |
| 42 | import org.onlab.onos.mastership.MastershipTermService; |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 43 | import org.onlab.onos.net.Device; |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 44 | import org.onlab.onos.net.DeviceId; |
| 45 | import org.onlab.onos.net.MastershipRole; |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 46 | import org.onlab.onos.net.Port; |
| 47 | import org.onlab.onos.net.PortNumber; |
Ayaka Koshibe | ea5b4ce | 2014-10-11 14:17:17 -0700 | [diff] [blame] | 48 | import org.onlab.onos.net.device.DefaultDeviceDescription; |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 49 | import org.onlab.onos.net.device.DeviceAdminService; |
Yuta HIGUCHI | 093e83e | 2014-10-10 22:26:11 -0700 | [diff] [blame] | 50 | import org.onlab.onos.net.device.DeviceClockProviderService; |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 51 | import org.onlab.onos.net.device.DeviceDescription; |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 52 | import org.onlab.onos.net.device.DeviceEvent; |
| 53 | import org.onlab.onos.net.device.DeviceListener; |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 54 | import org.onlab.onos.net.device.DeviceProvider; |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 55 | import org.onlab.onos.net.device.DeviceProviderRegistry; |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 56 | import org.onlab.onos.net.device.DeviceProviderService; |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 57 | import org.onlab.onos.net.device.DeviceService; |
tom | 41a2c5f | 2014-09-19 09:20:35 -0700 | [diff] [blame] | 58 | import org.onlab.onos.net.device.DeviceStore; |
tom | f80c972 | 2014-09-24 14:49:18 -0700 | [diff] [blame] | 59 | import org.onlab.onos.net.device.DeviceStoreDelegate; |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 60 | import org.onlab.onos.net.device.PortDescription; |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 61 | import org.onlab.onos.net.provider.AbstractProviderRegistry; |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 62 | import org.onlab.onos.net.provider.AbstractProviderService; |
| 63 | import org.slf4j.Logger; |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 64 | |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 65 | /** |
tom | e472987 | 2014-09-23 00:37:37 -0700 | [diff] [blame] | 66 | * Provides implementation of the device SB & NB APIs. |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 67 | */ |
| 68 | @Component(immediate = true) |
| 69 | @Service |
tom | 41a2c5f | 2014-09-19 09:20:35 -0700 | [diff] [blame] | 70 | public class DeviceManager |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 71 | extends AbstractProviderRegistry<DeviceProvider, DeviceProviderService> |
| 72 | implements DeviceService, DeviceAdminService, DeviceProviderRegistry { |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 73 | |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 74 | private static final String DEVICE_ID_NULL = "Device ID cannot be null"; |
| 75 | private static final String PORT_NUMBER_NULL = "Port number cannot be null"; |
| 76 | private static final String DEVICE_DESCRIPTION_NULL = "Device description cannot be null"; |
| 77 | private static final String PORT_DESCRIPTION_NULL = "Port description cannot be null"; |
| 78 | private static final String ROLE_NULL = "Role cannot be null"; |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 79 | |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 80 | private final Logger log = getLogger(getClass()); |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 81 | |
alshabib | 271a620 | 2014-09-28 22:11:21 -0700 | [diff] [blame] | 82 | protected final AbstractListenerRegistry<DeviceEvent, DeviceListener> listenerRegistry = |
| 83 | new AbstractListenerRegistry<>(); |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 84 | |
alshabib | 339a3d9 | 2014-09-26 17:54:32 -0700 | [diff] [blame] | 85 | private final DeviceStoreDelegate delegate = new InternalStoreDelegate(); |
tom | f80c972 | 2014-09-24 14:49:18 -0700 | [diff] [blame] | 86 | |
tom | c78acee | 2014-09-24 15:16:55 -0700 | [diff] [blame] | 87 | private final MastershipListener mastershipListener = new InternalMastershipListener(); |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 88 | |
Yuta HIGUCHI | 63323fd | 2014-11-11 12:16:58 -0800 | [diff] [blame] | 89 | private ScheduledExecutorService backgroundService; |
| 90 | |
tom | 41a2c5f | 2014-09-19 09:20:35 -0700 | [diff] [blame] | 91 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 92 | protected DeviceStore store; |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 93 | |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 94 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 95 | protected EventDeliveryService eventDispatcher; |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 96 | |
Ayaka Koshibe | a7f044e | 2014-09-23 16:56:20 -0700 | [diff] [blame] | 97 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 98 | protected ClusterService clusterService; |
| 99 | |
| 100 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Ayaka Koshibe | a7f044e | 2014-09-23 16:56:20 -0700 | [diff] [blame] | 101 | protected MastershipService mastershipService; |
| 102 | |
Ayaka Koshibe | 3de43ca | 2014-09-26 16:40:23 -0700 | [diff] [blame] | 103 | protected MastershipTermService termService; |
| 104 | |
Madan Jampani | 61056bc | 2014-09-27 09:07:26 -0700 | [diff] [blame] | 105 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
Yuta HIGUCHI | 093e83e | 2014-10-10 22:26:11 -0700 | [diff] [blame] | 106 | protected DeviceClockProviderService deviceClockProviderService; |
Madan Jampani | 61056bc | 2014-09-27 09:07:26 -0700 | [diff] [blame] | 107 | |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 108 | @Activate |
| 109 | public void activate() { |
Yuta HIGUCHI | 63323fd | 2014-11-11 12:16:58 -0800 | [diff] [blame] | 110 | backgroundService = Executors.newSingleThreadScheduledExecutor(namedThreads("device-manager-background")); |
| 111 | |
tom | f80c972 | 2014-09-24 14:49:18 -0700 | [diff] [blame] | 112 | store.setDelegate(delegate); |
tom | 96dfcab | 2014-08-28 09:26:03 -0700 | [diff] [blame] | 113 | eventDispatcher.addSink(DeviceEvent.class, listenerRegistry); |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 114 | mastershipService.addListener(mastershipListener); |
Ayaka Koshibe | 3de43ca | 2014-09-26 16:40:23 -0700 | [diff] [blame] | 115 | termService = mastershipService.requestTermService(); |
Yuta HIGUCHI | 63323fd | 2014-11-11 12:16:58 -0800 | [diff] [blame] | 116 | |
| 117 | backgroundService.scheduleWithFixedDelay(new Runnable() { |
| 118 | |
| 119 | @Override |
| 120 | public void run() { |
| 121 | try { |
| 122 | mastershipCheck(); |
| 123 | } catch (Exception e) { |
| 124 | log.error("Exception thrown during integrity check", e); |
| 125 | } |
| 126 | } |
| 127 | }, 1, 1, TimeUnit.MINUTES); |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 128 | log.info("Started"); |
| 129 | } |
| 130 | |
| 131 | @Deactivate |
| 132 | public void deactivate() { |
Yuta HIGUCHI | 63323fd | 2014-11-11 12:16:58 -0800 | [diff] [blame] | 133 | backgroundService.shutdown(); |
| 134 | |
tom | f80c972 | 2014-09-24 14:49:18 -0700 | [diff] [blame] | 135 | store.unsetDelegate(delegate); |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 136 | mastershipService.removeListener(mastershipListener); |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 137 | eventDispatcher.removeSink(DeviceEvent.class); |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 138 | log.info("Stopped"); |
| 139 | } |
| 140 | |
| 141 | @Override |
tom | ad2d209 | 2014-09-06 23:24:20 -0700 | [diff] [blame] | 142 | public int getDeviceCount() { |
| 143 | return store.getDeviceCount(); |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | @Override |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 147 | public Iterable<Device> getDevices() { |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 148 | return store.getDevices(); |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 149 | } |
| 150 | |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 151 | @Override |
| 152 | public Device getDevice(DeviceId deviceId) { |
| 153 | checkNotNull(deviceId, DEVICE_ID_NULL); |
tom | 132b58a | 2014-08-28 16:11:28 -0700 | [diff] [blame] | 154 | return store.getDevice(deviceId); |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Override |
tom | ad2d209 | 2014-09-06 23:24:20 -0700 | [diff] [blame] | 158 | public MastershipRole getRole(DeviceId deviceId) { |
| 159 | checkNotNull(deviceId, DEVICE_ID_NULL); |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 160 | return mastershipService.getLocalRole(deviceId); |
tom | ad2d209 | 2014-09-06 23:24:20 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | @Override |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 164 | public List<Port> getPorts(DeviceId deviceId) { |
| 165 | checkNotNull(deviceId, DEVICE_ID_NULL); |
tom | 132b58a | 2014-08-28 16:11:28 -0700 | [diff] [blame] | 166 | return store.getPorts(deviceId); |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public Port getPort(DeviceId deviceId, PortNumber portNumber) { |
| 171 | checkNotNull(deviceId, DEVICE_ID_NULL); |
| 172 | checkNotNull(portNumber, PORT_NUMBER_NULL); |
tom | 132b58a | 2014-08-28 16:11:28 -0700 | [diff] [blame] | 173 | return store.getPort(deviceId, portNumber); |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | @Override |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 177 | public boolean isAvailable(DeviceId deviceId) { |
| 178 | checkNotNull(deviceId, DEVICE_ID_NULL); |
| 179 | return store.isAvailable(deviceId); |
| 180 | } |
| 181 | |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 182 | // Check a device for control channel connectivity. |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 183 | private boolean isReachable(DeviceId deviceId) { |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 184 | if (deviceId == null) { |
| 185 | return false; |
| 186 | } |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 187 | DeviceProvider provider = getProvider(deviceId); |
| 188 | if (provider != null) { |
| 189 | return provider.isReachable(deviceId); |
| 190 | } else { |
Yuta HIGUCHI | 72669c4 | 2014-11-13 14:48:17 -0800 | [diff] [blame] | 191 | log.debug("Provider not found for {}", deviceId); |
Ayaka Koshibe | e60d452 | 2014-10-28 15:07:00 -0700 | [diff] [blame] | 192 | return false; |
| 193 | } |
Ayaka Koshibe | e8708e3 | 2014-10-22 13:40:18 -0700 | [diff] [blame] | 194 | } |
| 195 | |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 196 | @Override |
| 197 | public void removeDevice(DeviceId deviceId) { |
| 198 | checkNotNull(deviceId, DEVICE_ID_NULL); |
| 199 | DeviceEvent event = store.removeDevice(deviceId); |
tom | 0efbb1d | 2014-09-09 11:54:28 -0700 | [diff] [blame] | 200 | if (event != null) { |
| 201 | log.info("Device {} administratively removed", deviceId); |
| 202 | post(event); |
| 203 | } |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 204 | } |
| 205 | |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 206 | @Override |
| 207 | public void addListener(DeviceListener listener) { |
| 208 | listenerRegistry.addListener(listener); |
| 209 | } |
| 210 | |
| 211 | @Override |
| 212 | public void removeListener(DeviceListener listener) { |
| 213 | listenerRegistry.removeListener(listener); |
| 214 | } |
| 215 | |
| 216 | @Override |
alshabib | b7b4063 | 2014-09-28 21:30:00 -0700 | [diff] [blame] | 217 | protected DeviceProviderService createProviderService( |
| 218 | DeviceProvider provider) { |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 219 | return new InternalDeviceProviderService(provider); |
| 220 | } |
| 221 | |
Yuta HIGUCHI | 63323fd | 2014-11-11 12:16:58 -0800 | [diff] [blame] | 222 | /** |
| 223 | * Checks if all the reachable devices have a valid mastership role. |
| 224 | */ |
| 225 | private void mastershipCheck() { |
| 226 | log.debug("Checking mastership"); |
| 227 | for (Device device : getDevices()) { |
| 228 | final DeviceId deviceId = device.id(); |
| 229 | log.debug("Checking device {}", deviceId); |
| 230 | |
| 231 | if (!isReachable(deviceId)) { |
| 232 | continue; |
| 233 | } |
| 234 | |
| 235 | if (mastershipService.getLocalRole(deviceId) != NONE) { |
| 236 | continue; |
| 237 | } |
| 238 | |
| 239 | log.info("{} is reachable but did not have a valid role, reasserting", deviceId); |
| 240 | |
| 241 | // isReachable but was not MASTER or STANDBY, get a role and apply |
| 242 | // Note: NONE triggers request to MastershipService |
| 243 | reassertRole(deviceId, NONE); |
| 244 | } |
| 245 | } |
| 246 | |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 247 | // Personalized device provider service issued to the supplied provider. |
tom | dc361b6 | 2014-09-09 20:36:52 -0700 | [diff] [blame] | 248 | private class InternalDeviceProviderService |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 249 | extends AbstractProviderService<DeviceProvider> |
| 250 | implements DeviceProviderService { |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 251 | |
tom | cfde062 | 2014-09-09 11:02:42 -0700 | [diff] [blame] | 252 | InternalDeviceProviderService(DeviceProvider provider) { |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 253 | super(provider); |
| 254 | } |
| 255 | |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 256 | /** |
| 257 | * Apply role in reaction to provider event. |
| 258 | * |
| 259 | * @param deviceId device identifier |
| 260 | * @param newRole new role to apply to the device |
| 261 | * @return true if the request was sent to provider |
| 262 | */ |
| 263 | private boolean applyRole(DeviceId deviceId, MastershipRole newRole) { |
| 264 | |
| 265 | if (newRole.equals(MastershipRole.NONE)) { |
| 266 | //no-op |
| 267 | return true; |
| 268 | } |
| 269 | |
| 270 | DeviceProvider provider = provider(); |
| 271 | if (provider == null) { |
| 272 | log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole); |
| 273 | return false; |
| 274 | } |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 275 | provider.roleChanged(deviceId, newRole); |
| 276 | // not triggering probe when triggered by provider service event |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 277 | |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 278 | return true; |
| 279 | } |
| 280 | |
| 281 | |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 282 | @Override |
alshabib | b7b4063 | 2014-09-28 21:30:00 -0700 | [diff] [blame] | 283 | public void deviceConnected(DeviceId deviceId, |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 284 | DeviceDescription deviceDescription) { |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 285 | checkNotNull(deviceId, DEVICE_ID_NULL); |
| 286 | checkNotNull(deviceDescription, DEVICE_DESCRIPTION_NULL); |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 287 | checkValidity(); |
Yuta HIGUCHI | 24b2e2a | 2014-10-07 15:53:57 -0700 | [diff] [blame] | 288 | |
| 289 | log.info("Device {} connected", deviceId); |
Yuta HIGUCHI | dfe6e3b | 2014-10-30 11:31:51 -0700 | [diff] [blame] | 290 | final NodeId myNodeId = clusterService.getLocalNode().id(); |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 291 | |
| 292 | // check my Role |
| 293 | mastershipService.requestRoleFor(deviceId); |
| 294 | final MastershipTerm term = termService.getMastershipTerm(deviceId); |
Yuta HIGUCHI | dfe6e3b | 2014-10-30 11:31:51 -0700 | [diff] [blame] | 295 | if (!myNodeId.equals(term.master())) { |
Yuta HIGUCHI | 2d3cd31 | 2014-10-31 11:38:04 -0700 | [diff] [blame] | 296 | log.info("Role of this node is STANDBY for {}", deviceId); |
| 297 | // TODO: Do we need to explicitly tell the Provider that |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 298 | // this instance is not the MASTER |
| 299 | applyRole(deviceId, MastershipRole.STANDBY); |
Yuta HIGUCHI | 24b2e2a | 2014-10-07 15:53:57 -0700 | [diff] [blame] | 300 | return; |
| 301 | } |
Yuta HIGUCHI | 2d3cd31 | 2014-10-31 11:38:04 -0700 | [diff] [blame] | 302 | log.info("Role of this node is MASTER for {}", deviceId); |
Ayaka Koshibe | b5c63a0 | 2014-10-18 18:42:27 -0700 | [diff] [blame] | 303 | |
Yuta HIGUCHI | cf60390 | 2014-10-07 23:04:32 -0700 | [diff] [blame] | 304 | // tell clock provider if this instance is the master |
Yuta HIGUCHI | 093e83e | 2014-10-10 22:26:11 -0700 | [diff] [blame] | 305 | deviceClockProviderService.setMastershipTerm(deviceId, term); |
Yuta HIGUCHI | 24b2e2a | 2014-10-07 15:53:57 -0700 | [diff] [blame] | 306 | |
tom | e5ec3fd | 2014-09-04 15:18:06 -0700 | [diff] [blame] | 307 | DeviceEvent event = store.createOrUpdateDevice(provider().id(), |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 308 | deviceId, deviceDescription); |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 309 | |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 310 | applyRole(deviceId, MastershipRole.MASTER); |
| 311 | |
Yuta HIGUCHI | 24b2e2a | 2014-10-07 15:53:57 -0700 | [diff] [blame] | 312 | // If there was a change of any kind, tell the provider |
Yuta HIGUCHI | cf60390 | 2014-10-07 23:04:32 -0700 | [diff] [blame] | 313 | // that this instance is the master. |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 314 | if (event != null) { |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 315 | log.trace("event: {} {}", event.type(), event); |
tom | 568581d | 2014-09-08 20:13:36 -0700 | [diff] [blame] | 316 | post(event); |
tom | 80c0e5e | 2014-09-08 18:08:58 -0700 | [diff] [blame] | 317 | } |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | @Override |
| 321 | public void deviceDisconnected(DeviceId deviceId) { |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 322 | checkNotNull(deviceId, DEVICE_ID_NULL); |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 323 | checkValidity(); |
Yuta HIGUCHI | cf60390 | 2014-10-07 23:04:32 -0700 | [diff] [blame] | 324 | |
Yuta HIGUCHI | 2d3cd31 | 2014-10-31 11:38:04 -0700 | [diff] [blame] | 325 | log.info("Device {} disconnected from this node", deviceId); |
Ayaka Koshibe | d9f693e | 2014-09-29 18:04:54 -0700 | [diff] [blame] | 326 | |
Ayaka Koshibe | b5c63a0 | 2014-10-18 18:42:27 -0700 | [diff] [blame] | 327 | DeviceEvent event = null; |
| 328 | try { |
| 329 | event = store.markOffline(deviceId); |
| 330 | } catch (IllegalStateException e) { |
Yuta HIGUCHI | eb24e9d | 2014-10-26 19:34:20 -0700 | [diff] [blame] | 331 | log.warn("Failed to mark {} offline", deviceId); |
| 332 | // only the MASTER should be marking off-line in normal cases, |
| 333 | // but if I was the last STANDBY connection, etc. and no one else |
| 334 | // was there to mark the device offline, this instance may need to |
| 335 | // temporarily request for Master Role and mark offline. |
| 336 | |
Ayaka Koshibe | b5c63a0 | 2014-10-18 18:42:27 -0700 | [diff] [blame] | 337 | //there are times when this node will correctly have mastership, BUT |
| 338 | //that isn't reflected in the ClockManager before the device disconnects. |
| 339 | //we want to let go of the device anyways, so make sure this happens. |
Yuta HIGUCHI | 0722fb2 | 2014-10-19 01:16:33 -0700 | [diff] [blame] | 340 | |
Yuta HIGUCHI | eb24e9d | 2014-10-26 19:34:20 -0700 | [diff] [blame] | 341 | // FIXME: Store semantics leaking out as IllegalStateException. |
| 342 | // Consider revising store API to handle this scenario. |
| 343 | |
| 344 | MastershipRole role = mastershipService.requestRoleFor(deviceId); |
Ayaka Koshibe | b5c63a0 | 2014-10-18 18:42:27 -0700 | [diff] [blame] | 345 | MastershipTerm term = termService.getMastershipTerm(deviceId); |
Yuta HIGUCHI | 0722fb2 | 2014-10-19 01:16:33 -0700 | [diff] [blame] | 346 | final NodeId myNodeId = clusterService.getLocalNode().id(); |
| 347 | // TODO: Move this type of check inside device clock manager, etc. |
| 348 | if (myNodeId.equals(term.master())) { |
Yuta HIGUCHI | 2d3cd31 | 2014-10-31 11:38:04 -0700 | [diff] [blame] | 349 | log.info("Retry marking {} offline", deviceId); |
Yuta HIGUCHI | 0722fb2 | 2014-10-19 01:16:33 -0700 | [diff] [blame] | 350 | deviceClockProviderService.setMastershipTerm(deviceId, term); |
| 351 | event = store.markOffline(deviceId); |
Yuta HIGUCHI | eb24e9d | 2014-10-26 19:34:20 -0700 | [diff] [blame] | 352 | } else { |
Yuta HIGUCHI | 2d3cd31 | 2014-10-31 11:38:04 -0700 | [diff] [blame] | 353 | log.info("Failed again marking {} offline. {}", deviceId, role); |
Yuta HIGUCHI | 0722fb2 | 2014-10-19 01:16:33 -0700 | [diff] [blame] | 354 | } |
Ayaka Koshibe | b5c63a0 | 2014-10-18 18:42:27 -0700 | [diff] [blame] | 355 | } finally { |
| 356 | //relinquish master role and ability to be backup. |
| 357 | mastershipService.relinquishMastership(deviceId); |
| 358 | |
| 359 | if (event != null) { |
Yuta HIGUCHI | 2d3cd31 | 2014-10-31 11:38:04 -0700 | [diff] [blame] | 360 | log.info("Device {} disconnected from cluster", deviceId); |
Ayaka Koshibe | b5c63a0 | 2014-10-18 18:42:27 -0700 | [diff] [blame] | 361 | post(event); |
| 362 | } |
tom | 0efbb1d | 2014-09-09 11:54:28 -0700 | [diff] [blame] | 363 | } |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | @Override |
alshabib | b7b4063 | 2014-09-28 21:30:00 -0700 | [diff] [blame] | 367 | public void updatePorts(DeviceId deviceId, |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 368 | List<PortDescription> portDescriptions) { |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 369 | checkNotNull(deviceId, DEVICE_ID_NULL); |
alshabib | b7b4063 | 2014-09-28 21:30:00 -0700 | [diff] [blame] | 370 | checkNotNull(portDescriptions, |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 371 | "Port descriptions list cannot be null"); |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 372 | checkValidity(); |
Yuta HIGUCHI | 13c0b87 | 2014-10-30 18:09:22 -0700 | [diff] [blame] | 373 | if (!deviceClockProviderService.isTimestampAvailable(deviceId)) { |
| 374 | // Never been a master for this device |
| 375 | // any update will be ignored. |
| 376 | log.trace("Ignoring {} port updates on standby node. {}", deviceId, portDescriptions); |
| 377 | return; |
| 378 | } |
| 379 | |
Yuta HIGUCHI | 5f6739c | 2014-10-01 14:04:01 -0700 | [diff] [blame] | 380 | List<DeviceEvent> events = store.updatePorts(this.provider().id(), |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 381 | deviceId, portDescriptions); |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 382 | for (DeviceEvent event : events) { |
| 383 | post(event); |
| 384 | } |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | @Override |
alshabib | b7b4063 | 2014-09-28 21:30:00 -0700 | [diff] [blame] | 388 | public void portStatusChanged(DeviceId deviceId, |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 389 | PortDescription portDescription) { |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 390 | checkNotNull(deviceId, DEVICE_ID_NULL); |
| 391 | checkNotNull(portDescription, PORT_DESCRIPTION_NULL); |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 392 | checkValidity(); |
Ayaka Koshibe | b5c63a0 | 2014-10-18 18:42:27 -0700 | [diff] [blame] | 393 | |
Yuta HIGUCHI | 13c0b87 | 2014-10-30 18:09:22 -0700 | [diff] [blame] | 394 | if (!deviceClockProviderService.isTimestampAvailable(deviceId)) { |
| 395 | // Never been a master for this device |
| 396 | // any update will be ignored. |
| 397 | log.trace("Ignoring {} port update on standby node. {}", deviceId, portDescription); |
| 398 | return; |
| 399 | } |
| 400 | |
Yuta HIGUCHI | eb24e9d | 2014-10-26 19:34:20 -0700 | [diff] [blame] | 401 | final DeviceEvent event = store.updatePortStatus(this.provider().id(), |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 402 | deviceId, portDescription); |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 403 | if (event != null) { |
alshabib | b7b4063 | 2014-09-28 21:30:00 -0700 | [diff] [blame] | 404 | log.info("Device {} port {} status changed", deviceId, event |
| 405 | .port().number()); |
tom | 0efbb1d | 2014-09-09 11:54:28 -0700 | [diff] [blame] | 406 | post(event); |
tom | ff7eb7c | 2014-09-08 12:49:03 -0700 | [diff] [blame] | 407 | } |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 408 | } |
tom | 3f2bbd7 | 2014-09-24 12:07:58 -0700 | [diff] [blame] | 409 | |
| 410 | @Override |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 411 | public void receivedRoleReply( |
| 412 | DeviceId deviceId, MastershipRole requested, MastershipRole response) { |
| 413 | // Several things can happen here: |
| 414 | // 1. request and response match |
| 415 | // 2. request and response don't match |
| 416 | // 3. MastershipRole and requested match (and 1 or 2 are true) |
| 417 | // 4. MastershipRole and requested don't match (and 1 or 2 are true) |
| 418 | // |
| 419 | // 2, 4, and 3 with case 2 are failure modes. |
| 420 | |
tom | 3f2bbd7 | 2014-09-24 12:07:58 -0700 | [diff] [blame] | 421 | // FIXME: implement response to this notification |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 422 | |
| 423 | log.info("got reply to a role request for {}: asked for {}, and got {}", |
| 424 | deviceId, requested, response); |
| 425 | |
| 426 | if (requested == null && response == null) { |
| 427 | // something was off with DeviceProvider, maybe check channel too? |
| 428 | log.warn("Failed to assert role [{}] onto Device {}", requested, deviceId); |
Yuta HIGUCHI | cf60390 | 2014-10-07 23:04:32 -0700 | [diff] [blame] | 429 | mastershipService.relinquishMastership(deviceId); |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 430 | return; |
Yuta HIGUCHI | cf60390 | 2014-10-07 23:04:32 -0700 | [diff] [blame] | 431 | } |
Ayaka Koshibe | 3ef2b0d | 2014-10-31 13:58:27 -0700 | [diff] [blame] | 432 | |
| 433 | if (requested.equals(response)) { |
| 434 | if (requested.equals(mastershipService.getLocalRole(deviceId))) { |
| 435 | |
| 436 | return; |
| 437 | } else { |
| 438 | return; |
| 439 | // FIXME roleManager got the device to comply, but doesn't agree with |
| 440 | // the store; use the store's view, then try to reassert. |
| 441 | } |
| 442 | } else { |
| 443 | // we didn't get back what we asked for. Reelect someone else. |
| 444 | log.warn("Failed to assert role [{}] onto Device {}", response, deviceId); |
| 445 | if (response == MastershipRole.MASTER) { |
| 446 | mastershipService.relinquishMastership(deviceId); |
| 447 | // TODO: Shouldn't we be triggering event? |
| 448 | //final Device device = getDevice(deviceId); |
| 449 | //post(new DeviceEvent(DEVICE_MASTERSHIP_CHANGED, device)); |
| 450 | } |
| 451 | } |
| 452 | |
tom | 3f2bbd7 | 2014-09-24 12:07:58 -0700 | [diff] [blame] | 453 | } |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 454 | } |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 455 | |
tom | eadbb46 | 2014-09-07 16:10:19 -0700 | [diff] [blame] | 456 | // Posts the specified event to the local event dispatcher. |
tom | 32f6684 | 2014-08-27 19:27:47 -0700 | [diff] [blame] | 457 | private void post(DeviceEvent event) { |
| 458 | if (event != null && eventDispatcher != null) { |
| 459 | eventDispatcher.post(event); |
| 460 | } |
| 461 | } |
| 462 | |
Yuta HIGUCHI | 63323fd | 2014-11-11 12:16:58 -0800 | [diff] [blame] | 463 | // Applies the specified role to the device; ignores NONE |
| 464 | /** |
| 465 | * Apply role to device and send probe if MASTER. |
| 466 | * |
| 467 | * @param deviceId device identifier |
| 468 | * @param newRole new role to apply to the device |
| 469 | * @return true if the request was sent to provider |
| 470 | */ |
| 471 | private boolean applyRoleAndProbe(DeviceId deviceId, MastershipRole newRole) { |
| 472 | if (newRole.equals(MastershipRole.NONE)) { |
| 473 | //no-op |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 474 | return true; |
| 475 | } |
Ayaka Koshibe | 317245a | 2014-10-29 00:34:43 -0700 | [diff] [blame] | 476 | |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 477 | DeviceProvider provider = getProvider(deviceId); |
Yuta HIGUCHI | 63323fd | 2014-11-11 12:16:58 -0800 | [diff] [blame] | 478 | if (provider == null) { |
| 479 | log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole); |
| 480 | return false; |
| 481 | } |
| 482 | provider.roleChanged(deviceId, newRole); |
| 483 | |
| 484 | if (newRole.equals(MastershipRole.MASTER)) { |
| 485 | // only trigger event when request was sent to provider |
Ayaka Koshibe | 78bcbc1 | 2014-11-19 14:28:58 -0800 | [diff] [blame] | 486 | provider.triggerProbe(deviceId); |
Yuta HIGUCHI | 63323fd | 2014-11-11 12:16:58 -0800 | [diff] [blame] | 487 | } |
| 488 | return true; |
| 489 | } |
| 490 | |
| 491 | /** |
| 492 | * Reaasert role for specified device connected to this node. |
| 493 | * |
| 494 | * @param did device identifier |
| 495 | * @param nextRole role to apply. If NONE is specified, |
| 496 | * it will ask mastership service for a role and apply it. |
| 497 | */ |
| 498 | private void reassertRole(final DeviceId did, |
| 499 | final MastershipRole nextRole) { |
| 500 | |
| 501 | final NodeId myNodeId = clusterService.getLocalNode().id(); |
| 502 | MastershipRole myNextRole = nextRole; |
| 503 | if (myNextRole == NONE) { |
| 504 | mastershipService.requestRoleFor(did); |
| 505 | MastershipTerm term = termService.getMastershipTerm(did); |
| 506 | if (myNodeId.equals(term.master())) { |
| 507 | myNextRole = MASTER; |
| 508 | } else { |
| 509 | myNextRole = STANDBY; |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | switch (myNextRole) { |
| 514 | case MASTER: |
| 515 | final Device device = getDevice(did); |
| 516 | if ((device != null) && !isAvailable(did)) { |
| 517 | //flag the device as online. Is there a better way to do this? |
| 518 | DefaultDeviceDescription deviceDescription |
| 519 | = new DefaultDeviceDescription(did.uri(), |
| 520 | device.type(), |
| 521 | device.manufacturer(), |
| 522 | device.hwVersion(), |
| 523 | device.swVersion(), |
| 524 | device.serialNumber(), |
| 525 | device.chassisId()); |
| 526 | DeviceEvent devEvent = |
| 527 | store.createOrUpdateDevice(device.providerId(), did, |
| 528 | deviceDescription); |
| 529 | post(devEvent); |
| 530 | } |
| 531 | // TODO: should apply role only if there is mismatch |
| 532 | log.info("Applying role {} to {}", myNextRole, did); |
| 533 | if (!applyRoleAndProbe(did, MASTER)) { |
| 534 | // immediately failed to apply role |
| 535 | mastershipService.relinquishMastership(did); |
| 536 | // FIXME disconnect? |
| 537 | } |
| 538 | break; |
| 539 | case STANDBY: |
| 540 | log.info("Applying role {} to {}", myNextRole, did); |
| 541 | if (!applyRoleAndProbe(did, STANDBY)) { |
| 542 | // immediately failed to apply role |
| 543 | mastershipService.relinquishMastership(did); |
| 544 | // FIXME disconnect? |
| 545 | } |
| 546 | break; |
| 547 | case NONE: |
| 548 | default: |
| 549 | // should never reach here |
| 550 | log.error("You didn't see anything. I did not exist."); |
| 551 | break; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | // Intercepts mastership events |
| 556 | private class InternalMastershipListener implements MastershipListener { |
| 557 | |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 558 | @Override |
| 559 | public void event(MastershipEvent event) { |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 560 | |
| 561 | if (event.type() != MastershipEvent.Type.MASTER_CHANGED) { |
| 562 | // Don't care if backup list changed. |
| 563 | return; |
| 564 | } |
| 565 | |
Ayaka Koshibe | 4c89127 | 2014-10-08 17:14:16 -0700 | [diff] [blame] | 566 | final DeviceId did = event.subject(); |
Ayaka Koshibe | ea5b4ce | 2014-10-11 14:17:17 -0700 | [diff] [blame] | 567 | final NodeId myNodeId = clusterService.getLocalNode().id(); |
Yuta HIGUCHI | 24b2e2a | 2014-10-07 15:53:57 -0700 | [diff] [blame] | 568 | |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 569 | // myRole suggested by MastershipService |
| 570 | MastershipRole myNextRole; |
Yuta HIGUCHI | 67dce88 | 2014-10-21 21:13:26 -0700 | [diff] [blame] | 571 | if (myNodeId.equals(event.roleInfo().master())) { |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 572 | // confirm latest info |
Ayaka Koshibe | ea5b4ce | 2014-10-11 14:17:17 -0700 | [diff] [blame] | 573 | MastershipTerm term = termService.getMastershipTerm(did); |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 574 | final boolean iHaveControl = myNodeId.equals(term.master()); |
| 575 | if (iHaveControl) { |
Yuta HIGUCHI | 38b4d9d | 2014-10-30 11:32:41 -0700 | [diff] [blame] | 576 | deviceClockProviderService.setMastershipTerm(did, term); |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 577 | myNextRole = MASTER; |
Yuta HIGUCHI | 38b4d9d | 2014-10-30 11:32:41 -0700 | [diff] [blame] | 578 | } else { |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 579 | myNextRole = STANDBY; |
| 580 | } |
| 581 | } else if (event.roleInfo().backups().contains(myNodeId)) { |
| 582 | myNextRole = STANDBY; |
| 583 | } else { |
| 584 | myNextRole = NONE; |
| 585 | } |
| 586 | |
| 587 | |
Yuta HIGUCHI | 5481532 | 2014-10-31 23:17:08 -0700 | [diff] [blame] | 588 | final boolean isReachable = isReachable(did); |
Yuta HIGUCHI | d26354d | 2014-10-31 14:14:38 -0700 | [diff] [blame] | 589 | if (!isReachable) { |
| 590 | // device is not connected to this node |
| 591 | if (myNextRole != NONE) { |
| 592 | log.warn("Node was instructed to be {} role for {}, " |
| 593 | + "but this node cannot reach the device. " |
| 594 | + "Relinquishing role. ", |
| 595 | myNextRole, did); |
| 596 | mastershipService.relinquishMastership(did); |
| 597 | } |
| 598 | return; |
| 599 | } |
| 600 | |
| 601 | // device is connected to this node: |
Yuta HIGUCHI | 63323fd | 2014-11-11 12:16:58 -0800 | [diff] [blame] | 602 | reassertRole(did, myNextRole); |
Ayaka Koshibe | 317245a | 2014-10-29 00:34:43 -0700 | [diff] [blame] | 603 | } |
tom | b41d1ac | 2014-09-24 01:51:24 -0700 | [diff] [blame] | 604 | } |
tom | f80c972 | 2014-09-24 14:49:18 -0700 | [diff] [blame] | 605 | |
| 606 | // Store delegate to re-post events emitted from the store. |
alshabib | 271a620 | 2014-09-28 22:11:21 -0700 | [diff] [blame] | 607 | private class InternalStoreDelegate |
Thomas Vachuska | d16ce18 | 2014-10-29 17:25:29 -0700 | [diff] [blame] | 608 | implements DeviceStoreDelegate { |
tom | f80c972 | 2014-09-24 14:49:18 -0700 | [diff] [blame] | 609 | @Override |
| 610 | public void notify(DeviceEvent event) { |
| 611 | post(event); |
| 612 | } |
| 613 | } |
tom | d3097b0 | 2014-08-26 10:40:29 -0700 | [diff] [blame] | 614 | } |