blob: 2ecd52566c1b1f001bfe1e24d9431edbcfae3115 [file] [log] [blame]
tom8cc5aa72014-09-19 15:14:43 -07001package org.onlab.onos.store.device.impl;
2
Yuta HIGUCHIf5479702014-09-25 00:09:24 -07003import static com.google.common.base.Predicates.notNull;
Yuta HIGUCHIb5df76d2014-09-27 20:54:00 -07004
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -07005import com.google.common.base.Optional;
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -07006import com.google.common.cache.LoadingCache;
Yuta HIGUCHIf5479702014-09-25 00:09:24 -07007import com.google.common.collect.FluentIterable;
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -07008import com.google.common.collect.ImmutableList;
9import com.google.common.collect.ImmutableSet;
10import com.google.common.collect.ImmutableSet.Builder;
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -070011import com.hazelcast.core.IMap;
12import com.hazelcast.core.ISet;
Yuta HIGUCHIf5479702014-09-25 00:09:24 -070013
tom0872a172014-09-23 11:24:26 -070014import org.apache.felix.scr.annotations.Activate;
15import org.apache.felix.scr.annotations.Component;
16import org.apache.felix.scr.annotations.Deactivate;
tom0872a172014-09-23 11:24:26 -070017import org.apache.felix.scr.annotations.Service;
18import org.onlab.onos.net.DefaultDevice;
19import org.onlab.onos.net.DefaultPort;
20import org.onlab.onos.net.Device;
21import org.onlab.onos.net.DeviceId;
tom0872a172014-09-23 11:24:26 -070022import org.onlab.onos.net.Port;
23import org.onlab.onos.net.PortNumber;
24import org.onlab.onos.net.device.DeviceDescription;
25import org.onlab.onos.net.device.DeviceEvent;
26import org.onlab.onos.net.device.DeviceStore;
tom0755a362014-09-24 11:54:43 -070027import org.onlab.onos.net.device.DeviceStoreDelegate;
tom0872a172014-09-23 11:24:26 -070028import org.onlab.onos.net.device.PortDescription;
29import org.onlab.onos.net.provider.ProviderId;
Yuta HIGUCHIb5df76d2014-09-27 20:54:00 -070030import org.onlab.onos.store.common.AbsentInvalidatingLoadingCache;
31import org.onlab.onos.store.common.AbstractHazelcastStore;
32import org.onlab.onos.store.common.OptionalCacheLoader;
tom0872a172014-09-23 11:24:26 -070033import org.slf4j.Logger;
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -070034
tom0872a172014-09-23 11:24:26 -070035import java.util.ArrayList;
36import java.util.Collections;
37import java.util.HashMap;
38import java.util.HashSet;
39import java.util.Iterator;
40import java.util.List;
41import java.util.Map;
42import java.util.Objects;
43import java.util.Set;
tomca55e642014-09-24 18:28:38 -070044
tom0872a172014-09-23 11:24:26 -070045import static com.google.common.base.Preconditions.checkArgument;
tomb41d1ac2014-09-24 01:51:24 -070046import static com.google.common.cache.CacheBuilder.newBuilder;
tom0872a172014-09-23 11:24:26 -070047import static org.onlab.onos.net.device.DeviceEvent.Type.*;
48import static org.slf4j.LoggerFactory.getLogger;
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -070049
Yuta HIGUCHIc99a8d32014-10-02 17:16:34 -070050//TODO: Add support for multiple provider and annotations
tom8cc5aa72014-09-19 15:14:43 -070051/**
52 * Manages inventory of infrastructure devices using Hazelcast-backed map.
53 */
54@Component(immediate = true)
55@Service
tom0755a362014-09-24 11:54:43 -070056public class DistributedDeviceStore
Yuta HIGUCHI2e963892014-09-27 13:00:39 -070057 extends AbstractHazelcastStore<DeviceEvent, DeviceStoreDelegate>
tomb41d1ac2014-09-24 01:51:24 -070058 implements DeviceStore {
tom8cc5aa72014-09-19 15:14:43 -070059
60 private final Logger log = getLogger(getClass());
61
62 public static final String DEVICE_NOT_FOUND = "Device with ID %s not found";
63
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -070064 // private IMap<DeviceId, DefaultDevice> cache;
65 private IMap<byte[], byte[]> rawDevices;
66 private LoadingCache<DeviceId, Optional<DefaultDevice>> devices;
67
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -070068 // private ISet<DeviceId> availableDevices;
69 private ISet<byte[]> availableDevices;
70
71 // TODO DevicePorts is very inefficient consider restructuring.
72 // private IMap<DeviceId, Map<PortNumber, Port>> devicePorts;
73 private IMap<byte[], byte[]> rawDevicePorts;
74 private LoadingCache<DeviceId, Optional<Map<PortNumber, Port>>> devicePorts;
75
Yuta HIGUCHI63ab3ea2014-09-28 22:08:41 -070076 private String devicesListener;
77
78 private String portsListener;
79
Yuta HIGUCHIbb1fc722014-09-24 00:00:13 -070080 @Override
tom8cc5aa72014-09-19 15:14:43 -070081 @Activate
82 public void activate() {
tomb41d1ac2014-09-24 01:51:24 -070083 super.activate();
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -070084
85 // IMap event handler needs value
86 final boolean includeValue = true;
87
88 // TODO decide on Map name scheme to avoid collision
89 rawDevices = theInstance.getMap("devices");
Yuta HIGUCHI951e7902014-09-23 14:45:11 -070090 final OptionalCacheLoader<DeviceId, DefaultDevice> deviceLoader
Yuta HIGUCHIad4c2182014-09-29 11:16:23 -070091 = new OptionalCacheLoader<>(kryoSerializationService, rawDevices);
tomb41d1ac2014-09-24 01:51:24 -070092 devices = new AbsentInvalidatingLoadingCache<>(newBuilder().build(deviceLoader));
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -070093 // refresh/populate cache based on notification from other instance
Yuta HIGUCHI63ab3ea2014-09-28 22:08:41 -070094 devicesListener = rawDevices.addEntryListener(new RemoteDeviceEventHandler(devices), includeValue);
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -070095
Yuta HIGUCHI951e7902014-09-23 14:45:11 -070096 // TODO cache availableDevices
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -070097 availableDevices = theInstance.getSet("availableDevices");
98
99 rawDevicePorts = theInstance.getMap("devicePorts");
Yuta HIGUCHI951e7902014-09-23 14:45:11 -0700100 final OptionalCacheLoader<DeviceId, Map<PortNumber, Port>> devicePortLoader
Yuta HIGUCHIad4c2182014-09-29 11:16:23 -0700101 = new OptionalCacheLoader<>(kryoSerializationService, rawDevicePorts);
tomb41d1ac2014-09-24 01:51:24 -0700102 devicePorts = new AbsentInvalidatingLoadingCache<>(newBuilder().build(devicePortLoader));
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700103 // refresh/populate cache based on notification from other instance
Yuta HIGUCHI63ab3ea2014-09-28 22:08:41 -0700104 portsListener = rawDevicePorts.addEntryListener(new RemotePortEventHandler(devicePorts), includeValue);
tomca55e642014-09-24 18:28:38 -0700105
106 loadDeviceCache();
Yuta HIGUCHIce58fa72014-09-24 22:15:10 -0700107 loadDevicePortsCache();
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700108
tomb41d1ac2014-09-24 01:51:24 -0700109 log.info("Started");
tom8cc5aa72014-09-19 15:14:43 -0700110 }
111
112 @Deactivate
113 public void deactivate() {
Yuta HIGUCHI63ab3ea2014-09-28 22:08:41 -0700114 rawDevicePorts.removeEntryListener(portsListener);
115 rawDevices.removeEntryListener(devicesListener);
tom8cc5aa72014-09-19 15:14:43 -0700116 log.info("Stopped");
117 }
118
119 @Override
120 public int getDeviceCount() {
tomca55e642014-09-24 18:28:38 -0700121 return devices.asMap().size();
tom8cc5aa72014-09-19 15:14:43 -0700122 }
123
124 @Override
125 public Iterable<Device> getDevices() {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700126 // TODO builder v.s. copyOf. Guava semms to be using copyOf?
tom0872a172014-09-23 11:24:26 -0700127 Builder<Device> builder = ImmutableSet.builder();
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700128 for (Optional<DefaultDevice> e : devices.asMap().values()) {
129 if (e.isPresent()) {
130 builder.add(e.get());
131 }
132 }
133 return builder.build();
tom8cc5aa72014-09-19 15:14:43 -0700134 }
135
tomca55e642014-09-24 18:28:38 -0700136 private void loadDeviceCache() {
Yuta HIGUCHIce58fa72014-09-24 22:15:10 -0700137 for (byte[] keyBytes : rawDevices.keySet()) {
138 final DeviceId id = deserialize(keyBytes);
139 devices.refresh(id);
140 }
141 }
142
143 private void loadDevicePortsCache() {
144 for (byte[] keyBytes : rawDevicePorts.keySet()) {
145 final DeviceId id = deserialize(keyBytes);
146 devicePorts.refresh(id);
tomca55e642014-09-24 18:28:38 -0700147 }
148 }
149
tom8cc5aa72014-09-19 15:14:43 -0700150 @Override
151 public Device getDevice(DeviceId deviceId) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700152 // TODO revisit if ignoring exception is safe.
153 return devices.getUnchecked(deviceId).orNull();
tom8cc5aa72014-09-19 15:14:43 -0700154 }
155
156 @Override
157 public DeviceEvent createOrUpdateDevice(ProviderId providerId, DeviceId deviceId,
tom0872a172014-09-23 11:24:26 -0700158 DeviceDescription deviceDescription) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700159 DefaultDevice device = devices.getUnchecked(deviceId).orNull();
tom8cc5aa72014-09-19 15:14:43 -0700160 if (device == null) {
161 return createDevice(providerId, deviceId, deviceDescription);
162 }
163 return updateDevice(providerId, device, deviceDescription);
164 }
165
166 // Creates the device and returns the appropriate event if necessary.
167 private DeviceEvent createDevice(ProviderId providerId, DeviceId deviceId,
168 DeviceDescription desc) {
169 DefaultDevice device = new DefaultDevice(providerId, deviceId, desc.type(),
170 desc.manufacturer(),
171 desc.hwVersion(), desc.swVersion(),
172 desc.serialNumber());
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700173
tom8cc5aa72014-09-19 15:14:43 -0700174 synchronized (this) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700175 final byte[] deviceIdBytes = serialize(deviceId);
176 rawDevices.put(deviceIdBytes, serialize(device));
177 devices.put(deviceId, Optional.of(device));
178
179 availableDevices.add(deviceIdBytes);
tom8cc5aa72014-09-19 15:14:43 -0700180 }
tomca55e642014-09-24 18:28:38 -0700181 return new DeviceEvent(DEVICE_ADDED, device, null);
tom8cc5aa72014-09-19 15:14:43 -0700182 }
183
184 // Updates the device and returns the appropriate event if necessary.
185 private DeviceEvent updateDevice(ProviderId providerId, DefaultDevice device,
186 DeviceDescription desc) {
187 // We allow only certain attributes to trigger update
188 if (!Objects.equals(device.hwVersion(), desc.hwVersion()) ||
tom0872a172014-09-23 11:24:26 -0700189 !Objects.equals(device.swVersion(), desc.swVersion())) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700190
tom8cc5aa72014-09-19 15:14:43 -0700191 DefaultDevice updated = new DefaultDevice(providerId, device.id(),
192 desc.type(),
193 desc.manufacturer(),
194 desc.hwVersion(),
195 desc.swVersion(),
196 desc.serialNumber());
197 synchronized (this) {
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700198 final byte[] deviceIdBytes = serialize(device.id());
199 rawDevices.put(deviceIdBytes, serialize(updated));
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700200 devices.put(device.id(), Optional.of(updated));
201 availableDevices.add(serialize(device.id()));
tom8cc5aa72014-09-19 15:14:43 -0700202 }
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700203 return new DeviceEvent(DeviceEvent.Type.DEVICE_UPDATED, updated, null);
tom8cc5aa72014-09-19 15:14:43 -0700204 }
205
206 // Otherwise merely attempt to change availability
207 synchronized (this) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700208 boolean added = availableDevices.add(serialize(device.id()));
tom8cc5aa72014-09-19 15:14:43 -0700209 return !added ? null :
210 new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device, null);
211 }
212 }
213
214 @Override
215 public DeviceEvent markOffline(DeviceId deviceId) {
216 synchronized (this) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700217 Device device = devices.getUnchecked(deviceId).orNull();
218 boolean removed = device != null && availableDevices.remove(serialize(deviceId));
tom8cc5aa72014-09-19 15:14:43 -0700219 return !removed ? null :
220 new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device, null);
221 }
222 }
223
224 @Override
Yuta HIGUCHI5f6739c2014-10-01 14:04:01 -0700225 public List<DeviceEvent> updatePorts(ProviderId providerId, DeviceId deviceId,
tom0872a172014-09-23 11:24:26 -0700226 List<PortDescription> portDescriptions) {
tom8cc5aa72014-09-19 15:14:43 -0700227 List<DeviceEvent> events = new ArrayList<>();
228 synchronized (this) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700229 Device device = devices.getUnchecked(deviceId).orNull();
tom8cc5aa72014-09-19 15:14:43 -0700230 checkArgument(device != null, DEVICE_NOT_FOUND, deviceId);
231 Map<PortNumber, Port> ports = getPortMap(deviceId);
232
233 // Add new ports
234 Set<PortNumber> processed = new HashSet<>();
235 for (PortDescription portDescription : portDescriptions) {
236 Port port = ports.get(portDescription.portNumber());
237 events.add(port == null ?
238 createPort(device, portDescription, ports) :
239 updatePort(device, port, portDescription, ports));
240 processed.add(portDescription.portNumber());
241 }
242
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700243 updatePortMap(deviceId, ports);
244
tom8cc5aa72014-09-19 15:14:43 -0700245 events.addAll(pruneOldPorts(device, ports, processed));
246 }
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700247 return FluentIterable.from(events).filter(notNull()).toList();
tom8cc5aa72014-09-19 15:14:43 -0700248 }
249
250 // Creates a new port based on the port description adds it to the map and
251 // Returns corresponding event.
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700252 //@GuardedBy("this")
tom8cc5aa72014-09-19 15:14:43 -0700253 private DeviceEvent createPort(Device device, PortDescription portDescription,
254 Map<PortNumber, Port> ports) {
255 DefaultPort port = new DefaultPort(device, portDescription.portNumber(),
256 portDescription.isEnabled());
257 ports.put(port.number(), port);
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700258 updatePortMap(device.id(), ports);
tom8cc5aa72014-09-19 15:14:43 -0700259 return new DeviceEvent(PORT_ADDED, device, port);
260 }
261
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700262 // Checks if the specified port requires update and if so, it replaces the
tom8cc5aa72014-09-19 15:14:43 -0700263 // existing entry in the map and returns corresponding event.
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700264 //@GuardedBy("this")
tom8cc5aa72014-09-19 15:14:43 -0700265 private DeviceEvent updatePort(Device device, Port port,
266 PortDescription portDescription,
267 Map<PortNumber, Port> ports) {
268 if (port.isEnabled() != portDescription.isEnabled()) {
269 DefaultPort updatedPort =
270 new DefaultPort(device, portDescription.portNumber(),
271 portDescription.isEnabled());
272 ports.put(port.number(), updatedPort);
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700273 updatePortMap(device.id(), ports);
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700274 return new DeviceEvent(PORT_UPDATED, device, updatedPort);
tom8cc5aa72014-09-19 15:14:43 -0700275 }
276 return null;
277 }
278
279 // Prunes the specified list of ports based on which ports are in the
280 // processed list and returns list of corresponding events.
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700281 //@GuardedBy("this")
tom8cc5aa72014-09-19 15:14:43 -0700282 private List<DeviceEvent> pruneOldPorts(Device device,
283 Map<PortNumber, Port> ports,
284 Set<PortNumber> processed) {
285 List<DeviceEvent> events = new ArrayList<>();
286 Iterator<PortNumber> iterator = ports.keySet().iterator();
287 while (iterator.hasNext()) {
288 PortNumber portNumber = iterator.next();
289 if (!processed.contains(portNumber)) {
290 events.add(new DeviceEvent(PORT_REMOVED, device,
291 ports.get(portNumber)));
292 iterator.remove();
293 }
294 }
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700295 if (!events.isEmpty()) {
296 updatePortMap(device.id(), ports);
297 }
tom8cc5aa72014-09-19 15:14:43 -0700298 return events;
299 }
300
301 // Gets the map of ports for the specified device; if one does not already
302 // exist, it creates and registers a new one.
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700303 // WARN: returned value is a copy, changes made to the Map
304 // needs to be written back using updatePortMap
305 //@GuardedBy("this")
tom8cc5aa72014-09-19 15:14:43 -0700306 private Map<PortNumber, Port> getPortMap(DeviceId deviceId) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700307 Map<PortNumber, Port> ports = devicePorts.getUnchecked(deviceId).orNull();
tom8cc5aa72014-09-19 15:14:43 -0700308 if (ports == null) {
309 ports = new HashMap<>();
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700310 // this probably is waste of time in most cases.
311 updatePortMap(deviceId, ports);
tom8cc5aa72014-09-19 15:14:43 -0700312 }
313 return ports;
314 }
315
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700316 //@GuardedBy("this")
317 private void updatePortMap(DeviceId deviceId, Map<PortNumber, Port> ports) {
318 rawDevicePorts.put(serialize(deviceId), serialize(ports));
319 devicePorts.put(deviceId, Optional.of(ports));
320 }
321
tom8cc5aa72014-09-19 15:14:43 -0700322 @Override
Yuta HIGUCHI5f6739c2014-10-01 14:04:01 -0700323 public DeviceEvent updatePortStatus(ProviderId providerId, DeviceId deviceId,
tom0872a172014-09-23 11:24:26 -0700324 PortDescription portDescription) {
tom8cc5aa72014-09-19 15:14:43 -0700325 synchronized (this) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700326 Device device = devices.getUnchecked(deviceId).orNull();
tom8cc5aa72014-09-19 15:14:43 -0700327 checkArgument(device != null, DEVICE_NOT_FOUND, deviceId);
328 Map<PortNumber, Port> ports = getPortMap(deviceId);
329 Port port = ports.get(portDescription.portNumber());
330 return updatePort(device, port, portDescription, ports);
331 }
332 }
333
334 @Override
335 public List<Port> getPorts(DeviceId deviceId) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700336 Map<PortNumber, Port> ports = devicePorts.getUnchecked(deviceId).orNull();
337 return ports == null ? Collections.<Port>emptyList() : ImmutableList.copyOf(ports.values());
tom8cc5aa72014-09-19 15:14:43 -0700338 }
339
340 @Override
341 public Port getPort(DeviceId deviceId, PortNumber portNumber) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700342 Map<PortNumber, Port> ports = devicePorts.getUnchecked(deviceId).orNull();
tom8cc5aa72014-09-19 15:14:43 -0700343 return ports == null ? null : ports.get(portNumber);
344 }
345
346 @Override
347 public boolean isAvailable(DeviceId deviceId) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700348 return availableDevices.contains(serialize(deviceId));
tom8cc5aa72014-09-19 15:14:43 -0700349 }
350
351 @Override
tom8cc5aa72014-09-19 15:14:43 -0700352 public DeviceEvent removeDevice(DeviceId deviceId) {
353 synchronized (this) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700354 byte[] deviceIdBytes = serialize(deviceId);
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700355
356 // TODO conditional remove?
357 Device device = deserialize(rawDevices.remove(deviceIdBytes));
358 devices.invalidate(deviceId);
tom8cc5aa72014-09-19 15:14:43 -0700359 return device == null ? null :
360 new DeviceEvent(DEVICE_REMOVED, device, null);
361 }
362 }
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700363
Yuta HIGUCHIfec9e192014-09-28 14:58:02 -0700364 private class RemoteDeviceEventHandler extends RemoteCacheEventHandler<DeviceId, DefaultDevice> {
tomca55e642014-09-24 18:28:38 -0700365 public RemoteDeviceEventHandler(LoadingCache<DeviceId, Optional<DefaultDevice>> cache) {
366 super(cache);
367 }
368
369 @Override
370 protected void onAdd(DeviceId deviceId, DefaultDevice device) {
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700371 notifyDelegate(new DeviceEvent(DEVICE_ADDED, device));
tomca55e642014-09-24 18:28:38 -0700372 }
373
374 @Override
375 protected void onRemove(DeviceId deviceId, DefaultDevice device) {
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700376 notifyDelegate(new DeviceEvent(DEVICE_REMOVED, device));
tomca55e642014-09-24 18:28:38 -0700377 }
378
379 @Override
Yuta HIGUCHIa8a53eb2014-09-25 17:47:55 -0700380 protected void onUpdate(DeviceId deviceId, DefaultDevice oldDevice, DefaultDevice device) {
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700381 notifyDelegate(new DeviceEvent(DEVICE_UPDATED, device));
tomca55e642014-09-24 18:28:38 -0700382 }
383 }
384
Yuta HIGUCHIfec9e192014-09-28 14:58:02 -0700385 private class RemotePortEventHandler extends RemoteCacheEventHandler<DeviceId, Map<PortNumber, Port>> {
tomca55e642014-09-24 18:28:38 -0700386 public RemotePortEventHandler(LoadingCache<DeviceId, Optional<Map<PortNumber, Port>>> cache) {
387 super(cache);
388 }
389
390 @Override
391 protected void onAdd(DeviceId deviceId, Map<PortNumber, Port> ports) {
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700392// notifyDelegate(new DeviceEvent(PORT_ADDED, getDevice(deviceId)));
tomca55e642014-09-24 18:28:38 -0700393 }
394
395 @Override
396 protected void onRemove(DeviceId deviceId, Map<PortNumber, Port> ports) {
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700397// notifyDelegate(new DeviceEvent(PORT_REMOVED, getDevice(deviceId)));
tomca55e642014-09-24 18:28:38 -0700398 }
399
400 @Override
Yuta HIGUCHIa8a53eb2014-09-25 17:47:55 -0700401 protected void onUpdate(DeviceId deviceId, Map<PortNumber, Port> oldPorts, Map<PortNumber, Port> ports) {
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700402// notifyDelegate(new DeviceEvent(PORT_UPDATED, getDevice(deviceId)));
tomca55e642014-09-24 18:28:38 -0700403 }
404 }
405
406
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700407 // TODO cache serialized DeviceID if we suffer from serialization cost
tom8cc5aa72014-09-19 15:14:43 -0700408}