Rename arguments to be more descriptive
Change-Id: If5c51aa2d713414839650e689ed8c4050a53c3a2
Showing
3 changed files
with
45 additions
and
45 deletions
... | @@ -22,8 +22,8 @@ import org.apache.felix.scr.annotations.Component; | ... | @@ -22,8 +22,8 @@ import org.apache.felix.scr.annotations.Component; |
22 | import org.apache.felix.scr.annotations.Reference; | 22 | import org.apache.felix.scr.annotations.Reference; |
23 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
24 | import org.apache.felix.scr.annotations.Service; | 24 | import org.apache.felix.scr.annotations.Service; |
25 | -import org.onlab.util.Tools; | ||
26 | import org.onlab.util.KryoNamespace; | 25 | import org.onlab.util.KryoNamespace; |
26 | +import org.onlab.util.Tools; | ||
27 | import org.onosproject.net.resource.ContinuousResource; | 27 | import org.onosproject.net.resource.ContinuousResource; |
28 | import org.onosproject.net.resource.ContinuousResourceId; | 28 | import org.onosproject.net.resource.ContinuousResourceId; |
29 | import org.onosproject.net.resource.DiscreteResource; | 29 | import org.onosproject.net.resource.DiscreteResource; |
... | @@ -334,28 +334,28 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour | ... | @@ -334,28 +334,28 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour |
334 | * Appends the values to the existing values associated with the specified key. | 334 | * Appends the values to the existing values associated with the specified key. |
335 | * If the map already has all the given values, appending will not happen. | 335 | * If the map already has all the given values, appending will not happen. |
336 | * | 336 | * |
337 | - * @param key key specifying values | 337 | + * @param parent resource ID of the parent under which the given resources are registered |
338 | - * @param values values to be appended | 338 | + * @param resources resources to be registered |
339 | * @return true if the operation succeeds, false otherwise. | 339 | * @return true if the operation succeeds, false otherwise. |
340 | */ | 340 | */ |
341 | // computational complexity: O(n) where n is the number of the specified value | 341 | // computational complexity: O(n) where n is the number of the specified value |
342 | private boolean register(TransactionalDiscreteResourceSubStore discreteTxStore, | 342 | private boolean register(TransactionalDiscreteResourceSubStore discreteTxStore, |
343 | TransactionalContinuousResourceSubStore continuousTxStore, | 343 | TransactionalContinuousResourceSubStore continuousTxStore, |
344 | - DiscreteResourceId key, List<Resource> values) { | 344 | + DiscreteResourceId parent, List<Resource> resources) { |
345 | // it's assumed that the passed "values" is non-empty | 345 | // it's assumed that the passed "values" is non-empty |
346 | 346 | ||
347 | // This is 2-pass scan. Nicer to have 1-pass scan | 347 | // This is 2-pass scan. Nicer to have 1-pass scan |
348 | - Set<DiscreteResource> discreteValues = values.stream() | 348 | + Set<DiscreteResource> discreteResources = resources.stream() |
349 | .filter(x -> x instanceof DiscreteResource) | 349 | .filter(x -> x instanceof DiscreteResource) |
350 | .map(x -> (DiscreteResource) x) | 350 | .map(x -> (DiscreteResource) x) |
351 | .collect(Collectors.toCollection(LinkedHashSet::new)); | 351 | .collect(Collectors.toCollection(LinkedHashSet::new)); |
352 | - Set<ContinuousResource> continuousValues = values.stream() | 352 | + Set<ContinuousResource> continuousResources = resources.stream() |
353 | .filter(x -> x instanceof ContinuousResource) | 353 | .filter(x -> x instanceof ContinuousResource) |
354 | .map(x -> (ContinuousResource) x) | 354 | .map(x -> (ContinuousResource) x) |
355 | .collect(Collectors.toCollection(LinkedHashSet::new)); | 355 | .collect(Collectors.toCollection(LinkedHashSet::new)); |
356 | 356 | ||
357 | - return discreteTxStore.register(key, discreteValues) | 357 | + return discreteTxStore.register(parent, discreteResources) |
358 | - && continuousTxStore.register(key, continuousValues); | 358 | + && continuousTxStore.register(parent, continuousResources); |
359 | } | 359 | } |
360 | 360 | ||
361 | /** | 361 | /** |
... | @@ -364,26 +364,26 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour | ... | @@ -364,26 +364,26 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour |
364 | * | 364 | * |
365 | * @param discreteTxStore map holding multiple discrete resources for a key | 365 | * @param discreteTxStore map holding multiple discrete resources for a key |
366 | * @param continuousTxStore map holding multiple continuous resources for a key | 366 | * @param continuousTxStore map holding multiple continuous resources for a key |
367 | - * @param key key specifying values | 367 | + * @param parent resource ID of the parent under which the given resources are unregistered |
368 | - * @param values values to be removed | 368 | + * @param resources resources to be unregistered |
369 | * @return true if the operation succeeds, false otherwise | 369 | * @return true if the operation succeeds, false otherwise |
370 | */ | 370 | */ |
371 | private boolean unregister(TransactionalDiscreteResourceSubStore discreteTxStore, | 371 | private boolean unregister(TransactionalDiscreteResourceSubStore discreteTxStore, |
372 | TransactionalContinuousResourceSubStore continuousTxStore, | 372 | TransactionalContinuousResourceSubStore continuousTxStore, |
373 | - DiscreteResourceId key, List<Resource> values) { | 373 | + DiscreteResourceId parent, List<Resource> resources) { |
374 | // it's assumed that the passed "values" is non-empty | 374 | // it's assumed that the passed "values" is non-empty |
375 | 375 | ||
376 | // This is 2-pass scan. Nicer to have 1-pass scan | 376 | // This is 2-pass scan. Nicer to have 1-pass scan |
377 | - Set<DiscreteResource> discreteValues = values.stream() | 377 | + Set<DiscreteResource> discreteResources = resources.stream() |
378 | .filter(x -> x instanceof DiscreteResource) | 378 | .filter(x -> x instanceof DiscreteResource) |
379 | .map(x -> (DiscreteResource) x) | 379 | .map(x -> (DiscreteResource) x) |
380 | .collect(Collectors.toCollection(LinkedHashSet::new)); | 380 | .collect(Collectors.toCollection(LinkedHashSet::new)); |
381 | - Set<ContinuousResource> continuousValues = values.stream() | 381 | + Set<ContinuousResource> continuousResources = resources.stream() |
382 | .filter(x -> x instanceof ContinuousResource) | 382 | .filter(x -> x instanceof ContinuousResource) |
383 | .map(x -> (ContinuousResource) x) | 383 | .map(x -> (ContinuousResource) x) |
384 | .collect(Collectors.toCollection(LinkedHashSet::new)); | 384 | .collect(Collectors.toCollection(LinkedHashSet::new)); |
385 | 385 | ||
386 | - return discreteTxStore.unregister(key, discreteValues) | 386 | + return discreteTxStore.unregister(parent, discreteResources) |
387 | - && continuousTxStore.unregister(key, continuousValues); | 387 | + && continuousTxStore.unregister(parent, continuousResources); |
388 | } | 388 | } |
389 | } | 389 | } | ... | ... |
... | @@ -60,18 +60,18 @@ class TransactionalContinuousResourceSubStore { | ... | @@ -60,18 +60,18 @@ class TransactionalContinuousResourceSubStore { |
60 | .findFirst(); | 60 | .findFirst(); |
61 | } | 61 | } |
62 | 62 | ||
63 | - boolean register(DiscreteResourceId key, Set<ContinuousResource> requested) { | 63 | + boolean register(DiscreteResourceId parent, Set<ContinuousResource> resources) { |
64 | // short-circuit: receiving empty resource is regarded as success | 64 | // short-circuit: receiving empty resource is regarded as success |
65 | - if (requested.isEmpty()) { | 65 | + if (resources.isEmpty()) { |
66 | return true; | 66 | return true; |
67 | } | 67 | } |
68 | 68 | ||
69 | - Set<ContinuousResource> oldValues = childMap.putIfAbsent(key, requested); | 69 | + Set<ContinuousResource> oldValues = childMap.putIfAbsent(parent, resources); |
70 | if (oldValues == null) { | 70 | if (oldValues == null) { |
71 | return true; | 71 | return true; |
72 | } | 72 | } |
73 | 73 | ||
74 | - Set<ContinuousResource> addedValues = Sets.difference(requested, oldValues); | 74 | + Set<ContinuousResource> addedValues = Sets.difference(resources, oldValues); |
75 | // no new value, then no-op | 75 | // no new value, then no-op |
76 | if (addedValues.isEmpty()) { | 76 | if (addedValues.isEmpty()) { |
77 | // don't write to map because all values are already stored | 77 | // don't write to map because all values are already stored |
... | @@ -89,38 +89,38 @@ class TransactionalContinuousResourceSubStore { | ... | @@ -89,38 +89,38 @@ class TransactionalContinuousResourceSubStore { |
89 | } | 89 | } |
90 | Set<ContinuousResource> newValues = new LinkedHashSet<>(oldValues); | 90 | Set<ContinuousResource> newValues = new LinkedHashSet<>(oldValues); |
91 | newValues.addAll(addedValues); | 91 | newValues.addAll(addedValues); |
92 | - return childMap.replace(key, oldValues, newValues); | 92 | + return childMap.replace(parent, oldValues, newValues); |
93 | } | 93 | } |
94 | 94 | ||
95 | - boolean unregister(DiscreteResourceId key, Set<ContinuousResource> values) { | 95 | + boolean unregister(DiscreteResourceId parent, Set<ContinuousResource> resources) { |
96 | // short-circuit: receiving empty resource is regarded as success | 96 | // short-circuit: receiving empty resource is regarded as success |
97 | - if (values.isEmpty()) { | 97 | + if (resources.isEmpty()) { |
98 | return true; | 98 | return true; |
99 | } | 99 | } |
100 | 100 | ||
101 | // even if one of the resources is allocated to a consumer, | 101 | // even if one of the resources is allocated to a consumer, |
102 | // all unregistrations are regarded as failure | 102 | // all unregistrations are regarded as failure |
103 | - boolean allocated = values.stream().anyMatch(x -> isAllocated(x.id())); | 103 | + boolean allocated = resources.stream().anyMatch(x -> isAllocated(x.id())); |
104 | if (allocated) { | 104 | if (allocated) { |
105 | - log.warn("Failed to unregister {}: allocation exists", key); | 105 | + log.warn("Failed to unregister {}: allocation exists", parent); |
106 | return false; | 106 | return false; |
107 | } | 107 | } |
108 | 108 | ||
109 | - Set<ContinuousResource> oldValues = childMap.putIfAbsent(key, new LinkedHashSet<>()); | 109 | + Set<ContinuousResource> oldValues = childMap.putIfAbsent(parent, new LinkedHashSet<>()); |
110 | if (oldValues == null) { | 110 | if (oldValues == null) { |
111 | - log.trace("No-Op removing values. key {} did not exist", key); | 111 | + log.trace("No-Op removing values. key {} did not exist", parent); |
112 | return true; | 112 | return true; |
113 | } | 113 | } |
114 | 114 | ||
115 | - if (values.stream().allMatch(x -> !oldValues.contains(x))) { | 115 | + if (resources.stream().allMatch(x -> !oldValues.contains(x))) { |
116 | // don't write map because none of the values are stored | 116 | // don't write map because none of the values are stored |
117 | - log.trace("No-Op removing values. key {} did not contain {}", key, values); | 117 | + log.trace("No-Op removing values. key {} did not contain {}", parent, resources); |
118 | return true; | 118 | return true; |
119 | } | 119 | } |
120 | 120 | ||
121 | LinkedHashSet<ContinuousResource> newValues = new LinkedHashSet<>(oldValues); | 121 | LinkedHashSet<ContinuousResource> newValues = new LinkedHashSet<>(oldValues); |
122 | - newValues.removeAll(values); | 122 | + newValues.removeAll(resources); |
123 | - return childMap.replace(key, oldValues, newValues); | 123 | + return childMap.replace(parent, oldValues, newValues); |
124 | } | 124 | } |
125 | 125 | ||
126 | private boolean isAllocated(ContinuousResourceId id) { | 126 | private boolean isAllocated(ContinuousResourceId id) { | ... | ... |
... | @@ -53,14 +53,14 @@ class TransactionalDiscreteResourceSubStore { | ... | @@ -53,14 +53,14 @@ class TransactionalDiscreteResourceSubStore { |
53 | return values.lookup(id); | 53 | return values.lookup(id); |
54 | } | 54 | } |
55 | 55 | ||
56 | - boolean register(DiscreteResourceId key, Set<DiscreteResource> values) { | 56 | + boolean register(DiscreteResourceId parent, Set<DiscreteResource> resources) { |
57 | // short-circuit: receiving empty resource is regarded as success | 57 | // short-circuit: receiving empty resource is regarded as success |
58 | - if (values.isEmpty()) { | 58 | + if (resources.isEmpty()) { |
59 | return true; | 59 | return true; |
60 | } | 60 | } |
61 | 61 | ||
62 | - DiscreteResources requested = DiscreteResources.of(values); | 62 | + DiscreteResources requested = DiscreteResources.of(resources); |
63 | - DiscreteResources oldValues = childMap.putIfAbsent(key, requested); | 63 | + DiscreteResources oldValues = childMap.putIfAbsent(parent, requested); |
64 | if (oldValues == null) { | 64 | if (oldValues == null) { |
65 | return true; | 65 | return true; |
66 | } | 66 | } |
... | @@ -73,38 +73,38 @@ class TransactionalDiscreteResourceSubStore { | ... | @@ -73,38 +73,38 @@ class TransactionalDiscreteResourceSubStore { |
73 | } | 73 | } |
74 | 74 | ||
75 | DiscreteResources newValues = oldValues.add(addedValues); | 75 | DiscreteResources newValues = oldValues.add(addedValues); |
76 | - return childMap.replace(key, oldValues, newValues); | 76 | + return childMap.replace(parent, oldValues, newValues); |
77 | } | 77 | } |
78 | 78 | ||
79 | - boolean unregister(DiscreteResourceId key, Set<DiscreteResource> values) { | 79 | + boolean unregister(DiscreteResourceId parent, Set<DiscreteResource> resources) { |
80 | // short-circuit: receiving empty resource is regarded as success | 80 | // short-circuit: receiving empty resource is regarded as success |
81 | - if (values.isEmpty()) { | 81 | + if (resources.isEmpty()) { |
82 | return true; | 82 | return true; |
83 | } | 83 | } |
84 | 84 | ||
85 | // even if one of the resources is allocated to a consumer, | 85 | // even if one of the resources is allocated to a consumer, |
86 | // all unregistrations are regarded as failure | 86 | // all unregistrations are regarded as failure |
87 | - boolean allocated = values.stream().anyMatch(x -> isAllocated(x.id())); | 87 | + boolean allocated = resources.stream().anyMatch(x -> isAllocated(x.id())); |
88 | if (allocated) { | 88 | if (allocated) { |
89 | - log.warn("Failed to unregister {}: allocation exists", key); | 89 | + log.warn("Failed to unregister {}: allocation exists", parent); |
90 | return false; | 90 | return false; |
91 | } | 91 | } |
92 | 92 | ||
93 | - DiscreteResources oldValues = childMap.putIfAbsent(key, DiscreteResources.empty()); | 93 | + DiscreteResources oldValues = childMap.putIfAbsent(parent, DiscreteResources.empty()); |
94 | if (oldValues == null) { | 94 | if (oldValues == null) { |
95 | - log.trace("No-Op removing values. key {} did not exist", key); | 95 | + log.trace("No-Op removing values. key {} did not exist", parent); |
96 | return true; | 96 | return true; |
97 | } | 97 | } |
98 | 98 | ||
99 | - if (!oldValues.containsAny(values)) { | 99 | + if (!oldValues.containsAny(resources)) { |
100 | // don't write map because none of the values are stored | 100 | // don't write map because none of the values are stored |
101 | - log.trace("No-Op removing values. key {} did not contain {}", key, values); | 101 | + log.trace("No-Op removing values. key {} did not contain {}", parent, resources); |
102 | return true; | 102 | return true; |
103 | } | 103 | } |
104 | 104 | ||
105 | - DiscreteResources requested = DiscreteResources.of(values); | 105 | + DiscreteResources requested = DiscreteResources.of(resources); |
106 | DiscreteResources newValues = oldValues.difference(requested); | 106 | DiscreteResources newValues = oldValues.difference(requested); |
107 | - return childMap.replace(key, oldValues, newValues); | 107 | + return childMap.replace(parent, oldValues, newValues); |
108 | } | 108 | } |
109 | 109 | ||
110 | private boolean isAllocated(DiscreteResourceId id) { | 110 | private boolean isAllocated(DiscreteResourceId id) { | ... | ... |
-
Please register or login to post a comment