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%2Fselectionstrategy%2FLeastLoadedCandidateSelectionStrategy.java;h=7102cbbbf096be52bcc1656b39e162e6ce7bf796;hb=12fcdfe39aa26dcba7fd3bb4d4c68e3d02e65c51;hp=ee01d95496876ef0c0f5525ba59280898df0cd78;hpb=bb1891e328feee08ccd29c96034e967f1eeccece;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/LeastLoadedCandidateSelectionStrategy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/LeastLoadedCandidateSelectionStrategy.java index ee01d95496..7102cbbbf0 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/LeastLoadedCandidateSelectionStrategy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/selectionstrategy/LeastLoadedCandidateSelectionStrategy.java @@ -15,17 +15,14 @@ import com.google.common.base.Strings; import java.util.Collection; import java.util.HashMap; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; /** * The LeastLoadedCandidateSelectionStrategy assigns ownership for an entity to the candidate which owns the least * number of entities. */ public class LeastLoadedCandidateSelectionStrategy extends AbstractEntityOwnerSelectionStrategy { - private static final Logger LOG = LoggerFactory.getLogger(LeastLoadedCandidateSelectionStrategy.class); - - private Map localStatistics = new HashMap<>(); + private final Map localStatistics = new HashMap<>(); protected LeastLoadedCandidateSelectionStrategy(long selectionDelayInMillis, Map initialStatistics) { super(selectionDelayInMillis, initialStatistics); @@ -34,25 +31,25 @@ public class LeastLoadedCandidateSelectionStrategy extends AbstractEntityOwnerSe } @Override - public String newOwner(String currentOwner, Collection viableCandidates) { + public String newOwner(@Nullable String currentOwner, Collection viableCandidates) { Preconditions.checkArgument(viableCandidates.size() > 0); String leastLoadedCandidate = null; long leastLoadedCount = Long.MAX_VALUE; - if(!Strings.isNullOrEmpty(currentOwner)){ + if (!Strings.isNullOrEmpty(currentOwner)) { long localVal = MoreObjects.firstNonNull(localStatistics.get(currentOwner), 0L); localStatistics.put(currentOwner, localVal - 1); } - for(String candidateName : viableCandidates){ + for (String candidateName : viableCandidates) { long val = MoreObjects.firstNonNull(localStatistics.get(candidateName), 0L); - if(val < leastLoadedCount){ + if (val < leastLoadedCount) { leastLoadedCount = val; leastLoadedCandidate = candidateName; } } - if(leastLoadedCandidate == null){ + if (leastLoadedCandidate == null) { leastLoadedCandidate = viableCandidates.iterator().next(); } @@ -61,7 +58,7 @@ public class LeastLoadedCandidateSelectionStrategy extends AbstractEntityOwnerSe } @VisibleForTesting - Map getLocalStatistics(){ + Map getLocalStatistics() { return localStatistics; } }