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%2Ftree%2FListenerTree.java;h=da3e3b40bf9267fdd2d3fc37d89f97cac3eb8c60;hp=dcff6439d6608b67aea81cab5882b1d72846d2c8;hb=e301ed83b10c2665cda02ffd06153e1565a2bb39;hpb=08351c185b20967cf3de414b16e97670149f5d51 diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ListenerTree.java b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ListenerTree.java index dcff6439d6..da3e3b40bf 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ListenerTree.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ListenerTree.java @@ -7,18 +7,13 @@ */ package org.opendaylight.controller.md.sal.dom.store.impl.tree; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - 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.DataChangeListenerRegistration; -import org.opendaylight.yangtools.concepts.AbstractListenerRegistration; +import org.opendaylight.mdsal.dom.spi.AbstractRegistrationTree; +import org.opendaylight.mdsal.dom.spi.RegistrationTreeNode; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * A set of listeners organized as a tree by node to which they listen. This class @@ -26,11 +21,7 @@ import org.slf4j.LoggerFactory; * * @author Robert Varga */ -public final class ListenerTree { - private static final Logger LOG = LoggerFactory.getLogger(ListenerTree.class); - private final ReadWriteLock rwLock = new ReentrantReadWriteLock(true); - private final ListenerNode rootNode = new ListenerNode(null, null); - +public final class ListenerTree extends AbstractRegistrationTree> { private ListenerTree() { // Private to disallow direct instantiation } @@ -56,15 +47,9 @@ public final class ListenerTree { final L listener, final DataChangeScope scope) { // Take the write lock - rwLock.writeLock().lock(); - + takeLock(); try { - ListenerNode walkNode = rootNode; - for (final PathArgument arg : path.getPathArguments()) { - walkNode = walkNode.ensureChild(arg); - } - - final ListenerNode node = walkNode; + final RegistrationTreeNode> node = findNodeFor(path.getPathArguments()); DataChangeListenerRegistration reg = new DataChangeListenerRegistrationImpl(listener) { @Override public DataChangeScope getScope() { @@ -88,52 +73,15 @@ public final class ListenerTree { * While this does not directly violate the ListenerRegistration * contract, it is probably not going to be liked by the users. */ - - // Take the write lock - ListenerTree.this.rwLock.writeLock().lock(); - try { - node.removeListener(this); - } finally { - // Always release the lock - ListenerTree.this.rwLock.writeLock().unlock(); - } + ListenerTree.this.removeRegistration(node, this); } }; - node.addListener(reg); + addRegistration(node, reg); return reg; } finally { // Always release the lock - rwLock.writeLock().unlock(); - } - } - - /** - * Obtain a tree walking context. This context ensures a consistent view of - * the listener registrations. The context should be closed as soon as it - * is not required, because each unclosed instance blocks modification of - * the listener tree. - * - * @return A walker instance. - */ - public ListenerWalker getWalker() { - /* - * TODO: The only current user of this method is local to the datastore. - * Since this class represents a read-lock, losing a reference to - * it is a _major_ problem, as the registration process will get - * wedged, eventually grinding the system to a halt. Should an - * external user exist, make the Walker a phantom reference, which - * will cleanup the lock if not told to do so. - */ - final ListenerWalker ret = new ListenerWalker(rwLock.readLock(), rootNode); - rwLock.readLock().lock(); - return ret; - } - - abstract static class DataChangeListenerRegistrationImpl>> extends AbstractListenerRegistration // - implements DataChangeListenerRegistration { - public DataChangeListenerRegistrationImpl(final T listener) { - super(listener); + releaseLock(); } } }