Implemented a globally unique next id generator in FlowObjectStore
Change-Id: Ib98b2996e1ebcca56ad816ea94f25d838c5f4d44
diff --git a/core/store/dist/src/main/java/org/onosproject/store/flowobjective/impl/DistributedFlowObjectiveStore.java b/core/store/dist/src/main/java/org/onosproject/store/flowobjective/impl/DistributedFlowObjectiveStore.java
index 94d72ec..8dbc634 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/flowobjective/impl/DistributedFlowObjectiveStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/flowobjective/impl/DistributedFlowObjectiveStore.java
@@ -28,6 +28,7 @@
import org.onosproject.net.flowobjective.FlowObjectiveStoreDelegate;
import org.onosproject.net.flowobjective.ObjectiveEvent;
import org.onosproject.store.AbstractStore;
+import org.onosproject.store.service.AtomicCounter;
import org.onosproject.store.service.ConsistentMap;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageService;
@@ -52,6 +53,8 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected StorageService storageService;
+ private AtomicCounter nextIds;
+
@Activate
public void activate() {
nextGroups = storageService.<Integer, byte[]>consistentMapBuilder()
@@ -62,6 +65,10 @@
.build()))
.build();
+ nextIds = storageService.atomicCounterBuilder()
+ .withName("next-objective-counter")
+ .build();
+
log.info("Started");
}
@@ -86,4 +93,9 @@
}
return null;
}
+
+ @Override
+ public int allocateNextId() {
+ return (int) nextIds.incrementAndGet();
+ }
}