- final TreeNode currentRoot = state.getRoot();
- final Optional<TreeNode> newRoot = m.getStrategy().apply(m.getRootModification(),
- Optional.<TreeNode>of(currentRoot), m.getVersion());
- Preconditions.checkState(newRoot.isPresent(), "Apply strategy failed to produce root node");
- return new InMemoryDataTreeCandidate(PUBLIC_ROOT_PATH, root, currentRoot, newRoot.get());
+ final ModificationApplyOperation rootNode = getOperation(rootSchemaNode);
+ DataTreeState currentState;
+ DataTreeState newState;
+ do {
+ currentState = currentState();
+ newState = currentState.withSchemaContext(newSchemaContext, rootNode);
+ // TODO: can we lower this to compareAndSwapRelease?
+ } while (!STATE.compareAndSet(this, currentState, newState));
+ }
+
+ @Override
+ public InMemoryDataTreeSnapshot takeSnapshot() {
+ return currentState().newSnapshot();