BUG-648: Improve performance by reusing old data nodes 86/6886/2
authorRobert Varga <rovarga@cisco.com>
Thu, 8 May 2014 16:29:30 +0000 (18:29 +0200)
committerRobert Varga <rovarga@cisco.com>
Mon, 12 May 2014 05:43:26 +0000 (05:43 +0000)
This patchset gives yang-data-api the chance to optimize copy
operations we execute when creating a new generation.

Change-Id: Ib23a87e116a0a04f7fd4f2b709d7239e213ea744
Signed-off-by: Robert Varga <rovarga@cisco.com>
12 files changed:
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ChangeListenerNotifyTask.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/DOMImmutableDataChangeEvent.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/DataAndMetadataSnapshot.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/DataChangeListenerRegistration.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ModificationApplyOperation.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/OperationWithModification.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperation.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaAwareApplyOperationRoot.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/StoreUtils.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/StoreMetadataNode.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/StoreNodeCompositeBuilder.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/TreeNodeUtils.java

index a7952ac824d3f595fa08ead9f307ccd31fff2736..375376f383aa8beedcc8dccba4d1c37aeec0c788 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.md.sal.dom.store.impl;
 
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
index 3dfca40b4045d435cb79e909a7be0c9b77cec248..af479743aa12a824a0e7610e057b7bbdd299e448 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.md.sal.dom.store.impl;
 
 import java.util.Collections;
index 9961fcce8d25e00e42128928062485efcd5db731..11028dc842404fcc13298edff4ec72ff8be280f7 100644 (file)
@@ -16,7 +16,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 import com.google.common.base.Optional;
-import com.google.common.primitives.UnsignedLong;
 
 class DataAndMetadataSnapshot {
 
@@ -39,22 +38,14 @@ class DataAndMetadataSnapshot {
 
     public static DataAndMetadataSnapshot createEmpty(final NodeIdentifier rootNode) {
         NormalizedNode<?, ?> data = Builders.containerBuilder().withNodeIdentifier(rootNode).build();
-        StoreMetadataNode metadata = StoreMetadataNode.builder()
-                .setNodeVersion(UnsignedLong.ZERO)
-                .setSubtreeVersion(UnsignedLong.ZERO)
-                .setData(data)
-                .build();
+        StoreMetadataNode metadata = StoreMetadataNode.createEmpty(data);
         return new DataAndMetadataSnapshot(metadata,Optional.<SchemaContext>absent());
     }
 
     public static DataAndMetadataSnapshot createEmpty(final SchemaContext ctx) {
         NodeIdentifier rootNodeIdentifier = new NodeIdentifier(ctx.getQName());
         NormalizedNode<?, ?> data = Builders.containerBuilder().withNodeIdentifier(rootNodeIdentifier).build();
-        StoreMetadataNode metadata = StoreMetadataNode.builder()
-                .setData(data)
-                .setNodeVersion(UnsignedLong.ZERO)
-                .setSubtreeVersion(UnsignedLong.ZERO)
-                .build();
+        StoreMetadataNode metadata = StoreMetadataNode.createEmpty(data);
         return new DataAndMetadataSnapshot(metadata, Optional.of(ctx));
     }
 
index d3a892a2cd64cfedfa359d7334e952307efe61de..d8f024017ffa6a39fd2f2b8a0febce04414e9eb7 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.md.sal.dom.store.impl;
 
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
@@ -6,17 +13,11 @@ import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 
-public interface DataChangeListenerRegistration<L extends AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>>>
-extends ListenerRegistration<L> {
-
-
+public interface DataChangeListenerRegistration<L extends AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>>> extends ListenerRegistration<L> {
     @Override
-    public L getInstance();
+    L getInstance();
 
     InstanceIdentifier getPath();
 
     DataChangeScope getScope();
-
-
-
 }
index d02f1109d754680efe8afe0e053b179394a87d60..838afe31c6cf15ce52cb46b3b735d9270dc55452 100644 (file)
@@ -87,8 +87,5 @@ public interface ModificationApplyOperation extends StoreTreeNode<ModificationAp
      *    if suboperation is not supported for specified tree node.
      */
     @Override
-    public Optional<ModificationApplyOperation> getChild(PathArgument child);
-
-
-
+    Optional<ModificationApplyOperation> getChild(PathArgument child);
 }
index 35864b6bc29cfeed97f35690f5548b5bb2c9ad48..8aefb925e7a44e24446778e4f91c6b04d995be8d 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.md.sal.dom.store.impl;
 
 import org.opendaylight.controller.md.sal.dom.store.impl.tree.NodeModification;
@@ -63,4 +70,4 @@ public class OperationWithModification {
         Optional<ModificationApplyOperation> childOp = applyOperation.getChild(childId);
         return from(childOp.get(),childMod);
     }
-}
\ No newline at end of file
+}
index 7ea4d4e09fc1590557b339b65ce78a8fb54f25c6..4bb5aed20c72d9a8424063818cf0c84e31630b47 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.md.sal.dom.store.impl;
 
 import static com.google.common.base.Preconditions.checkArgument;
