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%2FCandidateListChangeListener.java;h=833ca30e31412f8ac159933a02d40e27e50eb05d;hb=175f38490b56c4b4e0ec356b17b91f887b295da4;hp=35100cb5b9a49d3e5c72be4d5c98fc7d3a0810ee;hpb=00e97ff87662959a39218b47bac904235003dc8d;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java index 35100cb5b9..833ca30e31 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/CandidateListChangeListener.java @@ -44,15 +44,19 @@ import org.slf4j.LoggerFactory; * @author Moiz Raja * @author Thomas Pantelis */ -public class CandidateListChangeListener implements DOMDataTreeChangeListener { +class CandidateListChangeListener implements DOMDataTreeChangeListener { private static final Logger LOG = LoggerFactory.getLogger(CandidateListChangeListener.class); + private final String logId; private final ActorRef shard; private final Map> currentCandidates = new HashMap<>(); - public CandidateListChangeListener(ActorRef shard, ShardDataTree shardDataTree) { + CandidateListChangeListener(ActorRef shard, String logId) { this.shard = Preconditions.checkNotNull(shard, "shard should not be null"); + this.logId = logId; + } + void init(ShardDataTree shardDataTree) { shardDataTree.registerTreeChangeListener(YangInstanceIdentifier.builder(ENTITY_OWNERS_PATH). node(EntityType.QNAME).node(EntityType.QNAME).node(ENTITY_QNAME).node(ENTITY_QNAME). node(Candidate.QNAME).node(Candidate.QNAME).build(), this); @@ -62,8 +66,9 @@ public class CandidateListChangeListener implements DOMDataTreeChangeListener { public void onDataTreeChanged(Collection changes) { for(DataTreeCandidate change: changes) { DataTreeCandidateNode changeRoot = change.getRootNode(); + ModificationType type = changeRoot.getModificationType(); - LOG.debug("Candidate node changed: {}, {}", changeRoot.getModificationType(), change.getRootPath()); + LOG.debug("{}: Candidate node changed: {}, {}", logId, type, change.getRootPath()); NodeIdentifierWithPredicates candidateKey = (NodeIdentifierWithPredicates) change.getRootPath().getLastPathArgument(); @@ -71,13 +76,13 @@ public class CandidateListChangeListener implements DOMDataTreeChangeListener { YangInstanceIdentifier entityId = extractEntityPath(change.getRootPath()); - if(changeRoot.getModificationType() == ModificationType.WRITE) { - LOG.debug("Candidate {} was added for entity {}", candidate, entityId); + if(type == ModificationType.WRITE || type == ModificationType.APPEARED) { + LOG.debug("{}: Candidate {} was added for entity {}", logId, candidate, entityId); Collection currentCandidates = addToCurrentCandidates(entityId, candidate); shard.tell(new CandidateAdded(entityId, candidate, new ArrayList<>(currentCandidates)), shard); - } else if(changeRoot.getModificationType() == ModificationType.DELETE) { - LOG.debug("Candidate {} was removed for entity {}", candidate, entityId); + } else if(type == ModificationType.DELETE || type == ModificationType.DISAPPEARED) { + LOG.debug("{}: Candidate {} was removed for entity {}", logId, candidate, entityId); Collection currentCandidates = removeFromCurrentCandidates(entityId, candidate); shard.tell(new CandidateRemoved(entityId, candidate, new ArrayList<>(currentCandidates)), shard); @@ -107,7 +112,7 @@ public class CandidateListChangeListener implements DOMDataTreeChangeListener { return Collections.emptyList(); } - private YangInstanceIdentifier extractEntityPath(YangInstanceIdentifier candidatePath) { + private static YangInstanceIdentifier extractEntityPath(YangInstanceIdentifier candidatePath) { List newPathArgs = new ArrayList<>(); for(PathArgument pathArg: candidatePath.getPathArguments()) { newPathArgs.add(pathArg); @@ -122,4 +127,4 @@ public class CandidateListChangeListener implements DOMDataTreeChangeListener { return YangInstanceIdentifier.create(newPathArgs); } -} \ No newline at end of file +}