X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fstore%2Fimpl%2FInMemoryDOMDataStore.java;h=a854c4806b4a61f8f3d52716e23f978503465a16;hb=fc2ff81f096e61194c0538452bb6ed1b2894159a;hp=788bc68f03716f3a98ebb5282f38afefb115dd33;hpb=db19853c7b8a5396cc0b9474bb197f5a678f9e64;p=controller.git diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java index 788bc68f03..a854c4806b 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java @@ -18,8 +18,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.ListenerRegistrationNode; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.ListenerRegistrationNode.DataChangeListenerRegistration; +import org.opendaylight.controller.md.sal.dom.store.impl.tree.ListenerTree; import org.opendaylight.controller.md.sal.dom.store.impl.tree.ModificationType; import org.opendaylight.controller.md.sal.dom.store.impl.tree.NodeModification; import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreMetadataNode; @@ -29,6 +28,7 @@ import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransactio import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransaction; import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction; +import org.opendaylight.yangtools.concepts.AbstractListenerRegistration; import org.opendaylight.yangtools.concepts.Identifiable; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; @@ -58,7 +58,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch private final ListeningExecutorService executor; private final String name; private final AtomicLong txCounter = new AtomicLong(0); - private final ListenerRegistrationNode listenerTree; + private final ListenerTree listenerTree; private final AtomicReference snapshot; private ModificationApplyOperation operationTree; @@ -68,7 +68,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch public InMemoryDOMDataStore(final String name, final ListeningExecutorService executor) { this.name = Preconditions.checkNotNull(name); this.executor = Preconditions.checkNotNull(executor); - this.listenerTree = ListenerRegistrationNode.createRoot(); + this.listenerTree = ListenerTree.create(); this.snapshot = new AtomicReference(DataAndMetadataSnapshot.createEmpty()); this.operationTree = new AlwaysFailOperation(); } @@ -102,11 +102,6 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch @Override public >> ListenerRegistration registerChangeListener( final InstanceIdentifier path, final L listener, final DataChangeScope scope) { - LOG.debug("{}: Registering data change listener {} for {}",name,listener,path); - ListenerRegistrationNode listenerNode = listenerTree; - for(PathArgument arg : path.getPath()) { - listenerNode = listenerNode.ensureChild(arg); - } /* * Make sure commit is not occurring right now. Listener has to be registered and its @@ -117,7 +112,9 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch */ final DataChangeListenerRegistration reg; synchronized (this) { - reg = listenerNode.registerDataChangeListener(path, listener, scope); + LOG.debug("{}: Registering data change listener {} for {}",name,listener,path); + + reg = listenerTree.registerDataChangeListener(path, listener, scope); Optional currentState = snapshot.get().read(path); if (currentState.isPresent()) { @@ -131,7 +128,14 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch } } - return reg; + return new AbstractListenerRegistration(listener) { + @Override + protected void removeRegistration() { + synchronized (InMemoryDOMDataStore.this) { + reg.close(); + } + } + }; } private synchronized DOMStoreThreePhaseCommitCohort submit( @@ -145,7 +149,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch } private void commit(final DataAndMetadataSnapshot currentSnapshot, - final StoreMetadataNode newDataTree, final Iterable listenerTasks) { + final StoreMetadataNode newDataTree, final DataChangeEventResolver listenerResolver) { LOG.debug("Updating Store snaphot version: {} with version:{}",currentSnapshot.getMetadataTree().getSubtreeVersion(),newDataTree.getSubtreeVersion()); if(LOG.isTraceEnabled()) { @@ -164,7 +168,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch final boolean success = snapshot.compareAndSet(currentSnapshot, newSnapshot); checkState(success, "Store snapshot and transaction snapshot differ. This should never happen."); - for (ChangeListenerNotifyTask task : listenerTasks) { + for (ChangeListenerNotifyTask task : listenerResolver.resolve()) { executor.submit(task); } } @@ -302,7 +306,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch private DataAndMetadataSnapshot storeSnapshot; private Optional proposedSubtree; - private Iterable listenerTasks; + private DataChangeEventResolver listenerResolver; public ThreePhaseCommitImpl(final SnaphostBackedWriteTransaction writeTransaction) { this.transaction = writeTransaction; @@ -343,13 +347,12 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch proposedSubtree = operationTree.apply(modification, Optional.of(metadataTree), increase(metadataTree.getSubtreeVersion())); - listenerTasks = DataChangeEventResolver.create() // + listenerResolver = DataChangeEventResolver.create() // .setRootPath(PUBLIC_ROOT_PATH) // .setBeforeRoot(Optional.of(metadataTree)) // .setAfterRoot(proposedSubtree) // .setModificationRoot(modification) // - .setListenerRoot(listenerTree) // - .resolve(); + .setListenerRoot(listenerTree); return null; } @@ -372,7 +375,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch checkState(proposedSubtree != null,"Proposed subtree must be computed"); checkState(storeSnapshot != null,"Proposed subtree must be computed"); // return ImmediateFuture<>; - InMemoryDOMDataStore.this.commit(storeSnapshot, proposedSubtree.get(),listenerTasks); + InMemoryDOMDataStore.this.commit(storeSnapshot, proposedSubtree.get(),listenerResolver); return Futures. immediateFuture(null); }