Sho SHIMIZU
Committed by Gerrit Code Review

Improve the performance of ResourceManager#getAvailableResources()

By removing an extra map access in ConsistentResourceStore#isAvailable()

This patch mitigates the issue of ONOS-3869

Change-Id: Ief231f5532c34719c150855afe0ea69fc6b478f1
...@@ -349,16 +349,16 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -349,16 +349,16 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
349 checkNotNull(resource); 349 checkNotNull(resource);
350 checkArgument(resource instanceof DiscreteResource || resource instanceof ContinuousResource); 350 checkArgument(resource instanceof DiscreteResource || resource instanceof ContinuousResource);
351 351
352 - // check if it's registered or not.
353 - Versioned<Set<Resource>> v = childMap.get(resource.parent().get().id());
354 - if (v == null || !v.value().contains(resource)) {
355 - return false;
356 - }
357 -
358 if (resource instanceof DiscreteResource) { 352 if (resource instanceof DiscreteResource) {
359 // check if already consumed 353 // check if already consumed
360 return getResourceAllocations(resource.id()).isEmpty(); 354 return getResourceAllocations(resource.id()).isEmpty();
361 } else { 355 } else {
356 + // check if it's registered or not.
357 + Versioned<Set<Resource>> v = childMap.get(resource.parent().get().id());
358 + if (v == null) {
359 + return false;
360 + }
361 +
362 ContinuousResource requested = (ContinuousResource) resource; 362 ContinuousResource requested = (ContinuousResource) resource;
363 ContinuousResource registered = v.value().stream() 363 ContinuousResource registered = v.value().stream()
364 .filter(c -> c.id().equals(resource.id())) 364 .filter(c -> c.id().equals(resource.id()))
......