Merge "BUG-576: fixed javadoc warnings."
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / InMemoryDataTree.java
index c5303e1dbed558c54d2ca709959a98bdff0710c8..0f0b4a12da7e96f594a5d7a8f78c1a0dc79bf8c4 100644 (file)
@@ -7,31 +7,33 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.tree.RootModificationApplyOperation.LatestOperationHolder;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 
 /**
  * Read-only snapshot of the data tree.
  */
 final class InMemoryDataTree implements DataTree {
     private static final Logger LOG = LoggerFactory.getLogger(InMemoryDataTree.class);
-    private static final InstanceIdentifier PUBLIC_ROOT_PATH = InstanceIdentifier.builder().build();
+    private static final YangInstanceIdentifier PUBLIC_ROOT_PATH = YangInstanceIdentifier.builder().build();
 
     private final ReadWriteLock rwLock = new ReentrantReadWriteLock(true);
-    private ModificationApplyOperation applyOper = new AlwaysFailOperation();
+    private final LatestOperationHolder operationHolder = new LatestOperationHolder();
     private SchemaContext currentSchemaContext;
     private TreeNode rootNode;
 
@@ -48,7 +50,8 @@ final class InMemoryDataTree implements DataTree {
     public synchronized void setSchemaContext(final SchemaContext newSchemaContext) {
         Preconditions.checkNotNull(newSchemaContext);
 
-        LOG.info("Attepting to install schema context {}", newSchemaContext);
+        LOG.info("Attempting to install schema contexts");
+        LOG.debug("Following schema contexts will be attempted {}",newSchemaContext);
 
         /*
          * FIXME: we should walk the schema contexts, both current and new and see
@@ -61,7 +64,7 @@ final class InMemoryDataTree implements DataTree {
         // Ready to change the context now, make sure no operations are running
         rwLock.writeLock().lock();
         try {
-            this.applyOper = newApplyOper;
+            this.operationHolder.setCurrent(newApplyOper);
             this.currentSchemaContext = newSchemaContext;
         } finally {
             rwLock.writeLock().unlock();
@@ -72,7 +75,7 @@ final class InMemoryDataTree implements DataTree {
     public InMemoryDataTreeSnapshot takeSnapshot() {
         rwLock.readLock().lock();
         try {
-            return new InMemoryDataTreeSnapshot(currentSchemaContext, rootNode, applyOper);
+            return new InMemoryDataTreeSnapshot(currentSchemaContext, rootNode, operationHolder.newSnapshot());
         } finally {
             rwLock.readLock().unlock();
         }
@@ -100,7 +103,7 @@ final class InMemoryDataTree implements DataTree {
         rwLock.writeLock().lock();
         try {
             final Optional<TreeNode> newRoot = m.getStrategy().apply(m.getRootModification(),
-                    Optional.<TreeNode>of(rootNode), rootNode.getSubtreeVersion().next());
+                    Optional.<TreeNode>of(rootNode), m.getVersion());
             Preconditions.checkState(newRoot.isPresent(), "Apply strategy failed to produce root node");
             return new InMemoryDataTreeCandidate(PUBLIC_ROOT_PATH, root, rootNode, newRoot.get());
         } finally {