ONOS-5816

Change-Id: I595fa04b9083bcbfe275b0342bcda0c4f1ecc8f5
This commit is contained in:
Kavitha Alagesan 2017-01-19 12:32:26 +05:30 committed by Ray Milkey
parent 0083a5120d
commit c884c3eff1

View File

@ -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<Status> statusChangeListener;
// Per device group table with (device id + app cookie) as key
private ConsistentMap<GroupStoreKeyMapKey,
StoredGroupEntry> 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.<GroupStoreKeyMapKey, StoredGroupEntry>consistentMapBuilder()
@ -251,6 +267,16 @@ public class DistributedGroupStore
}
}
/**
* Updating values of groupEntriesById.
*/
private void matchGroupEntries() {
for (Entry<GroupStoreKeyMapKey, StoredGroupEntry> entry : groupStoreEntriesByKey.asJavaMap().entrySet()) {
StoredGroupEntry group = entry.getValue();
getGroupIdTable(entry.getKey().deviceId()).put(group.id(), group);
}
}
/**
* Returns the group store eventual consistent key map.
*