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%2FDataTreeChangeListenerSupport.java;h=c7fb05f7e920c31b83d870e923636c201ab06d92;hb=9b235df8e0b4d8c4c7419419538188cdf7b2bfc2;hp=fa55523db0087467d4919075cbc39abc2a46621b;hpb=6050fd28f2def659abb5bc9d7127eb748b5fb32a;p=controller.git 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 fa55523db0..c7fb05f7e9 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,63 +9,30 @@ 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; +import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener; final class DataTreeChangeListenerSupport extends AbstractDataListenerSupport> { + RegisterDataTreeChangeListener> { + 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()); - - // 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); - - 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()); + void doRegistration(final RegisterDataTreeChangeListener message, final ActorRef registrationActor) { + final ActorSelection listenerActor = processListenerRegistrationMessage(message); - return regEntry; - } + DOMDataTreeChangeListener listener = new ForwardingDataTreeChangeListener(listenerActor); - @Override - protected DelayedDataTreeListenerRegistration newDelayedListenerRegistration(RegisterDataTreeChangeListener message) { - return new DelayedDataTreeListenerRegistration(message); - } + log().debug("{}: Registering listenerActor {} for path {}", persistenceId(), listenerActor, message.getPath()); - @Override - protected ActorRef newRegistrationActor(ListenerRegistration registration) { - return createActor(DataTreeChangeListenerRegistrationActor.props(registration)); - } - - @Override - protected Object newRegistrationReplyMessage(ActorRef registrationActor) { - return new RegisterDataTreeChangeListenerReply(registrationActor); + final ShardDataTree shardDataTree = getShard().getDataStore(); + shardDataTree.registerTreeChangeListener(message.getPath(), + listener, shardDataTree.readCurrentData(), registration -> registrationActor.tell( + new DataTreeNotificationListenerRegistrationActor.SetRegistration(registration, () -> + removeListenerActor(listenerActor)), ActorRef.noSender())); } @Override