private static void addToListenerChanges( final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> registrations, final YangInstanceIdentifier path, final DataTreeCandidateNode node, final Multimap<AbstractDOMDataTreeChangeListenerRegistration<?>, DataTreeCandidate> listenerChanges) { final DataTreeCandidate dataTreeCandidate = DataTreeCandidates.newDataTreeCandidate(path, node); for (AbstractDOMDataTreeChangeListenerRegistration<?> reg : registrations) { listenerChanges.put(reg, dataTreeCandidate); } } }
@Override protected void notifyListeners(final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> registrations, final YangInstanceIdentifier path, final DataTreeCandidateNode node) { final DataTreeCandidate candidate = DataTreeCandidates.newDataTreeCandidate(path, node); for (AbstractDOMDataTreeChangeListenerRegistration<?> reg : registrations) { LOG.debug("Enqueueing candidate {} to registration {}", candidate, registrations); notificationManager.submitNotification(reg, candidate); } }
@Override protected void notifyListeners(final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> registrations, final YangInstanceIdentifier path, final DataTreeCandidateNode node) { final DataTreeCandidate candidate = DataTreeCandidates.newDataTreeCandidate(path, node); for (AbstractDOMDataTreeChangeListenerRegistration<?> reg : registrations) { LOG.debug("Enqueueing candidate {} to registration {}", candidate, registrations); notificationManager.submitNotification(reg, candidate); } }
void onDataTreeChanged(final YangInstanceIdentifier rootPath, final Collection<DataTreeCandidate> changes) { final List<DataTreeCandidate> newCandidates = changes.stream() .map(candidate -> DataTreeCandidates.newDataTreeCandidate(rootPath, candidate.getRootNode())) .collect(Collectors.toList()); delegate.onDataTreeChanged(Collections.singleton(applyChanges(newCandidates))); }
@Override protected void notifyListeners(final Collection<AbstractDOMDataTreeChangeListenerRegistration<?>> registrations, final YangInstanceIdentifier path, final DataTreeCandidateNode node) { final Collection<DataTreeCandidate> changes = Collections.<DataTreeCandidate>singleton( DataTreeCandidates.newDataTreeCandidate(path, node)); for (AbstractDOMDataTreeChangeListenerRegistration<?> reg : registrations) { reg.getInstance().onDataTreeChanged(changes); } }
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)); }
public static DataTreeCandidate readDataTreeCandidate(final DataInput in) throws IOException { final NormalizedNodeDataInput reader = new NormalizedNodeInputStreamReader(in); final YangInstanceIdentifier rootPath = reader.readYangInstanceIdentifier(); final byte type = reader.readByte(); final DataTreeCandidateNode rootNode; switch (type) { case DELETE: rootNode = DeletedDataTreeCandidateNode.create(); break; case SUBTREE_MODIFIED: rootNode = ModifiedDataTreeCandidateNode.create(readChildren(reader)); break; case WRITE: rootNode = DataTreeCandidateNodes.fromNormalizedNode(reader.readNormalizedNode()); break; default: throw new IllegalArgumentException("Unhandled node type " + type); } return DataTreeCandidates.newDataTreeCandidate(rootPath, rootNode); }
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); } }