- // Ready to change the context now, make sure no operations are running
- rwLock.writeLock().lock();
- try {
- Preconditions.checkState(c.getBeforeRoot() == rootNode,
- "Store tree %s and candidate base %s differ.", rootNode, c.getBeforeRoot());
- this.rootNode = c.getAfterRoot();
- } finally {
- rwLock.writeLock().unlock();
- }
+ final TreeNode newRoot = c.getTipRoot();
+ DataTreeState currentState, newState;
+ do {
+ currentState = state;
+ final TreeNode currentRoot = currentState.getRoot();
+ LOG.debug("Updating datastore from {} to {}", currentRoot, newRoot);
+
+ final TreeNode oldRoot = c.getBeforeRoot();
+ Preconditions.checkState(oldRoot == currentRoot, "Store tree %s and candidate base %s differ.", currentRoot, oldRoot);
+
+ newState = currentState.withRoot(newRoot);
+ LOG.trace("Updated state from {} to {}", currentState, newState);
+ } while (!STATE_UPDATER.compareAndSet(this, currentState, newState));
+ }
+
+ @Override
+ public YangInstanceIdentifier getRootPath() {
+ return rootPath;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this).
+ add("object", super.toString()).
+ add("rootPath", rootPath).
+ add("state", state).
+ toString();
+ }
+
+ @Override
+ protected TreeNode getTipRoot() {
+ return state.getRoot();