As it turns out, we do not need a Set<>, but rather a collection. We do
not expect major modifications of listeners, but memory efficiency and
iteration speed are required. Thus turn the HashSet into an ArrayList.
Also rename DataChangeListenerRegistration to
DataChangeListenerRegistrationImpl, so that the interface itself can be
imported and used as a shortname. This has the nice effect of rendering
a nasty SuppressWarnings completely unneeded.
Change-Id: I100337651c3b42c715978708bc98cf24ce5bf703
Signed-off-by: Robert Varga <rovarga@cisco.com>
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
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.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;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
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.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;
import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
import org.opendaylight.yangtools.concepts.Identifiable;
import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
try {
Node walkNode = rootNode;
try {
Node walkNode = rootNode;
- for(PathArgument arg : path.getPath()) {
+ for (final PathArgument arg : path.getPath()) {
walkNode = walkNode.ensureChild(arg);
}
final Node node = walkNode;
walkNode = walkNode.ensureChild(arg);
}
final Node node = walkNode;
- DataChangeListenerRegistration<L> listenerReg = new DataChangeListenerRegistration<L>(listener) {
+ DataChangeListenerRegistration<L> reg = new DataChangeListenerRegistrationImpl<L>(listener) {
@Override
public DataChangeScope getScope() {
return scope;
@Override
public DataChangeScope getScope() {
return scope;
- node.addListener(listenerReg);
- return listenerReg;
+ node.addListener(reg);
+ return reg;
} finally {
// Always release the lock
rwLock.writeLock().unlock();
} finally {
// Always release the lock
rwLock.writeLock().unlock();
* unclosed.
*/
public static final class Node implements StoreTreeNode<Node>, Identifiable<PathArgument> {
* unclosed.
*/
public static final class Node implements StoreTreeNode<Node>, Identifiable<PathArgument> {
- private final HashSet<DataChangeListenerRegistration<?>> listeners = new HashSet<>();
+ private final Collection<DataChangeListenerRegistration<?>> listeners = new ArrayList<>();
private final Map<PathArgument, Node> children = new HashMap<>();
private final PathArgument identifier;
private final Reference<Node> parent;
private final Map<PathArgument, Node> children = new HashMap<>();
private final PathArgument identifier;
private final Reference<Node> parent;
*
* @return the list of current listeners
*/
*
* @return the list of current listeners
*/
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public Collection<org.opendaylight.controller.md.sal.dom.store.impl.DataChangeListenerRegistration<?>> getListeners() {
- return (Collection) listeners;
+ public Collection<DataChangeListenerRegistration<?>> getListeners() {
+ return listeners;
}
private Node ensureChild(final PathArgument child) {
}
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);
if (potential == null) {
potential = new Node(this, child);
children.put(child, potential);
LOG.debug("Listener {} registered", listener);
}
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);
listeners.remove(listener);
LOG.debug("Listener {} unregistered", listener);
- private abstract static class DataChangeListenerRegistration<T extends AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>>> extends AbstractListenerRegistration<T> implements
- org.opendaylight.controller.md.sal.dom.store.impl.DataChangeListenerRegistration<T> {
-
- public DataChangeListenerRegistration(final T listener) {
+ private abstract static class DataChangeListenerRegistrationImpl<T extends AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>>> extends AbstractListenerRegistration<T> //
+ implements DataChangeListenerRegistration<T> {
+ public DataChangeListenerRegistrationImpl(final T listener) {