@@ -27,11 +34,12 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
 import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAugmentationNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
@@ -59,8 +67,6 @@ import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
 import com.google.common.cache.LoadingCache;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSet.Builder;
 import com.google.common.primitives.UnsignedLong;
 
 public abstract class SchemaAwareApplyOperation implements ModificationApplyOperation {
@@ -321,30 +327,28 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
         @Override
         protected StoreMetadataNode applyWrite(final NodeModification modification,
                 final Optional<StoreMetadataNode> currentMeta, final UnsignedLong subtreeVersion) {
-            //
+
             NormalizedNode<?, ?> newValue = modification.getWritenValue();
 
-            UnsignedLong nodeVersion = subtreeVersion;
+            final UnsignedLong nodeVersion;
             if (currentMeta.isPresent()) {
                 nodeVersion = StoreUtils.increase(currentMeta.get().getNodeVersion());
+            } else {
+                nodeVersion = subtreeVersion;
             }
-            StoreMetadataNode newValueMeta = StoreMetadataNode.createRecursively(newValue, nodeVersion, nodeVersion);
 
+            final StoreMetadataNode newValueMeta = StoreMetadataNode.createRecursively(newValue, nodeVersion, nodeVersion);
             if (!modification.hasAdditionalModifications()) {
                 return newValueMeta;
             }
+
             @SuppressWarnings("rawtypes")
-            NormalizedNodeContainerBuilder dataBuilder = createBuilder(modification.getIdentifier());
+            NormalizedNodeContainerBuilder dataBuilder = createBuilder(newValue);
             StoreNodeCompositeBuilder builder = StoreNodeCompositeBuilder.from(dataBuilder) //
                     .setNodeVersion(nodeVersion) //
                     .setSubtreeVersion(subtreeVersion);
 
-            Set<PathArgument> processedPreexisting = applyPreexistingChildren(modification, newValueMeta.getChildren(),
-                    builder, nodeVersion);
-            applyNewChildren(modification, processedPreexisting, builder, nodeVersion);
-
-            return builder.build();
-
+            return mutateChildren(modification.getModifications(), newValueMeta, builder, nodeVersion);
         }
 
         @Override
@@ -357,55 +361,34 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
         @Override
         public StoreMetadataNode applySubtreeChange(final NodeModification modification,
                 final StoreMetadataNode currentMeta, final UnsignedLong subtreeVersion) {
+            // Bump subtree version to its new target
+            final UnsignedLong updatedSubtreeVersion = StoreUtils.increase(currentMeta.getSubtreeVersion());
 
-            UnsignedLong updatedSubtreeVersion = StoreUtils.increase(currentMeta.getSubtreeVersion());
             @SuppressWarnings("rawtypes")
-            NormalizedNodeContainerBuilder dataBuilder = createBuilder(modification.getIdentifier());
-            StoreNodeCompositeBuilder builder = StoreNodeCompositeBuilder.from(dataBuilder)
+            NormalizedNodeContainerBuilder dataBuilder = createBuilder(currentMeta.getData());
+            StoreNodeCompositeBuilder builder = StoreNodeCompositeBuilder.from(dataBuilder, currentMeta)
                     .setIdentifier(modification.getIdentifier()).setNodeVersion(currentMeta.getNodeVersion())
                     .setSubtreeVersion(updatedSubtreeVersion);
-            // We process preexisting nodes
-            Set<PathArgument> processedPreexisting = applyPreexistingChildren(modification, currentMeta.getChildren(),
-                    builder, updatedSubtreeVersion);
-            applyNewChildren(modification, processedPreexisting, builder, updatedSubtreeVersion);
-            return builder.build();
+
+            return mutateChildren(modification.getModifications(), currentMeta, builder, updatedSubtreeVersion);
         }
 
-        private void applyNewChildren(final NodeModification modification, final Set<PathArgument> ignore,
-                final StoreNodeCompositeBuilder builder, final UnsignedLong subtreeVersion) {
-            for (NodeModification childModification : modification.getModifications()) {
-                PathArgument childIdentifier = childModification.getIdentifier();
-                // We skip allready processed modifications
-                if (ignore.contains(childIdentifier)) {
-                    continue;
-                }
+        private StoreMetadataNode mutateChildren(final Iterable<NodeModification> modifications, final StoreMetadataNode meta,
+                final StoreNodeCompositeBuilder builder, final UnsignedLong nodeVersion) {
 
-                builder.addIfPresent(resolveChildOperation(childIdentifier) //
-                        .apply(childModification, Optional.<StoreMetadataNode> absent(), subtreeVersion));
-            }
-        }
+            for (NodeModification mod : modifications) {
+                final PathArgument id = mod.getIdentifier();
+                final Optional<StoreMetadataNode> cm = meta.getChild(id);
 
-        private Set<PathArgument> applyPreexistingChildren(final NodeModification modification,
-                final Iterable<StoreMetadataNode> children, final StoreNodeCompositeBuilder nodeBuilder,
-                final UnsignedLong subtreeVersion) {
-            Builder<PathArgument> processedModifications = ImmutableSet.<PathArgument> builder();
-            for (StoreMetadataNode childMeta : children) {
-                PathArgument childIdentifier = childMeta.getIdentifier();
-                // We retrieve Child modification metadata
-                Optional<NodeModification> childModification = modification.getChild(childIdentifier);
-                // Node is modified
-                if (childModification.isPresent()) {
-                    processedModifications.add(childIdentifier);
-                    Optional<StoreMetadataNode> result = resolveChildOperation(childIdentifier) //
-                            .apply(childModification.get(), Optional.of(childMeta), subtreeVersion);
-                    nodeBuilder.addIfPresent(result);
+                Optional<StoreMetadataNode> result = resolveChildOperation(id).apply(mod, cm, nodeVersion);
+                if (result.isPresent()) {
+                    builder.add(result.get());
                 } else {
-                    // Child is unmodified - reuse existing metadata and data
-                    // snapshot
-                    nodeBuilder.add(childMeta);
+                    builder.remove(id);
                 }
             }
-            return processedModifications.build();
+
+            return builder.build();
         }
 
         @Override
@@ -425,7 +408,7 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
         }
 
         @SuppressWarnings("rawtypes")
-        protected abstract NormalizedNodeContainerBuilder createBuilder(PathArgument identifier);
+        protected abstract NormalizedNodeContainerBuilder createBuilder(NormalizedNode<?, ?> original);
     }
 
     public static abstract class DataNodeContainerModificationStrategy<T extends DataNodeContainer> extends
@@ -470,7 +453,7 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
 
         @Override
         @SuppressWarnings("rawtypes")
-        protected abstract DataContainerNodeBuilder createBuilder(PathArgument identifier);
+        protected abstract DataContainerNodeBuilder createBuilder(NormalizedNode<?, ?> original);
 
         @Override
         public String toString() {
@@ -488,12 +471,10 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
 
         @Override
         @SuppressWarnings("rawtypes")
-        protected DataContainerNodeBuilder createBuilder(final PathArgument identifier) {
-            // TODO Auto-generated method stub
-            checkArgument(identifier instanceof NodeIdentifier);
-            return ImmutableContainerNodeBuilder.create().withNodeIdentifier((NodeIdentifier) identifier);
+        protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
+            checkArgument(original instanceof ContainerNode);
+            return ImmutableContainerNodeBuilder.create((ContainerNode) original);
         }
-
     }
 
     public static class UnkeyedListItemModificationStrategy extends
@@ -505,11 +486,10 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
 
         @Override
         @SuppressWarnings("rawtypes")
-        protected DataContainerNodeBuilder createBuilder(final PathArgument identifier) {
-            checkArgument(identifier instanceof NodeIdentifier);
-            return ImmutableUnkeyedListEntryNodeBuilder.create().withNodeIdentifier((NodeIdentifier) identifier);
+        protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
+            checkArgument(original instanceof UnkeyedListEntryNode);
+            return ImmutableUnkeyedListEntryNodeBuilder.create((UnkeyedListEntryNode) original);
         }
-
     }
 
     public static class AugmentationModificationStrategy extends
@@ -522,10 +502,11 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
         }
 
         @Override
