Apply SchemaContext to dataTree first 10/42410/3
authorRobert Varga <rovarga@cisco.com>
Sun, 24 Jul 2016 19:05:30 +0000 (21:05 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Tue, 26 Jul 2016 08:49:18 +0000 (08:49 +0000)
DataTree.setSchemaContext() can fail, hence do not update the schema
context before we propagate it to data tree.

Change-Id: I0170133177ac74280da2ccc367b3c447f9d4cdc9
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ShardDataTree.java

index 3e3d4cc20cb070395e75766c25ba95f3ab6eea37..edf05f2a25bb9fe5bb108b18dd5fcd10709266e8 100644 (file)
@@ -60,9 +60,10 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
             final ShardDataChangeListenerPublisher dataChangeListenerPublisher, final String logContext) {
         dataTree = InMemoryDataTreeFactory.getInstance().create(treeType);
         updateSchemaContext(schemaContext);
             final ShardDataChangeListenerPublisher dataChangeListenerPublisher, final String logContext) {
         dataTree = InMemoryDataTreeFactory.getInstance().create(treeType);
         updateSchemaContext(schemaContext);
-        this.treeChangeListenerPublisher = treeChangeListenerPublisher;
-        this.dataChangeListenerPublisher = dataChangeListenerPublisher;
-        this.logContext = logContext;
+
+        this.treeChangeListenerPublisher = Preconditions.checkNotNull(treeChangeListenerPublisher);
+        this.dataChangeListenerPublisher = Preconditions.checkNotNull(dataChangeListenerPublisher);
+        this.logContext = Preconditions.checkNotNull(logContext);
     }
 
     public ShardDataTree(final SchemaContext schemaContext, final TreeType treeType) {
     }
 
     public ShardDataTree(final SchemaContext schemaContext, final TreeType treeType) {
@@ -79,9 +80,8 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
     }
 
     void updateSchemaContext(final SchemaContext schemaContext) {
     }
 
     void updateSchemaContext(final SchemaContext schemaContext) {
-        Preconditions.checkNotNull(schemaContext);
-        this.schemaContext = schemaContext;
         dataTree.setSchemaContext(schemaContext);
         dataTree.setSchemaContext(schemaContext);
+        this.schemaContext = Preconditions.checkNotNull(schemaContext);
     }
 
     private ShardDataTreeTransactionChain ensureTransactionChain(final LocalHistoryIdentifier localHistoryIdentifier) {
     }
 
     private ShardDataTreeTransactionChain ensureTransactionChain(final LocalHistoryIdentifier localHistoryIdentifier) {
@@ -116,10 +116,9 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
         dataChangeListenerPublisher.publishChanges(candidate, logContext);
     }
 
         dataChangeListenerPublisher.publishChanges(candidate, logContext);
     }
 
-    void notifyOfInitialData(DataChangeListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier,
-            NormalizedNode<?, ?>>> listenerReg, Optional<DataTreeCandidate> currentState) {
-
-        if(currentState.isPresent()) {
+    void notifyOfInitialData(final DataChangeListenerRegistration<AsyncDataChangeListener<YangInstanceIdentifier,
+            NormalizedNode<?, ?>>> listenerReg, final Optional<DataTreeCandidate> currentState) {
+        if (currentState.isPresent()) {
             ShardDataChangeListenerPublisher localPublisher = dataChangeListenerPublisher.newInstance();
             localPublisher.registerDataChangeListener(listenerReg.getPath(), listenerReg.getInstance(),
                     listenerReg.getScope());
             ShardDataChangeListenerPublisher localPublisher = dataChangeListenerPublisher.newInstance();
             localPublisher.registerDataChangeListener(listenerReg.getPath(), listenerReg.getInstance(),
                     listenerReg.getScope());
@@ -129,7 +128,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
 
     void notifyOfInitialData(final YangInstanceIdentifier path, final DOMDataTreeChangeListener listener,
             final Optional<DataTreeCandidate> currentState) {
 
     void notifyOfInitialData(final YangInstanceIdentifier path, final DOMDataTreeChangeListener listener,
             final Optional<DataTreeCandidate> currentState) {
-        if(currentState.isPresent()) {
+        if (currentState.isPresent()) {
             ShardDataTreeChangeListenerPublisher localPublisher = treeChangeListenerPublisher.newInstance();
             localPublisher.registerTreeChangeListener(path, listener);
             localPublisher.publishChanges(currentState.get(), logContext);
             ShardDataTreeChangeListenerPublisher localPublisher = treeChangeListenerPublisher.newInstance();
             localPublisher.registerTreeChangeListener(path, listener);
             localPublisher.publishChanges(currentState.get(), logContext);
@@ -203,7 +202,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
         return new SimpleShardDataTreeCohort(this, snapshot, transaction.getId());
     }
 
         return new SimpleShardDataTreeCohort(this, snapshot, transaction.getId());
     }
 
-    public Optional<NormalizedNode<?, ?>> readNode(YangInstanceIdentifier path) {
+    public Optional<NormalizedNode<?, ?>> readNode(final YangInstanceIdentifier path) {
         return dataTree.takeSnapshot().readNode(path);
     }
 
         return dataTree.takeSnapshot().readNode(path);
     }
 
@@ -216,7 +215,7 @@ public class ShardDataTree extends ShardDataTreeTransactionParent {
     }
 
     // FIXME: This should be removed, it violates encapsulation
     }
 
     // FIXME: This should be removed, it violates encapsulation
-    public DataTreeCandidate commit(DataTreeModification modification) throws DataValidationFailedException {
+    public DataTreeCandidate commit(final DataTreeModification modification) throws DataValidationFailedException {
         modification.ready();
         dataTree.validate(modification);
         DataTreeCandidateTip candidate = dataTree.prepare(modification);
         modification.ready();
         dataTree.validate(modification);
         DataTreeCandidateTip candidate = dataTree.prepare(modification);