Yuta HIGUCHI

GDevStore: remove extra Map lookup

Change-Id: Ib7a234d0b0a69a7fbc7e8a75199ad58d52b7c411
...@@ -230,9 +230,10 @@ public class GossipDeviceStore ...@@ -230,9 +230,10 @@ public class GossipDeviceStore
230 final Timestamped<DeviceDescription> deltaDesc = new Timestamped<>(deviceDescription, newTimestamp); 230 final Timestamped<DeviceDescription> deltaDesc = new Timestamped<>(deviceDescription, newTimestamp);
231 final DeviceEvent event; 231 final DeviceEvent event;
232 final Timestamped<DeviceDescription> mergedDesc; 232 final Timestamped<DeviceDescription> mergedDesc;
233 - synchronized (getOrCreateDeviceDescriptionsMap(deviceId)) { 233 + final Map<ProviderId, DeviceDescriptions> device = getOrCreateDeviceDescriptionsMap(deviceId);
234 + synchronized (device) {
234 event = createOrUpdateDeviceInternal(providerId, deviceId, deltaDesc); 235 event = createOrUpdateDeviceInternal(providerId, deviceId, deltaDesc);
235 - mergedDesc = getOrCreateDeviceDescriptionsMap(deviceId).get(providerId).getDeviceDesc(); 236 + mergedDesc = device.get(providerId).getDeviceDesc();
236 } 237 }
237 if (event != null) { 238 if (event != null) {
238 log.info("Notifying peers of a device update topology event for providerId: {} and deviceId: {}", 239 log.info("Notifying peers of a device update topology event for providerId: {} and deviceId: {}",
...@@ -252,10 +253,10 @@ public class GossipDeviceStore ...@@ -252,10 +253,10 @@ public class GossipDeviceStore
252 Timestamped<DeviceDescription> deltaDesc) { 253 Timestamped<DeviceDescription> deltaDesc) {
253 254
254 // Collection of DeviceDescriptions for a Device 255 // Collection of DeviceDescriptions for a Device
255 - Map<ProviderId, DeviceDescriptions> providerDescs 256 + Map<ProviderId, DeviceDescriptions> device
256 = getOrCreateDeviceDescriptionsMap(deviceId); 257 = getOrCreateDeviceDescriptionsMap(deviceId);
257 258
258 - synchronized (providerDescs) { 259 + synchronized (device) {
259 // locking per device 260 // locking per device
260 261
261 if (isDeviceRemoved(deviceId, deltaDesc.timestamp())) { 262 if (isDeviceRemoved(deviceId, deltaDesc.timestamp())) {
...@@ -263,7 +264,7 @@ public class GossipDeviceStore ...@@ -263,7 +264,7 @@ public class GossipDeviceStore
263 return null; 264 return null;
264 } 265 }
265 266
266 - DeviceDescriptions descs = getOrCreateProviderDeviceDescriptions(providerDescs, providerId, deltaDesc); 267 + DeviceDescriptions descs = getOrCreateProviderDeviceDescriptions(device, providerId, deltaDesc);
267 268
268 final Device oldDevice = devices.get(deviceId); 269 final Device oldDevice = devices.get(deviceId);
269 final Device newDevice; 270 final Device newDevice;
...@@ -272,7 +273,7 @@ public class GossipDeviceStore ...@@ -272,7 +273,7 @@ public class GossipDeviceStore
272 deltaDesc.isNewer(descs.getDeviceDesc())) { 273 deltaDesc.isNewer(descs.getDeviceDesc())) {
273 // on new device or valid update 274 // on new device or valid update
274 descs.putDeviceDesc(deltaDesc); 275 descs.putDeviceDesc(deltaDesc);
275 - newDevice = composeDevice(deviceId, providerDescs); 276 + newDevice = composeDevice(deviceId, device);
276 } else { 277 } else {
277 // outdated event, ignored. 278 // outdated event, ignored.
278 return null; 279 return null;
...@@ -444,9 +445,10 @@ public class GossipDeviceStore ...@@ -444,9 +445,10 @@ public class GossipDeviceStore
444 final List<DeviceEvent> events; 445 final List<DeviceEvent> events;
445 final Timestamped<List<PortDescription>> merged; 446 final Timestamped<List<PortDescription>> merged;
446 447
447 - synchronized (getOrCreateDeviceDescriptionsMap(deviceId)) { 448 + final Map<ProviderId, DeviceDescriptions> device = getOrCreateDeviceDescriptionsMap(deviceId);
449 + synchronized (device) {
448 events = updatePortsInternal(providerId, deviceId, timestampedInput); 450 events = updatePortsInternal(providerId, deviceId, timestampedInput);
449 - final DeviceDescriptions descs = getOrCreateDeviceDescriptionsMap(deviceId).get(providerId); 451 + final DeviceDescriptions descs = device.get(providerId);
450 List<PortDescription> mergedList = 452 List<PortDescription> mergedList =
451 FluentIterable.from(portDescriptions) 453 FluentIterable.from(portDescriptions)
452 .transform(new Function<PortDescription, PortDescription>() { 454 .transform(new Function<PortDescription, PortDescription>() {
...@@ -632,9 +634,10 @@ public class GossipDeviceStore ...@@ -632,9 +634,10 @@ public class GossipDeviceStore
632 = new Timestamped<>(portDescription, newTimestamp); 634 = new Timestamped<>(portDescription, newTimestamp);
633 final DeviceEvent event; 635 final DeviceEvent event;
634 final Timestamped<PortDescription> mergedDesc; 636 final Timestamped<PortDescription> mergedDesc;
635 - synchronized (getOrCreateDeviceDescriptionsMap(deviceId)) { 637 + final Map<ProviderId, DeviceDescriptions> device = getOrCreateDeviceDescriptionsMap(deviceId);
638 + synchronized (device) {
636 event = updatePortStatusInternal(providerId, deviceId, deltaDesc); 639 event = updatePortStatusInternal(providerId, deviceId, deltaDesc);
637 - mergedDesc = getOrCreateDeviceDescriptionsMap(deviceId).get(providerId) 640 + mergedDesc = device.get(providerId)
638 .getPortDesc(portDescription.portNumber()); 641 .getPortDesc(portDescription.portNumber());
639 } 642 }
640 if (event != null) { 643 if (event != null) {
......