X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-inmemory-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fstore%2Fimpl%2FInMemoryDOMStoreTreeChangePublisher.java;h=4b656400a882515654d87e04fbf93f05b9b04ad3;hp=2f3b46366a918b9f92d8791c3cf68d39ae6bb3a1;hb=e2607370f5ac443a5a2f1f00f693f82a0b57161d;hpb=f0a3398f9a6598b9b7321ddf7d1a2f9433065d92 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 2f3b46366a..4b656400a8 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 @@ -7,9 +7,9 @@ */ package org.opendaylight.controller.md.sal.dom.store.impl; -import com.google.common.base.Optional; import java.util.Collection; import java.util.Collections; +import java.util.Optional; import java.util.concurrent.ExecutorService; import javax.annotation.Nonnull; import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener; @@ -29,25 +29,28 @@ 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)); - } - } - }; + (listener, notification) -> { + // FIXME: this is inefficient, as we could grab the entire queue for the listener and post it + listener.getInstance().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 = new QueuedNotificationManager<>(listenerExecutor, MANAGER_INVOKER, maxQueueSize, + "DataTreeChangeListenerQueueMgr"); + } + + private InMemoryDOMStoreTreeChangePublisher(QueuedNotificationManager< + AbstractDOMDataTreeChangeListenerRegistration, DataTreeCandidate> notificationManager) { + this.notificationManager = notificationManager; } @Override - protected void notifyListeners(final Collection> registrations, final YangInstanceIdentifier path, final DataTreeCandidateNode node) { + protected void notifyListeners(final Collection> registrations, + final YangInstanceIdentifier path, final DataTreeCandidateNode node) { final DataTreeCandidate candidate = DataTreeCandidates.newDataTreeCandidate(path, node); for (AbstractDOMDataTreeChangeListenerRegistration reg : registrations) { @@ -57,19 +60,26 @@ 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 } - ListenerRegistration registerTreeChangeListener(final YangInstanceIdentifier treeId, final L listener, final DataTreeSnapshot snapshot) { + ListenerRegistration registerTreeChangeListener( + final YangInstanceIdentifier treeId, final L listener, final DataTreeSnapshot snapshot) { final AbstractDOMDataTreeChangeListenerRegistration reg = registerTreeChangeListener(treeId, listener); - final Optional> node = snapshot.readNode(treeId); + final Optional> node = snapshot.readNode(YangInstanceIdentifier.EMPTY); if (node.isPresent()) { - final DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode(treeId, node.get()); - notificationManager.submitNotification(reg, candidate); + final DataTreeCandidate candidate = DataTreeCandidates.fromNormalizedNode( + YangInstanceIdentifier.EMPTY, node.get()); + + InMemoryDOMStoreTreeChangePublisher publisher = + new InMemoryDOMStoreTreeChangePublisher(notificationManager); + publisher.registerTreeChangeListener(treeId, listener); + publisher.publishChange(candidate); } return reg;