Sho SHIMIZU
Committed by Gerrit Code Review

Reduce the number of accesses to consistent map

Stop accessing the consistent map when the resource is discrete.
Now, access to the consistent map happens only when the resource
is continuous.

Change-Id: Ic1cb1d94d32a2097dfca891e1d2de7fdc5d4c00a
...@@ -202,10 +202,18 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -202,10 +202,18 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
202 TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumerTxMap = 202 TransactionalMap<ContinuousResourceId, ContinuousResourceAllocation> continuousConsumerTxMap =
203 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER); 203 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
204 204
205 - // Extract Discrete instances from resources 205 + // Look up resources by resource IDs
206 List<Resource> resources = ids.stream() 206 List<Resource> resources = ids.stream()
207 .filter(x -> x.parent().isPresent()) 207 .filter(x -> x.parent().isPresent())
208 - .flatMap(x -> Tools.stream(lookup(childTxMap, x))) 208 + .map(x -> {
209 + // avoid access to consistent map in the case of discrete resource
210 + if (x instanceof DiscreteResourceId) {
211 + return Optional.of(Resources.discrete((DiscreteResourceId) x).resource());
212 + } else {
213 + return lookup(childTxMap, x);
214 + }
215 + })
216 + .flatMap(Tools::stream)
209 .collect(Collectors.toList()); 217 .collect(Collectors.toList());
210 // the order is preserved by LinkedHashMap 218 // the order is preserved by LinkedHashMap
211 Map<DiscreteResourceId, List<Resource>> resourceMap = resources.stream() 219 Map<DiscreteResourceId, List<Resource>> resourceMap = resources.stream()
......