@Override protected DataTreeSnapshot takeSnapshot() { return tree.takeSnapshot(); }
@Override public synchronized void onGlobalContextUpdated(final SchemaContext ctx) { dataTree.setSchemaContext(ctx); }
private NormalizedNodeAggregator combine() throws DataValidationFailedException { final DataTreeModification mod = dataTree.takeSnapshot().newModification(); for (final Optional<NormalizedNode<?,?>> node : nodes) { if (node.isPresent()) { mod.merge(rootIdentifier, node.get()); } } mod.ready(); dataTree.validate(mod); final DataTreeCandidate candidate = dataTree.prepare(mod); dataTree.commit(candidate); return this; }
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); } }
@Override public void commit(final DataTreeCandidate dataTreeCandidate) { LOG.trace("Commit detected"); delegateDependency.commit(dataTreeCandidate); LOG.debug("Delegate commit successful. Persisting data"); // TODO(HONEYCOMB-163): doing full read and full write might not be the fastest way of persisting data here final DataTreeSnapshot dataTreeSnapshot = delegateDependency.takeSnapshot(); // TODO this can be handled in background by a dedicated thread + a limited blocking queue // TODO enable configurable granularity for persists. Maybe doing write on every modification is too much // and we could do bulk persist persister.persistCurrentData(dataTreeSnapshot.readNode(YangInstanceIdentifier.EMPTY)); }
private DataTreeContext prepareCandidateContext(final DataTreeModification dataTreeModification) throws ValidationFailedException { // Seal the modification (required to perform validate) dataTreeModification.ready(); // Check if modification can be applied to data tree try { dataTree.validate(dataTreeModification); } catch (DataValidationFailedException e) { throw new ValidationFailedException(e); } return contextFactory.create(dataTree.prepare(dataTreeModification)); }
synchronized void commit(final DataTreeCandidate candidate) { dataTree.commit(candidate); changePublisher.publishChange(candidate); }
@Override public DataTreeCandidateTip prepare( final DataTreeModification dataTreeModification) { return delegateDependency.prepare(dataTreeModification); }
void validate(final DataTreeModification modification) throws DataValidationFailedException { dataTree.validate(modification); }
@Override public YangInstanceIdentifier getRootPath() { return delegateDependency.getRootPath(); }
@Override public DataTree create(final DataTreeConfiguration treeConfig, final SchemaContext initialSchemaContext, final NormalizedNodeContainer<?, ?, ?> initialRoot) throws DataValidationFailedException { final DataTree ret = create(treeConfig, initialSchemaContext, false); final DataTreeModification mod = ret.takeSnapshot().newModification(); mod.write(YangInstanceIdentifier.EMPTY, initialRoot); mod.ready(); ret.validate(mod); final DataTreeCandidate candidate = ret.prepare(mod); ret.commit(candidate); return ret; }
@Override public ListenableFuture<Void> commit() { Preconditions.checkState(candidate != null, "Attempted to commit an aborted transaction"); LOG.debug("Commiting candidate {}", candidate); dataTree.commit(candidate); // publish this change for listeners changePublisher.publishChange(candidate); return SUCCESSFUL_FUTURE; } }
DataTreeCandidate prepare(final DataTreeModification modification) { return dataTree.prepare(modification); }
@Override public void validate(final DataTreeModification dataTreeModification) throws DataValidationFailedException { delegateDependency.validate(dataTreeModification); }
@Override public final void validate() throws ValidationFailedException { // Modification requires to be sealed before validation. // Sealed modification cannot be altered, so create copy. final CursorAwareDataTreeModification modificationCopy = (CursorAwareDataTreeModification) snapshot.newModification(); final DataTreeModificationCursor cursor = modificationCopy.createCursor(dataTree.getRootPath()); checkState(cursor != null, "DataTreeModificationCursor for root path should not be null"); modification.applyToCursor(cursor); // Then validate it. validateCandidate(prepareCandidateContext(modificationCopy)); }
@Override public DataTree create(final DataTreeConfiguration treeConfig, final SchemaContext initialSchemaContext, final NormalizedNodeContainer<?, ?, ?> initialRoot) throws DataValidationFailedException { final DataTree ret = create(treeConfig, initialSchemaContext, false); final DataTreeModification mod = ret.takeSnapshot().newModification(); mod.write(YangInstanceIdentifier.EMPTY, initialRoot); mod.ready(); ret.validate(mod); final DataTreeCandidate candidate = ret.prepare(mod); ret.commit(candidate); return ret; }
final DataTreeSnapshot takeSnapshot() { return dataTree.takeSnapshot(); }
@Override public synchronized void onGlobalContextUpdated(final SchemaContext ctx) { dataTree.setSchemaContext(ctx); }
synchronized void commit(final DataTreeCandidate candidate) { dataTree.commit(candidate); changePublisher.publishChange(candidate); ResolveDataChangeEventsTask.create(candidate, listenerTree).resolve(dataChangeListenerNotificationManager); } }