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
checkNotNull(resource);
checkArgument(resource instanceof DiscreteResource || resource instanceof ContinuousResource);
if (resource instanceof DiscreteResource) {
// check if already consumed
return getResourceAllocations(resource.id()).isEmpty();
} else {
// check if it's registered or not.
Versioned<Set<Resource>> v = childMap.get(resource.parent().get().id());
if (v == null || !v.value().contains(resource)) {
if (v == null) {
return false;
}
if (resource instanceof DiscreteResource) {
// check if already consumed
return getResourceAllocations(resource.id()).isEmpty();
} else {
ContinuousResource requested = (ContinuousResource) resource;
ContinuousResource registered = v.value().stream()
.filter(c -> c.id().equals(resource.id()))
......