blob: 894ee212eecd915e457a5acfba91cfa815665a0a [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 HIGUCHI672488d2014-10-07 09:23:43 -070091 = new OptionalCacheLoader<>(serializer, 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 HIGUCHI672488d2014-10-07 09:23:43 -0700101 = new OptionalCacheLoader<>(serializer, 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(),
alshabib7911a052014-10-16 17:49:37 -0700172 desc.serialNumber(), desc.chassisId());
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(),
alshabib7911a052014-10-16 17:49:37 -0700196 desc.serialNumber(),
197 desc.chassisId());
tom8cc5aa72014-09-19 15:14:43 -0700198 synchronized (this) {
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700199 final byte[] deviceIdBytes = serialize(device.id());
200 rawDevices.put(deviceIdBytes, serialize(updated));
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700201 devices.put(device.id(), Optional.of(updated));
202 availableDevices.add(serialize(device.id()));
tom8cc5aa72014-09-19 15:14:43 -0700203 }
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700204 return new DeviceEvent(DeviceEvent.Type.DEVICE_UPDATED, updated, null);
tom8cc5aa72014-09-19 15:14:43 -0700205 }
206
207 // Otherwise merely attempt to change availability
208 synchronized (this) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700209 boolean added = availableDevices.add(serialize(device.id()));
tom8cc5aa72014-09-19 15:14:43 -0700210 return !added ? null :
211 new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device, null);
212 }
213 }
214
215 @Override
216 public DeviceEvent markOffline(DeviceId deviceId) {
217 synchronized (this) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700218 Device device = devices.getUnchecked(deviceId).orNull();
219 boolean removed = device != null && availableDevices.remove(serialize(deviceId));
tom8cc5aa72014-09-19 15:14:43 -0700220 return !removed ? null :
221 new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device, null);
222 }
223 }
224
225 @Override
Yuta HIGUCHI5f6739c2014-10-01 14:04:01 -0700226 public List<DeviceEvent> updatePorts(ProviderId providerId, DeviceId deviceId,
tom0872a172014-09-23 11:24:26 -0700227 List<PortDescription> portDescriptions) {
tom8cc5aa72014-09-19 15:14:43 -0700228 List<DeviceEvent> events = new ArrayList<>();
229 synchronized (this) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700230 Device device = devices.getUnchecked(deviceId).orNull();
tom8cc5aa72014-09-19 15:14:43 -0700231 checkArgument(device != null, DEVICE_NOT_FOUND, deviceId);
232 Map<PortNumber, Port> ports = getPortMap(deviceId);
233
234 // Add new ports
235 Set<PortNumber> processed = new HashSet<>();
236 for (PortDescription portDescription : portDescriptions) {
237 Port port = ports.get(portDescription.portNumber());
238 events.add(port == null ?
239 createPort(device, portDescription, ports) :
240 updatePort(device, port, portDescription, ports));
241 processed.add(portDescription.portNumber());
242 }
243
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700244 updatePortMap(deviceId, ports);
245
tom8cc5aa72014-09-19 15:14:43 -0700246 events.addAll(pruneOldPorts(device, ports, processed));
247 }
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700248 return FluentIterable.from(events).filter(notNull()).toList();
tom8cc5aa72014-09-19 15:14:43 -0700249 }
250
251 // Creates a new port based on the port description adds it to the map and
252 // Returns corresponding event.
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700253 //@GuardedBy("this")
tom8cc5aa72014-09-19 15:14:43 -0700254 private DeviceEvent createPort(Device device, PortDescription portDescription,
255 Map<PortNumber, Port> ports) {
256 DefaultPort port = new DefaultPort(device, portDescription.portNumber(),
257 portDescription.isEnabled());
258 ports.put(port.number(), port);
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700259 updatePortMap(device.id(), ports);
tom8cc5aa72014-09-19 15:14:43 -0700260 return new DeviceEvent(PORT_ADDED, device, port);
261 }
262
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700263 // Checks if the specified port requires update and if so, it replaces the
tom8cc5aa72014-09-19 15:14:43 -0700264 // existing entry in the map and returns corresponding event.
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700265 //@GuardedBy("this")
tom8cc5aa72014-09-19 15:14:43 -0700266 private DeviceEvent updatePort(Device device, Port port,
267 PortDescription portDescription,
268 Map<PortNumber, Port> ports) {
269 if (port.isEnabled() != portDescription.isEnabled()) {
270 DefaultPort updatedPort =
271 new DefaultPort(device, portDescription.portNumber(),
272 portDescription.isEnabled());
273 ports.put(port.number(), updatedPort);
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700274 updatePortMap(device.id(), ports);
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700275 return new DeviceEvent(PORT_UPDATED, device, updatedPort);
tom8cc5aa72014-09-19 15:14:43 -0700276 }
277 return null;
278 }
279
280 // Prunes the specified list of ports based on which ports are in the
281 // processed list and returns list of corresponding events.
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700282 //@GuardedBy("this")
tom8cc5aa72014-09-19 15:14:43 -0700283 private List<DeviceEvent> pruneOldPorts(Device device,
284 Map<PortNumber, Port> ports,
285 Set<PortNumber> processed) {
286 List<DeviceEvent> events = new ArrayList<>();
287 Iterator<PortNumber> iterator = ports.keySet().iterator();
288 while (iterator.hasNext()) {
289 PortNumber portNumber = iterator.next();
290 if (!processed.contains(portNumber)) {
291 events.add(new DeviceEvent(PORT_REMOVED, device,
292 ports.get(portNumber)));
293 iterator.remove();
294 }
295 }
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700296 if (!events.isEmpty()) {
297 updatePortMap(device.id(), ports);
298 }
tom8cc5aa72014-09-19 15:14:43 -0700299 return events;
300 }
301
302 // Gets the map of ports for the specified device; if one does not already
303 // exist, it creates and registers a new one.
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700304 // WARN: returned value is a copy, changes made to the Map
305 // needs to be written back using updatePortMap
306 //@GuardedBy("this")
tom8cc5aa72014-09-19 15:14:43 -0700307 private Map<PortNumber, Port> getPortMap(DeviceId deviceId) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700308 Map<PortNumber, Port> ports = devicePorts.getUnchecked(deviceId).orNull();
tom8cc5aa72014-09-19 15:14:43 -0700309 if (ports == null) {
310 ports = new HashMap<>();
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700311 // this probably is waste of time in most cases.
312 updatePortMap(deviceId, ports);
tom8cc5aa72014-09-19 15:14:43 -0700313 }
314 return ports;
315 }
316
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700317 //@GuardedBy("this")
318 private void updatePortMap(DeviceId deviceId, Map<PortNumber, Port> ports) {
319 rawDevicePorts.put(serialize(deviceId), serialize(ports));
320 devicePorts.put(deviceId, Optional.of(ports));
321 }
322
tom8cc5aa72014-09-19 15:14:43 -0700323 @Override
Yuta HIGUCHI5f6739c2014-10-01 14:04:01 -0700324 public DeviceEvent updatePortStatus(ProviderId providerId, DeviceId deviceId,
tom0872a172014-09-23 11:24:26 -0700325 PortDescription portDescription) {
tom8cc5aa72014-09-19 15:14:43 -0700326 synchronized (this) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700327 Device device = devices.getUnchecked(deviceId).orNull();
tom8cc5aa72014-09-19 15:14:43 -0700328 checkArgument(device != null, DEVICE_NOT_FOUND, deviceId);
329 Map<PortNumber, Port> ports = getPortMap(deviceId);
330 Port port = ports.get(portDescription.portNumber());
331 return updatePort(device, port, portDescription, ports);
332 }
333 }
334
335 @Override
336 public List<Port> getPorts(DeviceId deviceId) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700337 Map<PortNumber, Port> ports = devicePorts.getUnchecked(deviceId).orNull();
338 return ports == null ? Collections.<Port>emptyList() : ImmutableList.copyOf(ports.values());
tom8cc5aa72014-09-19 15:14:43 -0700339 }
340
341 @Override
342 public Port getPort(DeviceId deviceId, PortNumber portNumber) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700343 Map<PortNumber, Port> ports = devicePorts.getUnchecked(deviceId).orNull();
tom8cc5aa72014-09-19 15:14:43 -0700344 return ports == null ? null : ports.get(portNumber);
345 }
346
347 @Override
348 public boolean isAvailable(DeviceId deviceId) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700349 return availableDevices.contains(serialize(deviceId));
tom8cc5aa72014-09-19 15:14:43 -0700350 }
351
352 @Override
tom8cc5aa72014-09-19 15:14:43 -0700353 public DeviceEvent removeDevice(DeviceId deviceId) {
354 synchronized (this) {
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700355 byte[] deviceIdBytes = serialize(deviceId);
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700356
357 // TODO conditional remove?
358 Device device = deserialize(rawDevices.remove(deviceIdBytes));
359 devices.invalidate(deviceId);
tom8cc5aa72014-09-19 15:14:43 -0700360 return device == null ? null :
361 new DeviceEvent(DEVICE_REMOVED, device, null);
362 }
363 }
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700364
Yuta HIGUCHIfec9e192014-09-28 14:58:02 -0700365 private class RemoteDeviceEventHandler extends RemoteCacheEventHandler<DeviceId, DefaultDevice> {
tomca55e642014-09-24 18:28:38 -0700366 public RemoteDeviceEventHandler(LoadingCache<DeviceId, Optional<DefaultDevice>> cache) {
367 super(cache);
368 }
369
370 @Override
371 protected void onAdd(DeviceId deviceId, DefaultDevice device) {
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700372 notifyDelegate(new DeviceEvent(DEVICE_ADDED, device));
tomca55e642014-09-24 18:28:38 -0700373 }
374
375 @Override
376 protected void onRemove(DeviceId deviceId, DefaultDevice device) {
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700377 notifyDelegate(new DeviceEvent(DEVICE_REMOVED, device));
tomca55e642014-09-24 18:28:38 -0700378 }
379
380 @Override
Yuta HIGUCHIa8a53eb2014-09-25 17:47:55 -0700381 protected void onUpdate(DeviceId deviceId, DefaultDevice oldDevice, DefaultDevice device) {
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700382 notifyDelegate(new DeviceEvent(DEVICE_UPDATED, device));
tomca55e642014-09-24 18:28:38 -0700383 }
384 }
385
Yuta HIGUCHIfec9e192014-09-28 14:58:02 -0700386 private class RemotePortEventHandler extends RemoteCacheEventHandler<DeviceId, Map<PortNumber, Port>> {
tomca55e642014-09-24 18:28:38 -0700387 public RemotePortEventHandler(LoadingCache<DeviceId, Optional<Map<PortNumber, Port>>> cache) {
388 super(cache);
389 }
390
391 @Override
392 protected void onAdd(DeviceId deviceId, Map<PortNumber, Port> ports) {
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700393// notifyDelegate(new DeviceEvent(PORT_ADDED, getDevice(deviceId)));
tomca55e642014-09-24 18:28:38 -0700394 }
395
396 @Override
397 protected void onRemove(DeviceId deviceId, Map<PortNumber, Port> ports) {
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700398// notifyDelegate(new DeviceEvent(PORT_REMOVED, getDevice(deviceId)));
tomca55e642014-09-24 18:28:38 -0700399 }
400
401 @Override
Yuta HIGUCHIa8a53eb2014-09-25 17:47:55 -0700402 protected void onUpdate(DeviceId deviceId, Map<PortNumber, Port> oldPorts, Map<PortNumber, Port> ports) {
Yuta HIGUCHIf5479702014-09-25 00:09:24 -0700403// notifyDelegate(new DeviceEvent(PORT_UPDATED, getDevice(deviceId)));
tomca55e642014-09-24 18:28:38 -0700404 }
405 }
406
407
Yuta HIGUCHIb3b2ac42014-09-21 23:37:11 -0700408 // TODO cache serialized DeviceID if we suffer from serialization cost
tom8cc5aa72014-09-19 15:14:43 -0700409}