Sho SHIMIZU
Committed by Gerrit Code Review

Refactor: extract the same procedures

Change-Id: If28960f4e9fddc3276091fd04e2b624e6168dc5c
...@@ -268,21 +268,18 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour ...@@ -268,21 +268,18 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour
268 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER); 268 tx.getTransactionalMap(CONTINUOUS_CONSUMER_MAP, SERIALIZER);
269 269
270 for (Resource resource: resources) { 270 for (Resource resource: resources) {
271 - if (resource instanceof DiscreteResource) { 271 + // if the resource is not registered, then abort
272 - if (!lookup(childTxMap, resource.id()).isPresent()) { 272 + Optional<Resource> lookedUp = lookup(childTxMap, resource.id());
273 - return abortTransaction(tx); 273 + if (!lookedUp.isPresent()) {
274 - } 274 + return abortTransaction(tx);
275 + }
275 276
277 + if (resource instanceof DiscreteResource) {
276 ResourceConsumer oldValue = discreteConsumerTxMap.put(((DiscreteResource) resource).id(), consumer); 278 ResourceConsumer oldValue = discreteConsumerTxMap.put(((DiscreteResource) resource).id(), consumer);
277 if (oldValue != null) { 279 if (oldValue != null) {
278 return abortTransaction(tx); 280 return abortTransaction(tx);
279 } 281 }
280 } else if (resource instanceof ContinuousResource) { 282 } else if (resource instanceof ContinuousResource) {
281 - Optional<Resource> lookedUp = lookup(childTxMap, resource.id());
282 - if (!lookedUp.isPresent()) {
283 - return abortTransaction(tx);
284 - }
285 -
286 // Down cast: this must be safe as ContinuousResource is associated with ContinuousResourceId 283 // Down cast: this must be safe as ContinuousResource is associated with ContinuousResourceId
287 ContinuousResource continuous = (ContinuousResource) lookedUp.get(); 284 ContinuousResource continuous = (ContinuousResource) lookedUp.get();
288 ContinuousResourceAllocation allocations = continuousConsumerTxMap.get(continuous.id()); 285 ContinuousResourceAllocation allocations = continuousConsumerTxMap.get(continuous.id());
......