From c884c3eff161735dfda30e86190b652f7d51cb3d Mon Sep 17 00:00:00 2001 From: Kavitha Alagesan Date: Thu, 19 Jan 2017 12:32:26 +0530 Subject: [PATCH] ONOS-5816 Change-Id: I595fa04b9083bcbfe275b0342bcda0c4f1ecc8f5 --- .../group/impl/DistributedGroupStore.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java b/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java index 88a1d54fc7..5fea69af18 100644 --- a/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java +++ b/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java @@ -64,6 +64,7 @@ import org.onosproject.store.service.Serializer; import org.onosproject.store.service.StorageService; import org.onosproject.store.service.Topic; import org.onosproject.store.service.Versioned; +import org.onosproject.store.service.DistributedPrimitive.Status; import org.osgi.service.component.ComponentContext; import org.slf4j.Logger; @@ -85,10 +86,13 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; import java.util.stream.Collectors; import static com.google.common.base.Strings.isNullOrEmpty; +import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; import static org.onlab.util.Tools.get; import static org.onlab.util.Tools.groupedThreads; import static org.slf4j.LoggerFactory.getLogger; @@ -126,6 +130,8 @@ public class DistributedGroupStore @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected ComponentConfigService cfgService; + private ScheduledExecutorService executor; + private Consumer statusChangeListener; // Per device group table with (device id + app cookie) as key private ConsistentMap groupStoreEntriesByKey = null; @@ -204,6 +210,16 @@ public class DistributedGroupStore log.debug("Current size of groupstorekeymap:{}", groupStoreEntriesByKey.size()); + log.debug("Creating GroupStoreId Map From GroupStoreKey Map"); + matchGroupEntries(); + executor = newSingleThreadScheduledExecutor(groupedThreads("onos/group", "store", log)); + statusChangeListener = status -> { + if (status == Status.ACTIVE) { + executor.execute(this::matchGroupEntries); + } + }; + groupStoreEntriesByKey.addStatusChangeListener(statusChangeListener); + log.debug("Creating Consistent map pendinggroupkeymap"); auditPendingReqQueue = storageService.consistentMapBuilder() @@ -251,6 +267,16 @@ public class DistributedGroupStore } } + /** + * Updating values of groupEntriesById. + */ + private void matchGroupEntries() { + for (Entry entry : groupStoreEntriesByKey.asJavaMap().entrySet()) { + StoredGroupEntry group = entry.getValue(); + getGroupIdTable(entry.getKey().deviceId()).put(group.id(), group); + } + } + /** * Returns the group store eventual consistent key map. *