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