Yuta HIGUCHI

DeviceStore bugfixes

Change-Id: Iebbfd99ea578c36438ec11e28e5230c73886dd55
1 package org.onlab.onos.store.device.impl; 1 package org.onlab.onos.store.device.impl;
2 2
3 +import static com.google.common.base.Predicates.notNull;
3 import com.google.common.base.Optional; 4 import com.google.common.base.Optional;
4 import com.google.common.cache.LoadingCache; 5 import com.google.common.cache.LoadingCache;
6 +import com.google.common.collect.FluentIterable;
5 import com.google.common.collect.ImmutableList; 7 import com.google.common.collect.ImmutableList;
6 import com.google.common.collect.ImmutableSet; 8 import com.google.common.collect.ImmutableSet;
7 import com.google.common.collect.ImmutableSet.Builder; 9 import com.google.common.collect.ImmutableSet.Builder;
8 import com.hazelcast.core.IMap; 10 import com.hazelcast.core.IMap;
9 import com.hazelcast.core.ISet; 11 import com.hazelcast.core.ISet;
12 +
10 import org.apache.felix.scr.annotations.Activate; 13 import org.apache.felix.scr.annotations.Activate;
11 import org.apache.felix.scr.annotations.Component; 14 import org.apache.felix.scr.annotations.Component;
12 import org.apache.felix.scr.annotations.Deactivate; 15 import org.apache.felix.scr.annotations.Deactivate;
...@@ -184,10 +187,12 @@ public class DistributedDeviceStore ...@@ -184,10 +187,12 @@ public class DistributedDeviceStore
184 desc.swVersion(), 187 desc.swVersion(),
185 desc.serialNumber()); 188 desc.serialNumber());
186 synchronized (this) { 189 synchronized (this) {
190 + final byte[] deviceIdBytes = serialize(device.id());
191 + rawDevices.put(deviceIdBytes, serialize(updated));
187 devices.put(device.id(), Optional.of(updated)); 192 devices.put(device.id(), Optional.of(updated));
188 availableDevices.add(serialize(device.id())); 193 availableDevices.add(serialize(device.id()));
189 } 194 }
190 - return new DeviceEvent(DeviceEvent.Type.DEVICE_UPDATED, device, null); 195 + return new DeviceEvent(DeviceEvent.Type.DEVICE_UPDATED, updated, null);
191 } 196 }
192 197
193 // Otherwise merely attempt to change availability 198 // Otherwise merely attempt to change availability
...@@ -231,7 +236,7 @@ public class DistributedDeviceStore ...@@ -231,7 +236,7 @@ public class DistributedDeviceStore
231 236
232 events.addAll(pruneOldPorts(device, ports, processed)); 237 events.addAll(pruneOldPorts(device, ports, processed));
233 } 238 }
234 - return events; 239 + return FluentIterable.from(events).filter(notNull()).toList();
235 } 240 }
236 241
237 // Creates a new port based on the port description adds it to the map and 242 // Creates a new port based on the port description adds it to the map and
...@@ -258,7 +263,7 @@ public class DistributedDeviceStore ...@@ -258,7 +263,7 @@ public class DistributedDeviceStore
258 portDescription.isEnabled()); 263 portDescription.isEnabled());
259 ports.put(port.number(), updatedPort); 264 ports.put(port.number(), updatedPort);
260 updatePortMap(device.id(), ports); 265 updatePortMap(device.id(), ports);
261 - return new DeviceEvent(PORT_UPDATED, device, port); 266 + return new DeviceEvent(PORT_UPDATED, device, updatedPort);
262 } 267 }
263 return null; 268 return null;
264 } 269 }
...@@ -355,17 +360,17 @@ public class DistributedDeviceStore ...@@ -355,17 +360,17 @@ public class DistributedDeviceStore
355 360
356 @Override 361 @Override
357 protected void onAdd(DeviceId deviceId, DefaultDevice device) { 362 protected void onAdd(DeviceId deviceId, DefaultDevice device) {
358 - delegate.notify(new DeviceEvent(DEVICE_ADDED, device)); 363 + notifyDelegate(new DeviceEvent(DEVICE_ADDED, device));
359 } 364 }
360 365
361 @Override 366 @Override
362 protected void onRemove(DeviceId deviceId, DefaultDevice device) { 367 protected void onRemove(DeviceId deviceId, DefaultDevice device) {
363 - delegate.notify(new DeviceEvent(DEVICE_REMOVED, device)); 368 + notifyDelegate(new DeviceEvent(DEVICE_REMOVED, device));
364 } 369 }
365 370
366 @Override 371 @Override
367 protected void onUpdate(DeviceId deviceId, DefaultDevice device) { 372 protected void onUpdate(DeviceId deviceId, DefaultDevice device) {
368 - delegate.notify(new DeviceEvent(DEVICE_UPDATED, device)); 373 + notifyDelegate(new DeviceEvent(DEVICE_UPDATED, device));
369 } 374 }
370 } 375 }
371 376
...@@ -376,17 +381,17 @@ public class DistributedDeviceStore ...@@ -376,17 +381,17 @@ public class DistributedDeviceStore
376 381
377 @Override 382 @Override
378 protected void onAdd(DeviceId deviceId, Map<PortNumber, Port> ports) { 383 protected void onAdd(DeviceId deviceId, Map<PortNumber, Port> ports) {
379 -// delegate.notify(new DeviceEvent(PORT_ADDED, getDevice(deviceId))); 384 +// notifyDelegate(new DeviceEvent(PORT_ADDED, getDevice(deviceId)));
380 } 385 }
381 386
382 @Override 387 @Override
383 protected void onRemove(DeviceId deviceId, Map<PortNumber, Port> ports) { 388 protected void onRemove(DeviceId deviceId, Map<PortNumber, Port> ports) {
384 -// delegate.notify(new DeviceEvent(PORT_REMOVED, getDevice(deviceId))); 389 +// notifyDelegate(new DeviceEvent(PORT_REMOVED, getDevice(deviceId)));
385 } 390 }
386 391
387 @Override 392 @Override
388 protected void onUpdate(DeviceId deviceId, Map<PortNumber, Port> ports) { 393 protected void onUpdate(DeviceId deviceId, Map<PortNumber, Port> ports) {
389 -// delegate.notify(new DeviceEvent(PORT_UPDATED, getDevice(deviceId))); 394 +// notifyDelegate(new DeviceEvent(PORT_UPDATED, getDevice(deviceId)));
390 } 395 }
391 } 396 }
392 397
......
...@@ -107,7 +107,7 @@ public abstract class AbstractDistributedStore<E extends Event, D extends StoreD ...@@ -107,7 +107,7 @@ public abstract class AbstractDistributedStore<E extends Event, D extends StoreD
107 @Override 107 @Override
108 public void entryRemoved(EntryEvent<byte[], byte[]> event) { 108 public void entryRemoved(EntryEvent<byte[], byte[]> event) {
109 K key = deserialize(event.getKey()); 109 K key = deserialize(event.getKey());
110 - V val = deserialize(event.getValue()); 110 + V val = deserialize(event.getOldValue());
111 cache.invalidate(key); 111 cache.invalidate(key);
112 onRemove(key, val); 112 onRemove(key, val);
113 } 113 }
......
1 package org.onlab.onos.net.trivial.impl; 1 package org.onlab.onos.net.trivial.impl;
2 2
3 +import com.google.common.collect.FluentIterable;
3 import com.google.common.collect.ImmutableList; 4 import com.google.common.collect.ImmutableList;
5 +
4 import org.apache.felix.scr.annotations.Activate; 6 import org.apache.felix.scr.annotations.Activate;
5 import org.apache.felix.scr.annotations.Component; 7 import org.apache.felix.scr.annotations.Component;
6 import org.apache.felix.scr.annotations.Deactivate; 8 import org.apache.felix.scr.annotations.Deactivate;
...@@ -33,6 +35,7 @@ import java.util.Set; ...@@ -33,6 +35,7 @@ import java.util.Set;
33 import java.util.concurrent.ConcurrentHashMap; 35 import java.util.concurrent.ConcurrentHashMap;
34 36
35 import static com.google.common.base.Preconditions.checkArgument; 37 import static com.google.common.base.Preconditions.checkArgument;
38 +import static com.google.common.base.Predicates.notNull;
36 import static org.onlab.onos.net.device.DeviceEvent.Type.*; 39 import static org.onlab.onos.net.device.DeviceEvent.Type.*;
37 import static org.slf4j.LoggerFactory.getLogger; 40 import static org.slf4j.LoggerFactory.getLogger;
38 41
...@@ -123,7 +126,7 @@ public class SimpleDeviceStore ...@@ -123,7 +126,7 @@ public class SimpleDeviceStore
123 devices.put(device.id(), updated); 126 devices.put(device.id(), updated);
124 availableDevices.add(device.id()); 127 availableDevices.add(device.id());
125 } 128 }
126 - return new DeviceEvent(DeviceEvent.Type.DEVICE_UPDATED, device, null); 129 + return new DeviceEvent(DeviceEvent.Type.DEVICE_UPDATED, updated, null);
127 } 130 }
128 131
129 // Otherwise merely attempt to change availability 132 // Otherwise merely attempt to change availability
...@@ -165,7 +168,7 @@ public class SimpleDeviceStore ...@@ -165,7 +168,7 @@ public class SimpleDeviceStore
165 168
166 events.addAll(pruneOldPorts(device, ports, processed)); 169 events.addAll(pruneOldPorts(device, ports, processed));
167 } 170 }
168 - return events; 171 + return FluentIterable.from(events).filter(notNull()).toList();
169 } 172 }
170 173
171 // Creates a new port based on the port description adds it to the map and 174 // Creates a new port based on the port description adds it to the map and
......