private <L extends DOMDataTreeChangeListener> void initialDataChangeEvent( final YangInstanceIdentifier listenerPath, final L listener) { // FIXME Add support for wildcard listeners final Optional<NormalizedNode<?, ?>> preExistingData = dataTree.takeSnapshot() .readNode(YangInstanceIdentifier.create(stripShardPath(listenerPath))); final DataTreeCandidate initialCandidate; if (preExistingData.isPresent()) { final NormalizedNode<?, ?> data = preExistingData.get(); checkState(data instanceof DataContainerNode, "Expected DataContainer node, but was {}", data.getClass()); // if we are listening on root of some shard we still get // empty normalized node, root is always present if (((DataContainerNode<?>) data).getValue().isEmpty()) { initialCandidate = DataTreeCandidates.newDataTreeCandidate(listenerPath, DataTreeCandidateNodes.empty(data.getIdentifier())); } else { initialCandidate = DataTreeCandidates.fromNormalizedNode(listenerPath, translateRootShardIdentifierToListenerPath(listenerPath, preExistingData.get())); } } else { initialCandidate = DataTreeCandidates.newDataTreeCandidate(listenerPath, DataTreeCandidateNodes.empty(listenerPath.getLastPathArgument())); } listener.onDataTreeChanged(Collections.singleton(initialCandidate)); }
private DataTreeCandidate applyChanges(final Collection<DataTreeCandidate> changes) { final DataTreeModification modification = dataTree.takeSnapshot().newModification(); for (final DataTreeCandidate change : changes) { DataTreeCandidates.applyToModification(modification, change); } modification.ready(); try { dataTree.validate(modification); } catch (final DataValidationFailedException e) { LOG.error("Validation failed for built modification", e); throw new RuntimeException("Notification validation failed", e); } // strip nodes we do not need since this listener doesn't have to be registered at the root of the DataTree DataTreeCandidateNode modifiedChild = dataTree.prepare(modification).getRootNode(); for (final PathArgument pathArgument : listenerPath.getPathArguments()) { modifiedChild = modifiedChild.getModifiedChild(pathArgument); } if (modifiedChild == null) { modifiedChild = DataTreeCandidateNodes.empty(listenerPath.getLastPathArgument()); } return DataTreeCandidates.newDataTreeCandidate(listenerPath, modifiedChild); } }