-        protected DataContainerNodeBuilder createBuilder(final PathArgument identifier) {
-            return Builders.augmentationBuilder().withNodeIdentifier((AugmentationIdentifier) identifier);
+        @SuppressWarnings("rawtypes")
+        protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
+            checkArgument(original instanceof AugmentationNode);
+            return ImmutableAugmentationNodeBuilder.create((AugmentationNode) original);
         }
-
     }
 
     public static class ChoiceModificationStrategy extends NormalizedNodeContainerModificationStrategy {
@@ -554,11 +535,10 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
 
         @Override
         @SuppressWarnings("rawtypes")
-        protected DataContainerNodeBuilder createBuilder(final PathArgument identifier) {
-            checkArgument(identifier instanceof NodeIdentifier);
-            return ImmutableChoiceNodeBuilder.create().withNodeIdentifier((NodeIdentifier) identifier);
+        protected DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
+            checkArgument(original instanceof org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode);
+            return ImmutableChoiceNodeBuilder.create((org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode) original);
         }
-
     }
 
     public static class ListEntryModificationStrategy extends DataNodeContainerModificationStrategy<ListSchemaNode> {
@@ -569,10 +549,10 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
 
         @Override
         @SuppressWarnings("rawtypes")
-        protected final DataContainerNodeBuilder createBuilder(final PathArgument identifier) {
-            return ImmutableMapEntryNodeBuilder.create().withNodeIdentifier((NodeIdentifierWithPredicates) identifier);
+        protected final DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
+            checkArgument(original instanceof MapEntryNode);
+            return ImmutableMapEntryNodeBuilder.create((MapEntryNode) original);
         }
-
     }
 
     public static class UnorderedLeafSetModificationStrategy extends NormalizedNodeContainerModificationStrategy {
@@ -587,8 +567,9 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
 
         @SuppressWarnings("rawtypes")
         @Override
-        protected NormalizedNodeContainerBuilder createBuilder(final PathArgument identifier) {
-            return ImmutableLeafSetNodeBuilder.create().withNodeIdentifier((NodeIdentifier) identifier);
+        protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode<?, ?> original) {
+            checkArgument(original instanceof LeafSetNode<?>);
+            return ImmutableLeafSetNodeBuilder.create((LeafSetNode<?>) original);
         }
 
         @Override
@@ -598,7 +579,6 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
             }
             return Optional.absent();
         }
