Remove AbstractRegistrationTree 12/69812/3
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 22 Mar 2018 12:34:56 +0000 (13:34 +0100)
committerTom Pantelis <tompantelis@gmail.com>
Thu, 22 Mar 2018 16:23:46 +0000 (16:23 +0000)
This class has been deprecated in favor of the MDSAL version,
remove it.

Change-Id: I28af7908969d7969f864a4e04d454270f948a807
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/md/sal/dom/spi/AbstractRegistrationTree.java [deleted file]
opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/md/sal/dom/spi/RegistrationTreeNode.java [deleted file]
opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/md/sal/dom/spi/RegistrationTreeSnapshot.java [deleted file]
opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ListenerNode.java
opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ListenerWalker.java

diff --git a/opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/md/sal/dom/spi/AbstractRegistrationTree.java b/opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/md/sal/dom/spi/AbstractRegistrationTree.java
deleted file mode 100644 (file)
index 61e8e3a..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/**
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.md.sal.dom.spi;
-
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-
-/**
- * An abstract tree of registrations. Allows a read-only snapshot to be taken.
- *
- * @param <T> Type of registered object
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.spi.AbstractRegistrationTree} instead.
- */
-@Deprecated
-public abstract class AbstractRegistrationTree<T> {
-    private final ReadWriteLock rwLock = new ReentrantReadWriteLock(true);
-    private final RegistrationTreeNode<T> rootNode = new RegistrationTreeNode<>(null, null);
-
-    protected AbstractRegistrationTree() {
-
-    }
-
-    /**
-     * Acquire the read-write lock. This should be done before invoking {@link #findNodeFor(Iterable)}.
-     */
-    protected final void takeLock() {
-        rwLock.writeLock().lock();
-    }
-
-    /**
-     * Release the read-write lock. This should be done after invocation of {@link #findNodeFor(Iterable)}
-     * and modification of the returned node. Note that callers should do so in a finally block.
-     */
-    protected final void releaseLock() {
-        rwLock.writeLock().unlock();
-    }
-
-    /**
-     * Find an existing, or allocate a fresh, node for a particular path. Must be called with the
-     * read-write lock held.
-     *
-     * @param path Path to find a node for
-     * @return A registration node for the specified path
-     */
-    @Nonnull protected final RegistrationTreeNode<T> findNodeFor(@Nonnull final Iterable<PathArgument> path) {
-        RegistrationTreeNode<T> walkNode = rootNode;
-        for (final PathArgument arg : path) {
-            walkNode = walkNode.ensureChild(arg);
-        }
-
-        return walkNode;
-    }
-
-    /**
-     * Add a registration to a particular node. The node must have been returned via {@link #findNodeFor(Iterable)}
-     * and the lock must still be held.
-     *
-     * @param node Tree node
-     * @param registration Registration instance
-     */
-    protected final void addRegistration(@Nonnull final RegistrationTreeNode<T> node, @Nonnull final T registration) {
-        node.addRegistration(registration);
-    }
-
-    /**
-     * Remove a registration from a particular node. This method must not be called while the read-write lock
-     * is held.
-     *
-     * @param node Tree node
-     * @param registration Registration instance
-     */
-    protected final void removeRegistration(@Nonnull final RegistrationTreeNode<T> node,
-            @Nonnull final T registration) {
-        // Take the write lock
-        rwLock.writeLock().lock();
-        try {
-            node.removeRegistration(registration);
-        } finally {
-            // Always release the lock
-            rwLock.writeLock().unlock();
-        }
-    }
-
-    /**
-     * Obtain a tree snapshot. This snapshot ensures a consistent view of
-     * registrations. The snapshot should be closed as soon as it is not required,
-     * because each unclosed instance blocks modification of this tree.
-     *
-     * @return A snapshot instance.
-     */
-    @Nonnull public final RegistrationTreeSnapshot<T> takeSnapshot() {
-        final RegistrationTreeSnapshot<T> ret = new RegistrationTreeSnapshot<>(rwLock.readLock(), rootNode);
-        rwLock.readLock().lock();
-        return ret;
-    }
-}
diff --git a/opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/md/sal/dom/spi/RegistrationTreeNode.java b/opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/md/sal/dom/spi/RegistrationTreeNode.java
deleted file mode 100644 (file)
index 178bbe2..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/**
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.md.sal.dom.spi;
-
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Preconditions;
-import java.lang.ref.Reference;
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.concepts.Identifiable;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This is a single node within the registration tree. Note that the data returned from
- * and instance of this class is guaranteed to have any relevance or consistency
- * only as long as the {@link RegistrationTreeSnapshot} instance through which it is reached
- * remains unclosed.
- *
- * @param <T> registration type
- * @author Robert Varga
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.spi.RegistrationTreeNode} instead.
- */
-@Deprecated
-public final class RegistrationTreeNode<T> implements Identifiable<PathArgument> {
-    private static final Logger LOG = LoggerFactory.getLogger(RegistrationTreeNode.class);
-
-    private final Map<PathArgument, RegistrationTreeNode<T>> children = new HashMap<>();
-    private final Collection<T> registrations = new ArrayList<>(2);
-    private final Collection<T> publicRegistrations = Collections.unmodifiableCollection(registrations);
-    private final Reference<RegistrationTreeNode<T>> parent;
-    private final PathArgument identifier;
-
-    RegistrationTreeNode(final RegistrationTreeNode<T> parent, final PathArgument identifier) {
-        this.parent = new WeakReference<>(parent);
-        this.identifier = identifier;
-    }
-
-    @Override
-    public PathArgument getIdentifier() {
-        return identifier;
-    }
-
-    /**
-     * Return the child matching a {@link PathArgument} specification.
-     *
-     * @param arg Child identifier
-     * @return Child matching exactly, or null.
-     */
-    public RegistrationTreeNode<T> getExactChild(@Nonnull final PathArgument arg) {
-        return children.get(Preconditions.checkNotNull(arg));
-    }
-
-    /**
-     * Return a collection children which match a {@link PathArgument} specification inexactly.
-     * This explicitly excludes the child returned by {@link #getExactChild(PathArgument)}.
-     *
-     * @param arg Child identifier
-     * @return Collection of children, guaranteed to be non-null.
-     */
-    public @Nonnull Collection<RegistrationTreeNode<T>> getInexactChildren(@Nonnull final PathArgument arg) {
-        Preconditions.checkNotNull(arg);
-        if (arg instanceof NodeWithValue || arg instanceof NodeIdentifierWithPredicates) {
-            /*
-             * TODO: This just all-or-nothing wildcards, which we have historically supported. Given
-             *       that the argument is supposed to have all the elements filled out, we could support
-             *       partial wildcards by iterating over the registrations and matching the maps for
-             *       partial matches.
-             */
-            final RegistrationTreeNode<T> child = children.get(new NodeIdentifier(arg.getNodeType()));
-            if (child == null) {
-                return Collections.emptyList();
-            } else {
-                return Collections.singletonList(child);
-            }
-        } else {
-            return Collections.emptyList();
-        }
-    }
-
-    public Collection<T> getRegistrations() {
-        return publicRegistrations;
-    }
-
-    RegistrationTreeNode<T> ensureChild(@Nonnull final PathArgument child) {
-        RegistrationTreeNode<T> potential = children.get(Preconditions.checkNotNull(child));
-        if (potential == null) {
-            potential = new RegistrationTreeNode<>(this, child);
-            children.put(child, potential);
-        }
-        return potential;
-    }
-
-    void addRegistration(@Nonnull final T registration) {
-        registrations.add(Preconditions.checkNotNull(registration));
-        LOG.debug("Registration {} added", registration);
-    }
-
-    void removeRegistration(@Nonnull final T registration) {
-        registrations.remove(Preconditions.checkNotNull(registration));
-        LOG.debug("Registration {} removed", registration);
-
-        // We have been called with the write-lock held, so we can perform some cleanup.
-        removeThisIfUnused();
-    }
-
-    private void removeThisIfUnused() {
-        final RegistrationTreeNode<T> p = parent.get();
-        if (p != null && registrations.isEmpty() && children.isEmpty()) {
-            p.removeChild(identifier);
-        }
-    }
-
-    private void removeChild(final PathArgument arg) {
-        children.remove(arg);
-        removeThisIfUnused();
-    }
-
-    @Override
-    public String toString() {
-        return MoreObjects.toStringHelper(this)
-                .add("identifier", identifier)
-                .add("registrations", registrations.size())
-                .add("children", children.size()).toString();
-    }
-}
diff --git a/opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/md/sal/dom/spi/RegistrationTreeSnapshot.java b/opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/md/sal/dom/spi/RegistrationTreeSnapshot.java
deleted file mode 100644 (file)
index d3cbdad..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.md.sal.dom.spi;
-
-import com.google.common.base.Preconditions;
-import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
-import java.util.concurrent.locks.Lock;
-
-/**
- * A stable read-only snapshot of a {@link AbstractRegistrationTree}.
- *
- * @author Robert Varga
- *
- * @deprecated Use {@link org.opendaylight.mdsal.dom.spi.RegistrationTreeSnapshot} instead.
- */
-@Deprecated
-public final class RegistrationTreeSnapshot<T> implements AutoCloseable {
-    @SuppressWarnings("rawtypes")
-    private static final AtomicIntegerFieldUpdater<RegistrationTreeSnapshot> CLOSED_UPDATER =
-            AtomicIntegerFieldUpdater.newUpdater(RegistrationTreeSnapshot.class, "closed");
-    private final RegistrationTreeNode<T> node;
-    private final Lock lock;
-
-    // Used via CLOSED_UPDATER
-    @SuppressWarnings("unused")
-    private volatile int closed = 0;
-
-    RegistrationTreeSnapshot(final Lock lock, final RegistrationTreeNode<T> node) {
-        this.lock = Preconditions.checkNotNull(lock);
-        this.node = Preconditions.checkNotNull(node);
-    }
-
-    public RegistrationTreeNode<T> getRootNode() {
-        return node;
-    }
-
-    @Override
-    public void close() {
-        if (CLOSED_UPDATER.compareAndSet(this, 0, 1)) {
-            lock.unlock();
-        }
-    }
-}
index 00be7d68b78effab5aa79e07c2bee6873d4b0ed2..fd16117cde7d139e02fa03ab88cfd3c9aec29661 100644 (file)
@@ -10,8 +10,8 @@ package org.opendaylight.controller.md.sal.dom.store.impl.tree;
 import com.google.common.base.Preconditions;
 import java.util.Collection;
 import java.util.Optional;
 import com.google.common.base.Preconditions;
 import java.util.Collection;
 import java.util.Optional;
