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=731e7284cf0895fdb1b89427f91762e80e67c2ff;hp=5b8e5f8abfb871f4bd2c503ce7de1853b4c5aac5;hpb=013a6679470bf692753f2e04ab4398c97fd9f5d0;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 5b8e5f8abf..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,89 +9,30 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorRef; import akka.actor.ActorSelection; -import com.google.common.base.Optional; -import com.google.common.collect.Sets; -import java.util.Collection; -import java.util.Collections; -import java.util.Map.Entry; -import java.util.Set; -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> { - - private final Set listenerActors = Sets.newConcurrentHashSet(); + RegisterDataTreeChangeListener> { DataTreeChangeListenerSupport(final Shard shard) { super(shard); } - Collection getListenerActors() { - return Collections.unmodifiableCollection(listenerActors); - } - @Override - ListenerRegistration createDelegate( - final RegisterDataTreeChangeListener message) { - final 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); - } + void doRegistration(final RegisterDataTreeChangeListener message, final ActorRef registrationActor) { + final ActorSelection listenerActor = processListenerRegistrationMessage(message); - DOMDataTreeChangeListener listener = new ForwardingDataTreeChangeListener(dataChangeListenerPath); + DOMDataTreeChangeListener listener = new ForwardingDataTreeChangeListener(listenerActor); - log().debug("{}: Registering for path {}", persistenceId(), message.getPath()); + log().debug("{}: Registering listenerActor {} for path {}", persistenceId(), listenerActor, message.getPath()); - Entry, Optional> regEntry = - getShard().getDataStore().registerTreeChangeListener(message.getPath(), listener); - - getShard().getDataStore().notifyOfInitialData(message.getPath(), - regEntry.getKey().getInstance(), regEntry.getValue()); - - listenerActors.add(dataChangeListenerPath); - final ListenerRegistration delegate = regEntry.getKey(); - return new ListenerRegistration() { - @Override - public DOMDataTreeChangeListener getInstance() { - return delegate.getInstance(); - } - - @Override - public void close() { - listenerActors.remove(dataChangeListenerPath); - delegate.close(); - } - }; - } - - @Override - protected DelayedDataTreeListenerRegistration newDelayedListenerRegistration( - RegisterDataTreeChangeListener message) { - return new DelayedDataTreeListenerRegistration(message); - } - - @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