Adjust to yangtools-2.0.0 changes
[controller.git] / opendaylight / md-sal / sal-inmemory-datastore / src / main / java / org / opendaylight / controller / md / sal / dom / store / impl / InMemoryDOMStoreTreeChangePublisher.java
index 2f3b46366a918b9f92d8791c3cf68d39ae6bb3a1..e469a159585543c7d7322a1487d06c995c1c8e07 100644 (file)
@@ -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,14 +29,11 @@ import org.slf4j.LoggerFactory;
 
 final class InMemoryDOMStoreTreeChangePublisher extends AbstractDOMStoreTreeChangePublisher {
     private static final Invoker<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate> MANAGER_INVOKER =
-            new Invoker<AbstractDOMDataTreeChangeListenerRegistration<?>, 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
+                final DOMDataTreeChangeListener inst = listener.getInstance();
+                if (inst != null) {
+                    inst.onDataTreeChanged(Collections.singletonList(notification));
                 }
             };
     private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMStoreTreeChangePublisher.class);
@@ -46,6 +43,11 @@ final class InMemoryDOMStoreTreeChangePublisher extends AbstractDOMStoreTreeChan
         notificationManager = new QueuedNotificationManager<>(listenerExecutor, MANAGER_INVOKER, maxQueueSize, "DataTreeChangeListenerQueueMgr");
     }
 
+    private InMemoryDOMStoreTreeChangePublisher(QueuedNotificationManager<
+            AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate> notificationManager) {
+        this.notificationManager = notificationManager;
+    }
+
     @Override
     protected void notifyListeners(final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> registrations, final YangInstanceIdentifier path, final DataTreeCandidateNode node) {
         final DataTreeCandidate candidate = DataTreeCandidates.newDataTreeCandidate(path, node);
@@ -66,10 +68,15 @@ final class InMemoryDOMStoreTreeChangePublisher extends AbstractDOMStoreTreeChan
     <L extends DOMDataTreeChangeListener> ListenerRegistration<L> registerTreeChangeListener(final YangInstanceIdentifier treeId, final L listener, final DataTreeSnapshot snapshot) {
         final AbstractDOMDataTreeChangeListenerRegistration<L> reg = registerTreeChangeListener(treeId, listener);
 
-        final Optional<NormalizedNode<?, ?>> node = snapshot.readNode(treeId);
+        final Optional<NormalizedNode<?, ?>> 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;