Committed by
Gerrit Code Review
Synchronize Multimap access.
- ONOS-2626 Change-Id: I730b310e67ab858999a16565b05c2904d9d9481c
Showing
1 changed file
with
13 additions
and
8 deletions
... | @@ -68,7 +68,6 @@ import org.onosproject.store.service.StorageService; | ... | @@ -68,7 +68,6 @@ import org.onosproject.store.service.StorageService; |
68 | import org.slf4j.Logger; | 68 | import org.slf4j.Logger; |
69 | 69 | ||
70 | import com.google.common.collect.HashMultimap; | 70 | import com.google.common.collect.HashMultimap; |
71 | -import com.google.common.collect.ImmutableMultimap; | ||
72 | import com.google.common.collect.ImmutableSet; | 71 | import com.google.common.collect.ImmutableSet; |
73 | import com.google.common.collect.Multimaps; | 72 | import com.google.common.collect.Multimaps; |
74 | import com.google.common.collect.SetMultimap; | 73 | import com.google.common.collect.SetMultimap; |
... | @@ -258,17 +257,23 @@ public class ECHostStore | ... | @@ -258,17 +257,23 @@ public class ECHostStore |
258 | 257 | ||
259 | @Override | 258 | @Override |
260 | public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { | 259 | public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { |
261 | - return ImmutableSet.copyOf(locations.get(connectPoint)); | 260 | + synchronized (locations) { |
261 | + return ImmutableSet.copyOf(locations.get(connectPoint)); | ||
262 | + } | ||
262 | } | 263 | } |
263 | 264 | ||
264 | @Override | 265 | @Override |
265 | public Set<Host> getConnectedHosts(DeviceId deviceId) { | 266 | public Set<Host> getConnectedHosts(DeviceId deviceId) { |
266 | - return ImmutableMultimap.copyOf(locations) | 267 | + Set<Host> filtered; |
267 | - .entries() | 268 | + synchronized (locations) { |
268 | - .stream() | 269 | + filtered = locations |
269 | - .filter(entry -> entry.getKey().deviceId().equals(deviceId)) | 270 | + .entries() |
270 | - .map(entry -> entry.getValue()) | 271 | + .stream() |
271 | - .collect(Collectors.toSet()); | 272 | + .filter(entry -> entry.getKey().deviceId().equals(deviceId)) |
273 | + .map(entry -> entry.getValue()) | ||
274 | + .collect(Collectors.toSet()); | ||
275 | + } | ||
276 | + return ImmutableSet.copyOf(filtered); | ||
272 | } | 277 | } |
273 | 278 | ||
274 | private Set<Host> filter(Collection<DefaultHost> collection, Predicate<DefaultHost> predicate) { | 279 | private Set<Host> filter(Collection<DefaultHost> collection, Predicate<DefaultHost> predicate) { | ... | ... |
-
Please register or login to post a comment