From a342c80142df67837019ad7f6fc74f91780eb580 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 11 Dec 2019 12:26:26 +0100 Subject: [PATCH] Use EqualityQueuedNotificationManager 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 --- .../store/inmemory/InMemoryDOMDataStore.java | 6 ++--- .../InMemoryDOMStoreTreeChangePublisher.java | 24 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStore.java b/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStore.java index 118bcdbd81..f8f10522da 100644 --- a/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStore.java +++ b/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMDataStore.java @@ -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 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(); } diff --git a/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreTreeChangePublisher.java b/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreTreeChangePublisher.java index ac355ed3e2..cbeaa13362 100644 --- a/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreTreeChangePublisher.java +++ b/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreTreeChangePublisher.java @@ -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, DataTreeCandidate> + // Registrations use identity for equality, hence we can skip wrapping them + private final EqualityQueuedNotificationManager, 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; } -- 2.36.6