*/
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.spi.AbstractRegistrationTree;
+import org.opendaylight.controller.md.sal.dom.spi.RegistrationTreeNode;
import org.opendaylight.controller.md.sal.dom.store.impl.DataChangeListenerRegistration;
-import org.opendaylight.yangtools.concepts.AbstractListenerRegistration;
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
*
* @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<DataChangeListenerRegistration<?>> {
private ListenerTree() {
// Private to disallow direct instantiation
}
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<DataChangeListenerRegistration<?>> node = findNodeFor(path.getPathArguments());
DataChangeListenerRegistration<L> reg = new DataChangeListenerRegistrationImpl<L>(listener) {
@Override
public DataChangeScope getScope() {
* 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();
+ releaseLock();
}
}
* the listener tree.
*
* @return A walker instance.
+ *
+ * @deprecated Use {@link #takeSnapshot()} instead.
*/
+ @Deprecated
public ListenerWalker getWalker() {
/*
* TODO: The only current user of this method is local to the datastore.
* 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<T extends AsyncDataChangeListener<YangInstanceIdentifier, NormalizedNode<?, ?>>> extends AbstractListenerRegistration<T> //
- implements DataChangeListenerRegistration<T> {
- public DataChangeListenerRegistrationImpl(final T listener) {
- super(listener);
- }
+ return new ListenerWalker(takeSnapshot());
}
}