Committed by
Gerrit Code Review
Synchronize Multimap access.
- ONOS-2626 Change-Id: I730b310e67ab858999a16565b05c2904d9d9481c
Showing
1 changed file
with
7 additions
and
2 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,18 +257,24 @@ public class ECHostStore | ... | @@ -258,18 +257,24 @@ public class ECHostStore |
| 258 | 257 | ||
| 259 | @Override | 258 | @Override |
| 260 | public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { | 259 | public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { |
| 260 | + synchronized (locations) { | ||
| 261 | return ImmutableSet.copyOf(locations.get(connectPoint)); | 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; |
| 268 | + synchronized (locations) { | ||
| 269 | + filtered = locations | ||
| 267 | .entries() | 270 | .entries() |
| 268 | .stream() | 271 | .stream() |
| 269 | .filter(entry -> entry.getKey().deviceId().equals(deviceId)) | 272 | .filter(entry -> entry.getKey().deviceId().equals(deviceId)) |
| 270 | .map(entry -> entry.getValue()) | 273 | .map(entry -> entry.getValue()) |
| 271 | .collect(Collectors.toSet()); | 274 | .collect(Collectors.toSet()); |
| 272 | } | 275 | } |
| 276 | + return ImmutableSet.copyOf(filtered); | ||
| 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) { |
| 275 | return collection.stream().filter(predicate).collect(Collectors.toSet()); | 280 | return collection.stream().filter(predicate).collect(Collectors.toSet()); | ... | ... |
-
Please register or login to post a comment