Use EqualityQueuedNotificationManager 50/86350/5
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 11 Dec 2019 11:26:26 +0000 (12:26 +0100)
committerRobert Varga <nite@hq.sk>
Thu, 23 Jan 2020 13:34:40 +0000 (13:34 +0000)
Since we are using Registrations as the key into notification
manager, there is no point it the manager using identity wrappers
-- registrations already perform that role.

Clean things up by using EqualityQueuedNotificationManager.

JIRA: MDSAL-514
Change-Id: Ief05a302169d205ed167e7fb88418910d029f9dc
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStore.java
dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreTreeChangePublisher.java

index 118bcdbd81d1cd369377434eb10d646a7753eea0..f8f10522da0db0ee259d48d272b3bce4f30e95f5 100644 (file)
@@ -27,7 +27,7 @@ import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction.Trans
 import org.opendaylight.yangtools.concepts.Identifiable;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.util.ExecutorServiceUtil;
-import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
+import org.opendaylight.yangtools.util.concurrent.EqualityQueuedNotificationManager;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
@@ -89,11 +89,11 @@ public class InMemoryDOMDataStore extends TransactionReadyPrototype<String> impl
         this.dataChangeListenerExecutor = requireNonNull(dataChangeListenerExecutor);
         this.debugTransactions = debugTransactions;
         dataTree = new InMemoryDataTreeFactory().create(config);
-        changePublisher = new InMemoryDOMStoreTreeChangePublisher(this.dataChangeListenerExecutor,
+        changePublisher = new InMemoryDOMStoreTreeChangePublisher("name", this.dataChangeListenerExecutor,
                 maxDataChangeListenerQueueSize);
     }
 
-    public QueuedNotificationManager<?, ?> getDataChangeListenerNotificationManager() {
+    public EqualityQueuedNotificationManager<?, ?> getDataChangeListenerNotificationManager() {
         return changePublisher.getNotificationManager();
     }
 
index ac355ed3e2dee979a49450b893f7351634d29f4d..cbeaa1336256e1d2944c2481fa3b45c85499e9e1 100644 (file)
@@ -17,7 +17,7 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
 import org.opendaylight.mdsal.dom.spi.AbstractDOMDataTreeChangeListenerRegistration;
 import org.opendaylight.mdsal.dom.spi.store.AbstractDOMStoreTreeChangePublisher;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager;
+import org.opendaylight.yangtools.util.concurrent.EqualityQueuedNotificationManager;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -30,23 +30,27 @@ import org.slf4j.LoggerFactory;
 final class InMemoryDOMStoreTreeChangePublisher extends AbstractDOMStoreTreeChangePublisher {
     private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMStoreTreeChangePublisher.class);
 
-    private final QueuedNotificationManager<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
+    // Registrations use identity for equality, hence we can skip wrapping them
+    private final EqualityQueuedNotificationManager<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate>
         notificationManager;
 
-    InMemoryDOMStoreTreeChangePublisher(final ExecutorService listenerExecutor, final int maxQueueSize) {
-        notificationManager = QueuedNotificationManager.create(listenerExecutor, (listener, notifications) -> {
-            if (!listener.isClosed()) {
-                listener.getInstance().onDataTreeChanged(notifications);
-            }
-        }, maxQueueSize, "DataTreeChangeListenerQueueMgr");
+    InMemoryDOMStoreTreeChangePublisher(final String dsName, final ExecutorService listenerExecutor,
+            final int maxQueueSize) {
+        notificationManager = new EqualityQueuedNotificationManager<>("DataTreeChangeListenerQueueMgr + dsName",
+            listenerExecutor, maxQueueSize,
+            (listener, notifications) -> {
+                if (!listener.isClosed()) {
+                    listener.getInstance().onDataTreeChanged(notifications);
+                }
+            });
     }
 
-    private InMemoryDOMStoreTreeChangePublisher(final QueuedNotificationManager<
+    private InMemoryDOMStoreTreeChangePublisher(final EqualityQueuedNotificationManager<
             AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate> notificationManager) {
         this.notificationManager = notificationManager;
     }
 
-    QueuedNotificationManager<?, ?> getNotificationManager() {
+    EqualityQueuedNotificationManager<?, ?> getNotificationManager() {
         return notificationManager;
     }