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%2FDataTreeChangeListenerSupport.java;h=4f70327cb7246e947801902c05a39d2f5c81cc3b;hp=f039ab707ba76fa4749c7895469d2c5af40b12ba;hb=ec870dee9bacb971f11bc747b69e84ac37f5d746;hpb=925cb4a228d0fda99c7bfeb432eb25285a223887 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupport.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupport.java index f039ab707b..4f70327cb7 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupport.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DataTreeChangeListenerSupport.java @@ -9,60 +9,37 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorRef; import akka.actor.ActorSelection; -import com.google.common.base.Optional; -import java.util.Map.Entry; -import org.opendaylight.controller.cluster.datastore.messages.EnableNotification; +import org.opendaylight.controller.cluster.datastore.actors.DataTreeNotificationListenerRegistrationActor; import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListener; import org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeChangeListenerReply; import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; final class DataTreeChangeListenerSupport extends AbstractDataListenerSupport> { + RegisterDataTreeChangeListener, DelayedDataTreeListenerRegistration> { + DataTreeChangeListenerSupport(final Shard shard) { super(shard); } @Override - Entry, Optional> createDelegate( - final RegisterDataTreeChangeListener message) { - ActorSelection dataChangeListenerPath = selectActor(message.getDataTreeChangeListenerPath()); - - // Notify the listener if notifications should be enabled or not - // If this shard is the leader then it will enable notifications else - // it will not - dataChangeListenerPath.tell(new EnableNotification(true), getSelf()); + void doRegistration(final RegisterDataTreeChangeListener message, final ActorRef registrationActor) { + final ActorSelection listenerActor = processListenerRegistrationMessage(message); - // Now store a reference to the data change listener so it can be notified - // at a later point if notifications should be enabled or disabled - if (!message.isRegisterOnAllInstances()) { - addListenerActor(dataChangeListenerPath); - } - - DOMDataTreeChangeListener listener = new ForwardingDataTreeChangeListener(dataChangeListenerPath); + DOMDataTreeChangeListener listener = new ForwardingDataTreeChangeListener(listenerActor); log().debug("{}: Registering for path {}", persistenceId(), message.getPath()); - Entry, Optional> regEntry = - getShard().getDataStore().registerTreeChangeListener(message.getPath(), listener); - - getShard().getDataStore().notifyOfInitialData(message.getPath(), - regEntry.getKey().getInstance(), regEntry.getValue()); - - return regEntry; + final ShardDataTree shardDataTree = getShard().getDataStore(); + shardDataTree.registerTreeChangeListener(message.getPath(), + listener, shardDataTree.readCurrentData(), registration -> registrationActor.tell( + new DataTreeNotificationListenerRegistrationActor.SetRegistration(registration, () -> + removeListenerActor(listenerActor)), ActorRef.noSender())); } @Override protected DelayedDataTreeListenerRegistration newDelayedListenerRegistration( - RegisterDataTreeChangeListener message) { - return new DelayedDataTreeListenerRegistration(message); - } - - @Override - protected ActorRef newRegistrationActor(ListenerRegistration registration) { - return createActor(DataTreeChangeListenerRegistrationActor.props(registration)); + RegisterDataTreeChangeListener message, ActorRef registrationActor) { + return new DelayedDataTreeListenerRegistration(message, registrationActor); } @Override