@Override public final <L extends DOMDataTreeChangeListener> AbstractDOMDataTreeChangeListenerRegistration<L> registerTreeChangeListener(final YangInstanceIdentifier treeId, final L listener) { // Take the write lock takeLock(); try { final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> node = findNodeFor(treeId.getPathArguments()); final AbstractDOMDataTreeChangeListenerRegistration<L> reg = new AbstractDOMDataTreeChangeListenerRegistration<L>(listener) { @Override protected void removeRegistration() { AbstractDOMStoreTreeChangePublisher.this.removeRegistration(node, this); registrationRemoved(this); } }; addRegistration(node, reg); return reg; } finally { // Always release the lock releaseLock(); } }
@Override protected void removeRegistration() { AbstractDOMStoreTreeChangePublisher.this.removeRegistration(node, this); registrationRemoved(this); } };
private void lookupAndNotify(final List<PathArgument> args, final int offset, final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> node, final DataTreeCandidate candidate) { if (args.size() != offset) { final PathArgument arg = args.get(offset); final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> exactChild = node.getExactChild(arg); if (exactChild != null) { lookupAndNotify(args, offset + 1, exactChild, candidate); } for (RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> c : node.getInexactChildren(arg)) { lookupAndNotify(args, offset + 1, c, candidate); } } else { notifyNode(candidate.getRootPath(), node, candidate.getRootNode()); } }
/** * Process a candidate tree with respect to registered listeners. * * @param candidate candidate three which needs to be processed */ protected final void processCandidateTree(@Nonnull final DataTreeCandidate candidate) { final DataTreeCandidateNode node = candidate.getRootNode(); if (node.getModificationType() == ModificationType.UNMODIFIED) { LOG.debug("Skipping unmodified candidate {}", candidate); return; } try (final RegistrationTreeSnapshot<AbstractDOMDataTreeChangeListenerRegistration<?>> snapshot = takeSnapshot()) { final List<PathArgument> toLookup = ImmutableList.copyOf(candidate.getRootPath().getPathArguments()); lookupAndNotify(toLookup, 0, snapshot.getRootNode(), candidate); } }
private void notifyNode(final YangInstanceIdentifier path, final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> regNode, final DataTreeCandidateNode candNode) { if (candNode.getModificationType() == ModificationType.UNMODIFIED) { LOG.debug("Skipping unmodified candidate {}", path); return; } final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> regs = regNode.getRegistrations(); if (!regs.isEmpty()) { notifyListeners(regs, path, candNode); } for (DataTreeCandidateNode candChild : candNode.getChildNodes()) { if (candChild.getModificationType() != ModificationType.UNMODIFIED) { final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> regChild = regNode.getExactChild(candChild.getIdentifier()); if (regChild != null) { notifyNode(path.node(candChild.getIdentifier()), regChild, candChild); } for (RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> rc : regNode.getInexactChildren(candChild.getIdentifier())) { notifyNode(path.node(candChild.getIdentifier()), rc, candChild); } } } } }
private void lookupAndNotify(final List<PathArgument> args, final int offset, final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> node, final DataTreeCandidate candidate) { if (args.size() != offset) { final PathArgument arg = args.get(offset); final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> exactChild = node.getExactChild(arg); if (exactChild != null) { lookupAndNotify(args, offset + 1, exactChild, candidate); } for (RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> c : node.getInexactChildren(arg)) { lookupAndNotify(args, offset + 1, c, candidate); } } else { notifyNode(candidate.getRootPath(), node, candidate.getRootNode()); } }
/** * Process a candidate tree with respect to registered listeners. * * @param candidate candidate three which needs to be processed */ protected final void processCandidateTree(@Nonnull final DataTreeCandidate candidate) { final DataTreeCandidateNode node = candidate.getRootNode(); if (node.getModificationType() == ModificationType.UNMODIFIED) { LOG.debug("Skipping unmodified candidate {}", candidate); return; } try (RegistrationTreeSnapshot<AbstractDOMDataTreeChangeListenerRegistration<?>> snapshot = takeSnapshot()) { lookupAndNotify(candidate.getRootPath().getPathArguments(), 0, snapshot.getRootNode(), candidate); } }
private void notifyNode(final YangInstanceIdentifier path, final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> regNode, final DataTreeCandidateNode candNode) { if (candNode.getModificationType() == ModificationType.UNMODIFIED) { LOG.debug("Skipping unmodified candidate {}", path); return; } final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> regs = regNode.getRegistrations(); if (!regs.isEmpty()) { notifyListeners(regs, path, candNode); } for (DataTreeCandidateNode candChild : candNode.getChildNodes()) { if (candChild.getModificationType() != ModificationType.UNMODIFIED) { final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> regChild = regNode.getExactChild(candChild.getIdentifier()); if (regChild != null) { notifyNode(path.node(candChild.getIdentifier()), regChild, candChild); } for (RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> rc : regNode.getInexactChildren(candChild.getIdentifier())) { notifyNode(path.node(candChild.getIdentifier()), rc, candChild); } } } } }
@Override public final <L extends DOMDataTreeChangeListener> AbstractDOMDataTreeChangeListenerRegistration<L> registerTreeChangeListener(final YangInstanceIdentifier treeId, final L listener) { // Take the write lock takeLock(); try { final RegistrationTreeNode<AbstractDOMDataTreeChangeListenerRegistration<?>> node = findNodeFor(treeId.getPathArguments()); final AbstractDOMDataTreeChangeListenerRegistration<L> reg = new AbstractDOMDataTreeChangeListenerRegistration<L>(listener) { @Override protected void removeRegistration() { AbstractDOMStoreTreeChangePublisher.this.removeRegistration(node, this); registrationRemoved(this); } }; addRegistration(node, reg); return reg; } finally { // Always release the lock releaseLock(); } }
@Override protected void removeRegistration() { AbstractDOMStoreTreeChangePublisher.this.removeRegistration(node, this); registrationRemoved(this); } };