X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-inmemory-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fstore%2Fimpl%2FInMemoryDOMStoreTreeChangePublisher.java;h=3337d1ce9bcdc14c5225978592492eb52943f017;hb=72d71d1cded60bcac65296211272754006b3f89a;hp=999fb91c659e20bed7a481ce3b12013efa230586;hpb=1561fd6e1546236640afc070eb2fc68a064347f0;p=controller.git diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMStoreTreeChangePublisher.java b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMStoreTreeChangePublisher.java index 999fb91c65..3337d1ce9b 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMStoreTreeChangePublisher.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMStoreTreeChangePublisher.java @@ -8,42 +8,51 @@ package org.opendaylight.controller.md.sal.dom.store.impl; import java.util.Collection; -import java.util.Collections; +import java.util.Optional; import java.util.concurrent.ExecutorService; -import javax.annotation.Nonnull; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener; import org.opendaylight.controller.md.sal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration; import org.opendaylight.controller.sal.core.spi.data.AbstractDOMStoreTreeChangePublisher; +import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager; -import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager.Invoker; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate; import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates; +import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; final class InMemoryDOMStoreTreeChangePublisher extends AbstractDOMStoreTreeChangePublisher { - private static final Invoker, DataTreeCandidate> MANAGER_INVOKER = - new Invoker, DataTreeCandidate>() { - @Override - public void invokeListener(final AbstractDOMDataTreeChangeListenerRegistration listener, final DataTreeCandidate notification) { - // FIXME: this is inefficient, as we could grab the entire queue for the listener and post it - final DOMDataTreeChangeListener inst = listener.getInstance(); - if (inst != null) { - inst.onDataTreeChanged(Collections.singletonList(notification)); - } - } - }; private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMStoreTreeChangePublisher.class); - private final QueuedNotificationManager, DataTreeCandidate> notificationManager; + + private final QueuedNotificationManager, DataTreeCandidate> + notificationManager; InMemoryDOMStoreTreeChangePublisher(final ExecutorService listenerExecutor, final int maxQueueSize) { - notificationManager = new QueuedNotificationManager<>(listenerExecutor, MANAGER_INVOKER, maxQueueSize, "DataTreeChangeListenerQueueMgr"); + notificationManager = QueuedNotificationManager.create(listenerExecutor, (listener, notifications) -> { + // FIXME: we are not checking for listener being closed + listener.getInstance().onDataTreeChanged(notifications); + }, maxQueueSize, + "DataTreeChangeListenerQueueMgr"); + } + + private InMemoryDOMStoreTreeChangePublisher(final QueuedNotificationManager< + AbstractDOMDataTreeChangeListenerRegistration, DataTreeCandidate> notificationManager) { + this.notificationManager = notificationManager; + } + + QueuedNotificationManager, DataTreeCandidate> + getNotificationManager() { + return notificationManager; } @Override - protected void notifyListeners(final Collection> registrations, final YangInstanceIdentifier path, final DataTreeCandidateNode node) { - final DataTreeCandidate candidate = new SimpleDataTreeCandidate(path, node); + protected void notifyListeners(final Collection> registrations, + final YangInstanceIdentifier path, final DataTreeCandidateNode node) { + final DataTreeCandidate candidate = DataTreeCandidates.newDataTreeCandidate(path, node); for (AbstractDOMDataTreeChangeListenerRegistration reg : registrations) { LOG.debug("Enqueueing candidate {} to registration {}", candidate, registrations); @@ -52,13 +61,32 @@ final class InMemoryDOMStoreTreeChangePublisher extends AbstractDOMStoreTreeChan } @Override - protected synchronized void registrationRemoved(final AbstractDOMDataTreeChangeListenerRegistration registration) { + protected synchronized void registrationRemoved( + final AbstractDOMDataTreeChangeListenerRegistration registration) { LOG.debug("Closing registration {}", registration); // FIXME: remove the queue for this registration and make sure we clear it } - synchronized void publishChange(@Nonnull final DataTreeCandidate candidate) { + ListenerRegistration registerTreeChangeListener( + final YangInstanceIdentifier treeId, final L listener, final DataTreeSnapshot snapshot) { + final AbstractDOMDataTreeChangeListenerRegistration reg = registerTreeChangeListener(treeId, listener); + + final Optional> node = snapshot.readNode(YangInstanceIdentifier.EMPTY); + if (node.isPresent()) { + final DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode( + YangInstanceIdentifier.EMPTY, node.get()); + + InMemoryDOMStoreTreeChangePublisher publisher = + new InMemoryDOMStoreTreeChangePublisher(notificationManager); + publisher.registerTreeChangeListener(treeId, listener); + publisher.publishChange(candidate); + } + + return reg; + } + + synchronized void publishChange(final @NonNull DataTreeCandidate candidate) { // Runs synchronized with registrationRemoved() processCandidateTree(candidate); }