Zsolt Haraszti
Committed by Gerrit Code Review

Use allocateNextId when building new NextObjective

In order to avoid nextId collisions, all users of the flow objective
service should use the provided allocateNextId() method when
constructing new NextObjectives. I found one instance where this was not
the case: CordMcast.

Solution: removed private id generator from CordMacst and replaced it
with allocateNextId.

Change-Id: I134931b58c524291ae937dd6f0051ee549236734
...@@ -77,7 +77,6 @@ import java.util.Map; ...@@ -77,7 +77,6 @@ import java.util.Map;
77 import java.util.Properties; 77 import java.util.Properties;
78 import java.util.concurrent.ConcurrentHashMap; 78 import java.util.concurrent.ConcurrentHashMap;
79 import java.util.concurrent.atomic.AtomicBoolean; 79 import java.util.concurrent.atomic.AtomicBoolean;
80 -import java.util.concurrent.atomic.AtomicInteger;
81 80
82 import static com.google.common.base.Preconditions.checkNotNull; 81 import static com.google.common.base.Preconditions.checkNotNull;
83 import static com.google.common.base.Strings.isNullOrEmpty; 82 import static com.google.common.base.Strings.isNullOrEmpty;
...@@ -129,9 +128,6 @@ public class CordMcast { ...@@ -129,9 +128,6 @@ public class CordMcast {
129 //TODO: move this to a ec map 128 //TODO: move this to a ec map
130 private Map<IpAddress, Integer> groups = Maps.newConcurrentMap(); 129 private Map<IpAddress, Integer> groups = Maps.newConcurrentMap();
131 130
132 - //TODO: move this to distributed atomic long
133 - private AtomicInteger channels = new AtomicInteger(0);
134 -
135 private ApplicationId appId; 131 private ApplicationId appId;
136 132
137 @Property(name = "mcastVlan", intValue = DEFAULT_MCAST_VLAN, 133 @Property(name = "mcastVlan", intValue = DEFAULT_MCAST_VLAN,
...@@ -331,7 +327,7 @@ public class CordMcast { ...@@ -331,7 +327,7 @@ public class CordMcast {
331 final AtomicBoolean sync = new AtomicBoolean(false); 327 final AtomicBoolean sync = new AtomicBoolean(false);
332 328
333 Integer nextId = groups.computeIfAbsent(route.group(), (g) -> { 329 Integer nextId = groups.computeIfAbsent(route.group(), (g) -> {
334 - Integer id = allocateId(); 330 + Integer id = flowObjectiveService.allocateNextId();
335 331
336 NextObjective next = DefaultNextObjective.builder() 332 NextObjective next = DefaultNextObjective.builder()
337 .fromApp(appId) 333 .fromApp(appId)
...@@ -497,10 +493,6 @@ public class CordMcast { ...@@ -497,10 +493,6 @@ public class CordMcast {
497 mcastRoutes.forEach(this::removeRemoteRoute); 493 mcastRoutes.forEach(this::removeRemoteRoute);
498 } 494 }
499 495
500 - private Integer allocateId() {
501 - return channels.getAndIncrement();
502 - }
503 -
504 private WebResource.Builder getClientBuilder(String uri) { 496 private WebResource.Builder getClientBuilder(String uri) {
505 Client client = Client.create(); 497 Client client = Client.create();
506 client.setConnectTimeout(DEFAULT_REST_TIMEOUT_MS); 498 client.setConnectTimeout(DEFAULT_REST_TIMEOUT_MS);
......