-
     }
 
     public static class OrderedLeafSetModificationStrategy extends NormalizedNodeContainerModificationStrategy {
@@ -613,8 +593,9 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
 
         @SuppressWarnings("rawtypes")
         @Override
-        protected NormalizedNodeContainerBuilder createBuilder(final PathArgument identifier) {
-            return ImmutableOrderedLeafSetNodeBuilder.create().withNodeIdentifier((NodeIdentifier) identifier);
+        protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode<?, ?> original) {
+            checkArgument(original instanceof OrderedLeafSetNode<?>);
+            return ImmutableOrderedLeafSetNodeBuilder.create((OrderedLeafSetNode<?>) original);
         }
 
         @Override
@@ -624,7 +605,6 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
             }
             return Optional.absent();
         }
-
     }
 
     public static class UnkeyedListModificationStrategy extends SchemaAwareApplyOperation {
@@ -685,8 +665,9 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
 
         @SuppressWarnings("rawtypes")
         @Override
-        protected NormalizedNodeContainerBuilder createBuilder(final PathArgument identifier) {
-            return ImmutableMapNodeBuilder.create().withNodeIdentifier((NodeIdentifier) identifier);
+        protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode<?, ?> original) {
+            checkArgument(original instanceof MapNode);
+            return ImmutableMapNodeBuilder.create((MapNode) original);
         }
 
         @Override
@@ -714,8 +695,9 @@ public abstract class SchemaAwareApplyOperation implements ModificationApplyOper
 
         @SuppressWarnings("rawtypes")
         @Override
-        protected NormalizedNodeContainerBuilder createBuilder(final PathArgument identifier) {
-            return ImmutableOrderedMapNodeBuilder.create().withNodeIdentifier((NodeIdentifier) identifier);
+        protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode<?, ?> original) {
+            checkArgument(original instanceof OrderedMapNode);
+            return ImmutableOrderedMapNodeBuilder.create((OrderedMapNode) original);
         }
 
         @Override
index e7265dedb5a5cb99eb6739247f8daa888bf7e54e..8a539ff36edc7e2f25b9b5bddea1710486b0310f 100644 (file)
@@ -7,16 +7,14 @@
  */
 package org.opendaylight.controller.md.sal.dom.store.impl;
 
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class SchemaAwareApplyOperationRoot extends SchemaAwareApplyOperation.DataNodeContainerModificationStrategy<ContainerSchemaNode> {
-
     private final SchemaContext context;
 
     public SchemaAwareApplyOperationRoot(final SchemaContext context) {
@@ -24,11 +22,6 @@ public class SchemaAwareApplyOperationRoot extends SchemaAwareApplyOperation.Dat
         this.context = context;
     }
 
-    @Override
-    protected DataContainerNodeBuilder createBuilder(final PathArgument identifier) {
-        return ImmutableContainerNodeBuilder.create().withNodeIdentifier((NodeIdentifier) identifier);
-    }
-
     public SchemaContext getContext() {
         return context;
     }
@@ -38,4 +31,9 @@ public class SchemaAwareApplyOperationRoot extends SchemaAwareApplyOperation.Dat
         return "SchemaAwareApplyOperationRoot [context=" + context + "]";
     }
 
+    @Override
+    @SuppressWarnings("rawtypes")
+    protected DataContainerNodeBuilder createBuilder(NormalizedNode<?, ?> original) {
+        return ImmutableContainerNodeBuilder.create((ContainerNode) original);
+    }
 }
