X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fentityownership%2FEntityOwnershipStatistics.java;h=f18ae66e2f430261f117f0cf9cdcc46fe280ea99;hp=02bd00bfb1e43a7dfcd01c7fb98f85f64529f387;hb=354ad30e58618b4bdec256d7a78bd80284cccc77;hpb=1c66a277c9791984fab3b70f8e93d61795b2fe15 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipStatistics.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipStatistics.java index 02bd00bfb1..f18ae66e2f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipStatistics.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnershipStatistics.java @@ -9,13 +9,14 @@ package org.opendaylight.controller.cluster.datastore.entityownership; import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.entityTypeFromEntityPath; + import com.google.common.base.Optional; import com.google.common.base.Strings; -import com.romix.scala.collection.concurrent.TrieMap; import java.util.Collection; import java.util.HashMap; import java.util.Map; import javax.annotation.Nonnull; +import org.opendaylight.yangtools.triemap.TrieMap; import org.opendaylight.yangtools.yang.data.api.schema.LeafNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; @@ -24,32 +25,32 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNod /** * EntityOwnershipStatistics is a utility class that keeps track of ownership statistics for the candidates and * caches it for quick count queries. - *

+ *

* While the entity ownership model does maintain the information about which entity is owned by which candidate * finding out how many entities of a given type are owned by a given candidate is not an efficient query. */ class EntityOwnershipStatistics extends AbstractEntityOwnerChangeListener { - private TrieMap> statistics = new TrieMap<>(); + private final TrieMap> statistics = TrieMap.create(); EntityOwnershipStatistics(){ } @Override - public void onDataTreeChanged(@Nonnull Collection changes) { + public void onDataTreeChanged(@Nonnull final Collection changes) { for (DataTreeCandidate change : changes) { DataTreeCandidateNode changeRoot = change.getRootNode(); LeafNode ownerLeaf = (LeafNode) changeRoot.getDataAfter().get(); String entityType = entityTypeFromEntityPath(change.getRootPath()); String newOwner = extractOwner(ownerLeaf); - if(!Strings.isNullOrEmpty(newOwner)) { + if (!Strings.isNullOrEmpty(newOwner)) { updateStatistics(entityType, newOwner, 1); } Optional> dataBefore = changeRoot.getDataBefore(); if (dataBefore.isPresent()) { String origOwner = extractOwner((LeafNode) changeRoot.getDataBefore().get()); - if(!Strings.isNullOrEmpty(origOwner)) { + if (!Strings.isNullOrEmpty(origOwner)) { updateStatistics(entityType, origOwner, -1); } } @@ -58,32 +59,32 @@ class EntityOwnershipStatistics extends AbstractEntityOwnerChangeListener { Map> all() { Map> snapshot = new HashMap<>(); - for (String entityType : statistics.readOnlySnapshot().keySet()) { + for (String entityType : statistics.immutableSnapshot().keySet()) { snapshot.put(entityType, byEntityType(entityType)); } return snapshot; } - Map byEntityType(String entityType){ - if(statistics.get(entityType) != null) { - return statistics.get(entityType).readOnlySnapshot(); + Map byEntityType(final String entityType) { + if (statistics.get(entityType) != null) { + return statistics.get(entityType).immutableSnapshot(); } return new HashMap<>(); } - private void updateStatistics(String entityType, String candidateName, long count){ - Map m = statistics.get(entityType); - if(m == null){ - m = new TrieMap<>(); - m.put(candidateName, count); - statistics.put(entityType, m); + private void updateStatistics(final String entityType, final String candidateName, final long count) { + TrieMap map = statistics.get(entityType); + if (map == null) { + map = TrieMap.create(); + map.put(candidateName, count); + statistics.put(entityType, map); } else { - Long candidateOwnedEntities = m.get(candidateName); - if(candidateOwnedEntities == null){ - m.put(candidateName, count); + Long candidateOwnedEntities = map.get(candidateName); + if (candidateOwnedEntities == null) { + map.put(candidateName, count); } else { - m.put(candidateName, candidateOwnedEntities + count); + map.put(candidateName, candidateOwnedEntities + count); } } } -} \ No newline at end of file +}