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
Showing
1 changed file
with
5 additions
and
5 deletions
... | @@ -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 | + if (resource instanceof DiscreteResource) { | ||
353 | + // check if already consumed | ||
354 | + return getResourceAllocations(resource.id()).isEmpty(); | ||
355 | + } else { | ||
352 | // check if it's registered or not. | 356 | // check if it's registered or not. |
353 | Versioned<Set<Resource>> v = childMap.get(resource.parent().get().id()); | 357 | Versioned<Set<Resource>> v = childMap.get(resource.parent().get().id()); |
354 | - if (v == null || !v.value().contains(resource)) { | 358 | + if (v == null) { |
355 | return false; | 359 | return false; |
356 | } | 360 | } |
357 | 361 | ||
358 | - if (resource instanceof DiscreteResource) { | ||
359 | - // check if already consumed | ||
360 | - return getResourceAllocations(resource.id()).isEmpty(); | ||
361 | - } else { | ||
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())) | ... | ... |
-
Please register or login to post a comment