index 830d7e3dc40303859748e5d1977eeaa3f7018c3b..0f77ac504a3f5a647f9a184e88b7ecc569332c6f 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.md.sal.dom.store.impl;
 
 import java.util.Collections;
index d42f36fb90768757bcda5f4878f7ef985b827af4..455777b7fb9a1b315c036c6a5d9d6482473e0fa7 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.controller.md.sal.dom.store.impl.tree;
 
 import static com.google.common.base.Preconditions.checkState;
 
+import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
@@ -46,10 +47,24 @@ public class StoreMetadataNode implements Immutable, Identifiable<PathArgument>,
         this.children = Preconditions.checkNotNull(children);
     }
 
+    public static StoreMetadataNode createEmpty(final NormalizedNode<?, ?> data) {
+        return new StoreMetadataNode(data, UnsignedLong.ZERO, UnsignedLong.ZERO,
+                Collections.<PathArgument, StoreMetadataNode>emptyMap());
+    }
+
+    public StoreMetadataNode(final NormalizedNode<?, ?> data, final UnsignedLong nodeVersion,
+            final UnsignedLong subtreeVersion) {
+        this(data, nodeVersion, subtreeVersion, Collections.<PathArgument, StoreMetadataNode>emptyMap());
+    }
+
     public static Builder builder() {
         return new Builder();
     }
 
+    public static Builder builder(StoreMetadataNode node) {
+        return new Builder(node);
+    }
+
     public UnsignedLong getNodeVersion() {
         return this.nodeVersion;
     }
@@ -118,11 +133,16 @@ public class StoreMetadataNode implements Immutable, Identifiable<PathArgument>,
         private UnsignedLong nodeVersion;
         private UnsignedLong subtreeVersion;
         private NormalizedNode<?, ?> data;
-        private Map<PathArgument, StoreMetadataNode> children = new LinkedHashMap<>();
+        private Map<PathArgument, StoreMetadataNode> children;
         private boolean dirty = false;
 
