Committed by
Sho Shimizu
Preserve the original order when registering/unregistering
Change-Id: Id112f7027454132f00ca45b4254aa3f5c2e7b094
Showing
1 changed file
with
5 additions
and
2 deletions
... | @@ -53,6 +53,7 @@ import org.slf4j.LoggerFactory; | ... | @@ -53,6 +53,7 @@ import org.slf4j.LoggerFactory; |
53 | import java.util.Arrays; | 53 | import java.util.Arrays; |
54 | import java.util.Collection; | 54 | import java.util.Collection; |
55 | import java.util.Iterator; | 55 | import java.util.Iterator; |
56 | +import java.util.LinkedHashMap; | ||
56 | import java.util.LinkedHashSet; | 57 | import java.util.LinkedHashSet; |
57 | import java.util.List; | 58 | import java.util.List; |
58 | import java.util.Map; | 59 | import java.util.Map; |
... | @@ -162,9 +163,10 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour | ... | @@ -162,9 +163,10 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour |
162 | TransactionalMap<DiscreteResourceId, Set<Resource>> childTxMap = | 163 | TransactionalMap<DiscreteResourceId, Set<Resource>> childTxMap = |
163 | tx.getTransactionalMap(CHILD_MAP, SERIALIZER); | 164 | tx.getTransactionalMap(CHILD_MAP, SERIALIZER); |
164 | 165 | ||
166 | + // the order is preserved by LinkedHashMap | ||
165 | Map<DiscreteResource, List<Resource>> resourceMap = resources.stream() | 167 | Map<DiscreteResource, List<Resource>> resourceMap = resources.stream() |
166 | .filter(x -> x.parent().isPresent()) | 168 | .filter(x -> x.parent().isPresent()) |
167 | - .collect(Collectors.groupingBy(x -> x.parent().get())); | 169 | + .collect(Collectors.groupingBy(x -> x.parent().get(), LinkedHashMap::new, Collectors.toList())); |
168 | 170 | ||
169 | for (Map.Entry<DiscreteResource, List<Resource>> entry: resourceMap.entrySet()) { | 171 | for (Map.Entry<DiscreteResource, List<Resource>> entry: resourceMap.entrySet()) { |
170 | if (!lookup(childTxMap, entry.getKey().id()).isPresent()) { | 172 | if (!lookup(childTxMap, entry.getKey().id()).isPresent()) { |
... | @@ -208,8 +210,9 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour | ... | @@ -208,8 +210,9 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour |
208 | .filter(Optional::isPresent) | 210 | .filter(Optional::isPresent) |
209 | .map(Optional::get) | 211 | .map(Optional::get) |
210 | .collect(Collectors.toList()); | 212 | .collect(Collectors.toList()); |
213 | + // the order is preserved by LinkedHashMap | ||
211 | Map<DiscreteResourceId, List<Resource>> resourceMap = resources.stream() | 214 | Map<DiscreteResourceId, List<Resource>> resourceMap = resources.stream() |
212 | - .collect(Collectors.groupingBy(x -> x.parent().get().id())); | 215 | + .collect(Collectors.groupingBy(x -> x.parent().get().id(), LinkedHashMap::new, Collectors.toList())); |
213 | 216 | ||
214 | // even if one of the resources is allocated to a consumer, | 217 | // even if one of the resources is allocated to a consumer, |
215 | // all unregistrations are regarded as failure | 218 | // all unregistrations are regarded as failure | ... | ... |
-
Please register or login to post a comment