X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fentityownership%2FEntityOwnershipStatistics.java;h=b09356dcc1c20c0964b222c8265fef3cc8360285;hb=3859df9beca8f13f1ff2b2744ed3470a1715bec3;hp=6c013c1c8f37ee50c9fda10fa40e372dd9dd86c9;hpb=83c901ab9309bda0f78e8a847a5511061f6e79b5;p=controller.git 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 6c013c1c8f..b09356dcc1 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 @@ -5,22 +5,20 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - 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 java.util.Optional; 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; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; +import tech.pantheon.triemap.TrieMap; /** * EntityOwnershipStatistics is a utility class that keeps track of ownership statistics for the candidates and @@ -31,13 +29,13 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNod */ class EntityOwnershipStatistics extends AbstractEntityOwnerChangeListener { - private final TrieMap> statistics = new TrieMap<>(); + private final TrieMap> statistics = TrieMap.create(); EntityOwnershipStatistics(){ } @Override - public void onDataTreeChanged(@Nonnull Collection changes) { + public void onDataTreeChanged(final Collection changes) { for (DataTreeCandidate change : changes) { DataTreeCandidateNode changeRoot = change.getRootNode(); LeafNode ownerLeaf = (LeafNode) changeRoot.getDataAfter().get(); @@ -59,32 +57,27 @@ 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) { + Map byEntityType(final String entityType) { if (statistics.get(entityType) != null) { - return statistics.get(entityType).readOnlySnapshot(); + return statistics.get(entityType).immutableSnapshot(); } return new HashMap<>(); } - private void updateStatistics(String entityType, String candidateName, long count) { - Map map = statistics.get(entityType); + private void updateStatistics(final String entityType, final String candidateName, final long count) { + TrieMap map = statistics.get(entityType); if (map == null) { - map = new TrieMap<>(); + map = TrieMap.create(); map.put(candidateName, count); statistics.put(entityType, map); } else { - Long candidateOwnedEntities = map.get(candidateName); - if (candidateOwnedEntities == null) { - map.put(candidateName, count); - } else { - map.put(candidateName, candidateOwnedEntities + count); - } + map.merge(candidateName, count, (ownedEntities, addedEntities) -> ownedEntities + addedEntities); } } }