Expose DataTreeSnapshot's SchemaContext 90/71390/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 26 Apr 2018 09:01:28 +0000 (11:01 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 26 Apr 2018 09:38:03 +0000 (11:38 +0200)
There are use cases where we need to acquire the SchemaContext
associated with a snapshot. Introduce a method to acquire it.

Change-Id: I16053e03068e7313d409b4d35353eb3c0328b76f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/DataTree.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/DataTreeSnapshot.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/SynchronizedDataTreeModification.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeModification.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTreeSnapshot.java

index 4077a4b01caa3342c3b3cf28ffab082cff1918eb..2c61b5f95f4573070f1b959b43124df4eb39935f 100644 (file)
@@ -13,6 +13,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 /**
  * Interface representing a data tree which can be modified in an MVCC fashion.
  */
+// FIXME: 3.0.0: Consider splitting out a read-only interface, which has no means of affecting internal state
 public interface DataTree extends DataTreeTip {
     /**
      * Take a read-only point-in-time snapshot of the tree.
index d6bd11fc43743861d1d0e009604997b240496bb6..e31750f4533380a4aff987e7b84b87c94ff10096 100644 (file)
@@ -8,13 +8,14 @@
 package org.opendaylight.yangtools.yang.data.api.schema.tree;
 
 import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 /**
- * Read-only snapshot of a {@link DataTree}. The snapshot is stable and isolated,
- * e.g. data tree changes occurring after the snapshot has been taken are not
- * visible through the snapshot.
+ * Read-only snapshot of a {@link DataTree}. The snapshot is stable and isolated, e.g. data tree changes occurring after
+ * the snapshot has been taken are not visible through the snapshot.
  */
 public interface DataTreeSnapshot {
     /**
@@ -32,4 +33,14 @@ public interface DataTreeSnapshot {
      * @return A new data tree modification
      */
     DataTreeModification newModification();
+
+    /**
+     * Return the current {@link SchemaContext}, which is being used for operations.
+     *
+     * @return Current schema context.
+     */
+    // FIXME: 3.0.0: Make this method non-default.
+    default @NonNull SchemaContext getSchemaContext() {
+        throw new UnsupportedOperationException("Not implemented by  " + getClass());
+    }
 }
index 660c81e0881469ae724237534329e63826ab934d..fe71d3db49b88ec5e3b0c9e1364152c2b85c97e8 100644 (file)
@@ -13,6 +13,7 @@ import java.util.Optional;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 /**
  * A {@link DataTreeModification} implementation which delegates all calls to
@@ -64,4 +65,9 @@ public final class SynchronizedDataTreeModification implements DataTreeModificat
     public synchronized void applyToCursor(@Nonnull final DataTreeModificationCursor cursor) {
         delegate.applyToCursor(cursor);
     }
+
+    @Override
+    public synchronized SchemaContext getSchemaContext() {
+        return delegate.getSchemaContext();
+    }
 }
index 049cc3f3401b0eefd3c98e8037556dccc08bf4cc..a2caa98e54a37298dfdb9571b92661a0a8a32d7e 100644 (file)
@@ -22,6 +22,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification
 import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNodes;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -63,6 +64,11 @@ final class InMemoryDataTreeModification extends AbstractCursorAware implements
         return strategyTree;
     }
 
+    @Override
+    public SchemaContext getSchemaContext() {
+        return snapshot.getSchemaContext();
+    }
+
     @Override
     public void write(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
         checkSealed();
index 7cc443281c57f8e22a365643ed7e9e1582312a89..8491eed4f10765f06e6a4778bc568afe7b43596b 100644 (file)
@@ -12,6 +12,7 @@ import static java.util.Objects.requireNonNull;
 
 import java.util.Optional;
 import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
@@ -22,9 +23,9 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 final class InMemoryDataTreeSnapshot extends AbstractCursorAware implements CursorAwareDataTreeSnapshot {
-    private final RootModificationApplyOperation applyOper;
-    private final SchemaContext schemaContext;
-    private final TreeNode rootNode;
+    private final @NonNull RootModificationApplyOperation applyOper;
+    private final @NonNull SchemaContext schemaContext;
+    private final @NonNull TreeNode rootNode;
 
     InMemoryDataTreeSnapshot(final SchemaContext schemaContext, final TreeNode rootNode,
             final RootModificationApplyOperation applyOper) {
@@ -37,7 +38,8 @@ final class InMemoryDataTreeSnapshot extends AbstractCursorAware implements Curs
         return rootNode;
     }
 
-    SchemaContext getSchemaContext() {
+    @Override
+    public SchemaContext getSchemaContext() {
         return schemaContext;
     }