X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fstore%2Fimpl%2Ftree%2FListenerTree.java;h=f93f40a9cc1f5b9bd85e00543be0497fde16d4de;hp=58a0c69bb06a94e59d97f9dc88aee0ea71cef4ca;hb=7206d41640f98943c64da8f8486e5205b279c943;hpb=4312c58d37c9e1ad27d6cf228eda0ba3f7501a0c diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ListenerTree.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ListenerTree.java index 58a0c69bb0..f93f40a9cc 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ListenerTree.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ListenerTree.java @@ -9,9 +9,9 @@ package org.opendaylight.controller.md.sal.dom.store.impl.tree; import java.lang.ref.Reference; import java.lang.ref.WeakReference; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; @@ -21,6 +21,7 @@ import javax.annotation.concurrent.GuardedBy; 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.yangtools.concepts.Identifiable; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; @@ -61,12 +62,12 @@ public final class ListenerTree { try { Node walkNode = rootNode; - for(PathArgument arg : path.getPath()) { + for (final PathArgument arg : path.getPath()) { walkNode = walkNode.ensureChild(arg); } final Node node = walkNode; - DataChangeListenerRegistration listenerReg = new DataChangeListenerRegistration(listener) { + DataChangeListenerRegistration reg = new DataChangeListenerRegistrationImpl(listener) { @Override public DataChangeScope getScope() { return scope; @@ -101,8 +102,8 @@ public final class ListenerTree { } }; - node.addListener(listenerReg); - return listenerReg; + node.addListener(reg); + return reg; } finally { // Always release the lock rwLock.writeLock().unlock(); @@ -155,7 +156,7 @@ public final class ListenerTree { * unclosed. */ public static final class Node implements StoreTreeNode, Identifiable { - private final HashSet> listeners = new HashSet<>(); + private final Collection> listeners = new ArrayList<>(); private final Map children = new HashMap<>(); private final PathArgument identifier; private final Reference parent; @@ -182,13 +183,12 @@ public final class ListenerTree { * * @return the list of current listeners */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - public Collection> getListeners() { - return (Collection) listeners; + public Collection> getListeners() { + return listeners; } private Node ensureChild(final PathArgument child) { - Node potential = (children.get(child)); + Node potential = children.get(child); if (potential == null) { potential = new Node(this, child); children.put(child, potential); @@ -201,7 +201,7 @@ public final class ListenerTree { LOG.debug("Listener {} registered", listener); } - private void removeListener(final DataChangeListenerRegistration listener) { + private void removeListener(final DataChangeListenerRegistrationImpl listener) { listeners.remove(listener); LOG.debug("Listener {} unregistered", listener); @@ -220,14 +220,19 @@ public final class ListenerTree { children.remove(arg); removeThisIfUnused(); } - } - private abstract static class DataChangeListenerRegistration>> extends AbstractListenerRegistration implements - org.opendaylight.controller.md.sal.dom.store.impl.DataChangeListenerRegistration { + @Override + public String toString() { + return "Node [identifier=" + identifier + ", listeners=" + listeners.size() + ", children=" + children.size() + "]"; + } + - public DataChangeListenerRegistration(final T listener) { + } + + private abstract static class DataChangeListenerRegistrationImpl>> extends AbstractListenerRegistration // + implements DataChangeListenerRegistration { + public DataChangeListenerRegistrationImpl(final T listener) { super(listener); } } - }