-import org.opendaylight.controller.md.sal.dom.spi.RegistrationTreeNode;
 import org.opendaylight.controller.md.sal.dom.store.impl.DataChangeListenerRegistration;
 import org.opendaylight.controller.md.sal.dom.store.impl.DataChangeListenerRegistration;
+import org.opendaylight.mdsal.dom.spi.RegistrationTreeNode;
 import org.opendaylight.yangtools.concepts.Identifiable;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNode;
 import org.opendaylight.yangtools.concepts.Identifiable;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNode;
index f8169c4e48c0508228084ad414d7924fccd6abcc..7b8add90379010bdeeb03a860524e8f89d92e497 100644 (file)
@@ -8,8 +8,8 @@
 package org.opendaylight.controller.md.sal.dom.store.impl.tree;
 
 import com.google.common.base.Preconditions;
 package org.opendaylight.controller.md.sal.dom.store.impl.tree;
 
 import com.google.common.base.Preconditions;
-import org.opendaylight.controller.md.sal.dom.spi.RegistrationTreeSnapshot;
 import org.opendaylight.controller.md.sal.dom.store.impl.DataChangeListenerRegistration;
 import org.opendaylight.controller.md.sal.dom.store.impl.DataChangeListenerRegistration;
+import org.opendaylight.mdsal.dom.spi.RegistrationTreeSnapshot;
 
 /**
  * A walking context, pretty much equivalent to an iterator, but it
 
 /**
  * A walking context, pretty much equivalent to an iterator, but it