-        private Builder() {}
+        private Builder() {
+            children = new LinkedHashMap<>();
+        }
 
+        public Builder(StoreMetadataNode node) {
+            children = new LinkedHashMap<>(node.children);
+        }
 
         public UnsignedLong getVersion() {
             return nodeVersion;
@@ -153,6 +173,15 @@ public class StoreMetadataNode implements Immutable, Identifiable<PathArgument>,
             return this;
         }
 
+        public Builder remove(final PathArgument id) {
+            if (dirty) {
+                children = new LinkedHashMap<>(children);
+                dirty = false;
+            }
+            children.remove(id);
+            return this;
+        }
+
         public StoreMetadataNode build() {
             checkState(data != null, "Data node should not be null.");
             checkState(subtreeVersion.compareTo(nodeVersion) >= 0,
@@ -165,5 +194,4 @@ public class StoreMetadataNode implements Immutable, Identifiable<PathArgument>,
     public static StoreMetadataNode createRecursively(final NormalizedNode<?, ?> node, final UnsignedLong version) {
         return createRecursively(node, version, version);
     }
-
 }
index 41fc8239fbab36edee44a6ecacd7940a4722e4ce..a66a1d5b1ce3808af5e66e2eeca95684748346d0 100644 (file)
@@ -10,7 +10,7 @@ package org.opendaylight.controller.md.sal.dom.store.impl.tree;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
 
-import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedLong;
 
 /**
@@ -28,7 +28,12 @@ public class StoreNodeCompositeBuilder {
 
     private StoreNodeCompositeBuilder(final NormalizedNodeContainerBuilder nodeBuilder) {
         this.metadata = StoreMetadataNode.builder();
-        this.data = nodeBuilder;
+        this.data = Preconditions.checkNotNull(nodeBuilder);
+    }
+
+    public StoreNodeCompositeBuilder(NormalizedNodeContainerBuilder nodeBuilder, StoreMetadataNode currentMeta) {
+        this.metadata = StoreMetadataNode.builder(currentMeta);
+        this.data = Preconditions.checkNotNull(nodeBuilder);
     }
 
     @SuppressWarnings("unchecked")
@@ -39,12 +44,9 @@ public class StoreNodeCompositeBuilder {
     }
 
     @SuppressWarnings("unchecked")
-    public StoreNodeCompositeBuilder addIfPresent(final Optional<StoreMetadataNode> potential) {
-        if (potential.isPresent()) {
-            StoreMetadataNode node = potential.get();
-            metadata.add(node);
-            data.addChild(node.getData());
-        }
+    public StoreNodeCompositeBuilder remove(PathArgument id) {
+        metadata.remove(id);
+        data.removeChild(id);
         return this;
     }
 
@@ -56,6 +58,10 @@ public class StoreNodeCompositeBuilder {
         return new StoreNodeCompositeBuilder(nodeBuilder);
     }
 
+    public static StoreNodeCompositeBuilder from(final NormalizedNodeContainerBuilder nodeBuilder, StoreMetadataNode currentMeta) {
+        return new StoreNodeCompositeBuilder(nodeBuilder, currentMeta);
+    }
+
     @SuppressWarnings("unchecked")
     public StoreNodeCompositeBuilder setIdentifier(final PathArgument identifier) {
         data.withNodeIdentifier(identifier);
@@ -71,5 +77,4 @@ public class StoreNodeCompositeBuilder {
         metadata.setSubtreeVersion(updatedSubtreeVersion);
         return this;
     }
-
 }
index 339d9cb44e2ed9515daa1eabbb8db2d913dab91a..732352dd34bbf974b6d897984d9b731c72e5e591 100644 (file)
@@ -21,7 +21,10 @@ import com.google.common.base.Preconditions;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 
-public class TreeNodeUtils {
+public final class TreeNodeUtils {
+    private TreeNodeUtils() {
+        throw new UnsupportedOperationException("Utility class should not be instantiated");
+    }
 
     /**
      * Finds a node in tree
@@ -40,7 +43,6 @@ public class TreeNodeUtils {
         return current;
     }
 
-
     public static <T extends StoreTreeNode<T>> T findNodeChecked(final T tree, final InstanceIdentifier path) {
         T current = tree;
         List<PathArgument> nested = new ArrayList<>(path.getPath().size());