From: Robert Varga Date: Thu, 29 May 2014 13:04:30 +0000 (+0200) Subject: BUG-509: cleanup datastore interafaces X-Git-Tag: autorelease-tag-v20140601202136_82eb3f9~5 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=ce0f8ee50fbbc078c679bbf6305442e3aa2a2cfb BUG-509: cleanup datastore interafaces This removes unused methods and adds interface contract documentation. Change-Id: I7bc57d034da1d0503d76afa6f4c09ce6a6bfe669 Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java index 00df6580ef..7b799661af 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java @@ -257,7 +257,7 @@ public class InMemoryDOMDataStore implements DOMStore, Identifiable, Sch ready = true; LOG.debug("Store transaction: {} : Ready", getIdentifier()); - mutableTree.seal(); + mutableTree.ready(); return store.submit(this); } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeEventsTask.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeEventsTask.java index b36ef3dd7c..2a163d8dbc 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeEventsTask.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/ResolveDataChangeEventsTask.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.md.sal.dom.store.impl; import static org.opendaylight.controller.md.sal.dom.store.impl.DOMImmutableDataChangeEvent.builder; -import static org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreUtils.append; import java.util.Collection; import java.util.Collections; @@ -46,23 +45,10 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; /** - * * Resolve Data Change Events based on modifications and listeners * * Computes data change events for all affected registered listeners in data * tree. - * - * Prerequisites for computation is to set all parameters properly: - *
    - *
  • {@link #setRootPath(InstanceIdentifier)} - Root path of datastore - *
  • {@link #setListenerRoot(ListenerTree)} - Root of listener registration - * tree, which contains listeners to be notified - *
  • {@link #setModificationRoot(NodeModification)} - Modification root, for - * which events should be computed - *
  • {@link #setBeforeRoot(Optional)} - State of before modification occurred - *
  • {@link #setAfterRoot(Optional)} - State of after modification occurred - *
- * */ final class ResolveDataChangeEventsTask implements Callable> { private static final Logger LOG = LoggerFactory.getLogger(ResolveDataChangeEventsTask.class); @@ -72,7 +58,7 @@ final class ResolveDataChangeEventsTask implements Callable beforeChild : beforeCont.getValue()) { PathArgument childId = beforeChild.getIdentifier(); alreadyProcessed.add(childId); - InstanceIdentifier childPath = append(path, childId); + InstanceIdentifier childPath = path.node(childId); Collection childListeners = getListenerChildrenWildcarded(listeners, childId); Optional> afterChild = afterCont.getChild(childId); DOMImmutableDataChangeEvent childChange = resolveNodeContainerChildUpdated(childPath, childListeners, @@ -348,7 +334,7 @@ final class ResolveDataChangeEventsTask implements Callable childListeners = getListenerChildrenWildcarded(listeners, childId); - InstanceIdentifier childPath = append(path,childId); + InstanceIdentifier childPath = path.node(childId); childChanges.add(resolveSameEventRecursivelly(childPath , childListeners, afterChild, DOMImmutableDataChangeEvent.getCreateEventFactory())); } @@ -432,7 +418,7 @@ final class ResolveDataChangeEventsTask implements Callable childListeners = getListenerChildrenWildcarded(listeners, childId); - eventBuilder.merge(resolveSameEventRecursivelly(append(path, childId), childListeners, child, eventFactory)); + eventBuilder.merge(resolveSameEventRecursivelly(path.node(childId), childListeners, child, eventFactory)); } propagateEvent = eventBuilder.build(); } else { @@ -460,7 +446,7 @@ final class ResolveDataChangeEventsTask implements Callable childListeners = getListenerChildrenWildcarded(listeners, childId); switch (childMod.getModificationType()) { @@ -522,7 +508,7 @@ final class ResolveDataChangeEventsTask implements Callable getChildNodes(); + /** + * Return the type of modification this node is undergoing. + * + * @return Node modification type. + */ ModificationType getModificationType(); + + /** + * Return the before-image of data corresponding to the node. + * + * @return Node data as they were present in the tree before + * the modification was applied. + */ Optional> getDataAfter(); + + /** + * Return the after-image of data corresponding to the node. + * + * @return Node data as they will be present in the tree after + * the modification is applied. + */ Optional> getDataBefore(); } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/DataTreeModification.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/DataTreeModification.java index cff90a4aef..e4370c46a0 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/DataTreeModification.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/DataTreeModification.java @@ -16,8 +16,35 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; * has the ability to rebase itself to a new snapshot. */ public interface DataTreeModification extends DataTreeSnapshot { - void delete(InstanceIdentifier path); - void merge(InstanceIdentifier path, NormalizedNode data); - void write(InstanceIdentifier path, NormalizedNode data); - void seal(); + /** + * Delete the node at specified path. + * + * @param path Node path + */ + void delete(InstanceIdentifier path); + + /** + * Merge the specified data with the currently-present data + * at specified path. + * + * @param path Node path + * @param data Data to be merged + */ + void merge(InstanceIdentifier path, NormalizedNode data); + + /** + * Replace the data at specified path with supplied data. + * + * @param path Node path + * @param data New node data + */ + void write(InstanceIdentifier path, NormalizedNode data); + + /** + * Finish creation of a modification, making it ready for application + * to the data tree. Any calls to this object's methods will result + * in undefined behavior, possibly with an + * {@link IllegalStateException} being thrown. + */ + void ready(); } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ListenerTree.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ListenerTree.java index f93f40a9cc..0d73143de2 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ListenerTree.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ListenerTree.java @@ -33,15 +33,24 @@ import org.slf4j.LoggerFactory; import com.google.common.base.Optional; import com.google.common.base.Preconditions; +/** + * A set of listeners organized as a tree by node to which they listen. This class + * allows for efficient lookup of listeners when we walk the DataTreeCandidate. + */ public final class ListenerTree { private static final Logger LOG = LoggerFactory.getLogger(ListenerTree.class); private final ReadWriteLock rwLock = new ReentrantReadWriteLock(true); private final Node rootNode = new Node(null, null); private ListenerTree() { - + // Private to disallow direct instantiation } + /** + * Create a new empty instance of the listener tree. + * + * @return An empty instance. + */ public static ListenerTree create() { return new ListenerTree(); } @@ -110,6 +119,14 @@ public final class ListenerTree { } } + /** + * Obtain a tree walking context. This context ensures a consistent view of + * the listener registrations. The context should be closed as soon as it + * is not required, because each unclosed instance blocks modification of + * the listener tree. + * + * @return A walker instance. + */ public Walker getWalker() { /* * TODO: The only current user of this method is local to the datastore. @@ -124,6 +141,10 @@ public final class ListenerTree { return ret; } + /** + * A walking context, pretty much equivalent to an iterator, but it + * exposes the undelying tree structure. + */ public static final class Walker implements AutoCloseable { private final Lock lock; private final Node node; diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ModificationType.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ModificationType.java index b16e907120..b9a26f5c00 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ModificationType.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/ModificationType.java @@ -7,37 +7,39 @@ */ package org.opendaylight.controller.md.sal.dom.store.impl.tree; +/** + * Enumeration of all possible node modification states. These are used in + * data tree modification context to quickly assess what sort of modification + * the node is undergoing. + */ public enum ModificationType { - /** - * - * Node is unmodified - * - * + * Node is currently unmodified. */ UNMODIFIED, + /** - * - * Child of tree node was modified - * + * A child node, either direct or indirect, has been modified. This means + * that the data representation of this node has potentially changed. */ SUBTREE_MODIFIED, + /** - * Tree node was replaced with new value / subtree - * + * This node has been placed into the tree, potentially completely replacing + * pre-existing contents. */ WRITE, + /** - * - * Tree node is to be deleted. - * + * This node has been deleted along with any of its child nodes. */ DELETE, /** - * - * Tree node is to be merged with existing one. - * + * Node has been written into the tree, but instead of replacing pre-existing + * contents, it has been merged. This means that any incoming nodes which + * were present in the tree have been replaced, but their child nodes have + * been retained. */ - MERGE + MERGE, } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/StoreTreeNode.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/StoreTreeNode.java index 52beaa7c61..d714f1cc85 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/StoreTreeNode.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/StoreTreeNode.java @@ -10,17 +10,17 @@ package org.opendaylight.controller.md.sal.dom.store.impl.tree; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; import com.google.common.base.Optional; + /** - * - * Tree node which contains references to it's leafs + * A tree node which has references to its child leaves. This are typically + * internal non-data leaves, such as containers, lists, etc. * * @param Final node type */ public interface StoreTreeNode> { /** - * - * Returns direct child of the node + * Returns a direct child of the node * * @param child Identifier of child * @return Optional with node if the child is existing, {@link Optional#absent()} otherwise. diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/StoreUtils.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/StoreUtils.java index 7e783f927d..b634866856 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/StoreUtils.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/StoreUtils.java @@ -7,60 +7,32 @@ */ package org.opendaylight.controller.md.sal.dom.store.impl.tree; -import java.util.Set; - -import org.opendaylight.yangtools.concepts.Identifiable; -import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.AugmentationIdentifier; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.NodeIdentifierWithPredicates; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer; -import com.google.common.base.Function; import com.google.common.base.Strings; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.ImmutableList; -import com.google.common.primitives.UnsignedLong; +/** + * Data store tree manipulation utilities. + */ public final class StoreUtils { private static final int STRINGTREE_INDENT = 4; - private final static Function, Object> EXTRACT_IDENTIFIER = new Function, Object>() { - @Override - public Object apply(final Identifiable input) { - return input.getIdentifier(); - } - }; - private StoreUtils() { throw new UnsupportedOperationException("Utility class should not be instantiated"); } - /* - * Suppressing warnings here allows us to fool the compiler enough - * such that we can reuse a single function for all applicable types - * and present it in a type-safe manner to our users. + /** + * Convert a data subtree under a node into a human-readable string format. + * + * @param node Data subtree root + * @return String containing a human-readable form of the subtree. */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static Function, V> identifierExtractor() { - return (Function) EXTRACT_IDENTIFIER; - } - - public static final UnsignedLong increase(final UnsignedLong original) { - return original.plus(UnsignedLong.ONE); - } - - public static final InstanceIdentifier append(final InstanceIdentifier parent, final PathArgument arg) { - return new InstanceIdentifier(ImmutableList. builder().addAll(parent.getPath()).add(arg).build()); - } - - public static Set toIdentifierSet(final Iterable> children) { - return FluentIterable.from(children).transform(StoreUtils. identifierExtractor()).toSet(); - } - public static String toStringTree(final NormalizedNode node) { - StringBuilder builder = new StringBuilder(); + final StringBuilder builder = new StringBuilder(); toStringTree(builder, node, 0); return builder.toString(); } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/TreeNodeUtils.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/TreeNodeUtils.java index 732352dd34..99982d318c 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/TreeNodeUtils.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/TreeNodeUtils.java @@ -13,6 +13,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.opendaylight.controller.md.sal.dom.store.impl.tree.spi.TreeNode; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; @@ -21,6 +22,9 @@ import com.google.common.base.Preconditions; import com.google.common.base.Predicate; import com.google.common.base.Predicates; +/** + * A set of utility methods for interacting with {@link TreeNode} objects. + */ public final class TreeNodeUtils { private TreeNodeUtils() { throw new UnsupportedOperationException("Utility class should not be instantiated"); @@ -32,7 +36,6 @@ public final class TreeNodeUtils { * @param tree Data Tree * @param path Path to the node * @return Optional with node if the node is present in tree, {@link Optional#absent()} otherwise. - * */ public static > Optional findNode(final T tree, final InstanceIdentifier path) { Optional current = Optional. of(tree); diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTreeModification.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTreeModification.java index c05ed4b442..f7e95b84bd 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTreeModification.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/InMemoryDataTreeModification.java @@ -131,7 +131,7 @@ final class InMemoryDataTreeModification implements DataTreeModification { } @Override - public synchronized void seal() { + public synchronized void ready() { Preconditions.checkState(!sealed, "Attempted to seal an already-sealed Data Tree."); sealed = true; rootNode.seal(); diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NodeModification.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NodeModification.java index 2639d050ef..e7e79f8916 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NodeModification.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NodeModification.java @@ -14,8 +14,31 @@ import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; import com.google.common.base.Optional; +/** + * Internal interface representing a modification action of a particular node. + * It is used by the validation code to allow for a read-only view of the + * modification tree as we should never modify that during validation. + */ interface NodeModification extends Identifiable { + /** + * Get the type of modification. + * + * @return Modification type. + */ ModificationType getType(); + + /** + * Get the original tree node to which the modification is to be applied. + * + * @return The original node, or {@link Optional#absent()} if the node is + * a new node. + */ Optional getOriginal(); + + /** + * Get a read-only view of children nodes. + * + * @return Iterable of all children nodes. + */ Iterable getChildren(); } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NoopDataTreeCandidate.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NoopDataTreeCandidate.java index 2ef85cbcb7..227684ae35 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NoopDataTreeCandidate.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NoopDataTreeCandidate.java @@ -18,6 +18,11 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import com.google.common.base.Optional; import com.google.common.base.Preconditions; +/** + * Internal utility class for an empty candidate. We instantiate this class + * for empty modifications, saving memory and processing speed. Instances + * of this class are explicitly recognized and processing of them is skipped. + */ final class NoopDataTreeCandidate extends AbstractDataTreeCandidate { private static final DataTreeCandidateNode ROOT = new DataTreeCandidateNode() { @Override diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NormalizedNodeContainerModificationStrategy.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NormalizedNodeContainerModificationStrategy.java index b70c5d18dc..5c6aeace56 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NormalizedNodeContainerModificationStrategy.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/data/NormalizedNodeContainerModificationStrategy.java @@ -13,7 +13,6 @@ import java.util.Map; import org.opendaylight.controller.md.sal.dom.store.impl.tree.DataPreconditionFailedException; import org.opendaylight.controller.md.sal.dom.store.impl.tree.ModificationType; -import org.opendaylight.controller.md.sal.dom.store.impl.tree.StoreUtils; import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.DataNodeContainerModificationStrategy.ListEntryModificationStrategy; import org.opendaylight.controller.md.sal.dom.store.impl.tree.data.ValueNodeModificationStrategy.LeafSetEntryModificationStrategy; import org.opendaylight.controller.md.sal.dom.store.impl.tree.spi.MutableTreeNode; @@ -178,7 +177,7 @@ abstract class NormalizedNodeContainerModificationStrategy extends SchemaAwareAp final PathArgument childId = childMod.getIdentifier(); final Optional childMeta = currentMeta.getChild(childId); - InstanceIdentifier childPath = StoreUtils.append(path, childId); + InstanceIdentifier childPath = path.node(childId); resolveChildOperation(childId).checkApplicable(childPath, childMod, childMeta); } } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/AbstractTreeNode.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/AbstractTreeNode.java index 1444f0c6a8..522bf3c84d 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/AbstractTreeNode.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/AbstractTreeNode.java @@ -12,7 +12,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import com.google.common.base.Preconditions; -/* +/** * A very basic data tree node. */ abstract class AbstractTreeNode implements TreeNode { diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/MutableTreeNode.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/MutableTreeNode.java index 7ab309607b..087f4de666 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/MutableTreeNode.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/MutableTreeNode.java @@ -17,9 +17,43 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; * any interactions with it will result in undefined behavior. */ public interface MutableTreeNode extends StoreTreeNode { + /** + * Set the data component of the node. + * + * @param data New data component, may not be null. + */ void setData(NormalizedNode data); + + /** + * Set the new subtree version. This is typically invoked when the user + * has modified some of this node's children. + * + * @param subtreeVersion New subtree version. + */ void setSubtreeVersion(Version subtreeVersion); + + /** + * Add a new child node. This acts as add-or-replace operation, e.g. it + * succeeds even if a conflicting child is already present. + * + * @param child New child node. + */ void addChild(TreeNode child); + + /** + * Remove a child node. This acts as delete-or-nothing operation, e.g. it + * succeeds even if the corresponding child is not present. + * + * @param id Child identificator. + */ void removeChild(PathArgument id); + + /** + * Finish node modification and return a read-only view of this node. After + * this method is invoked, any further calls to this object's method result + * in undefined behavior. + * + * @return Read-only view of this node. + */ TreeNode seal(); } diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/TreeNode.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/TreeNode.java index b0beb8168b..def1958123 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/TreeNode.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/TreeNode.java @@ -12,7 +12,7 @@ import org.opendaylight.yangtools.concepts.Identifiable; import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -/* +/** * A very basic data tree node. It has a version (when it was last modified), * a subtree version (when any of its children were modified) and some read-only * data. diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/ValueNode.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/ValueNode.java index 7194faadf6..d89928b51e 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/ValueNode.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/tree/spi/ValueNode.java @@ -14,6 +14,11 @@ import org.slf4j.LoggerFactory; import com.google.common.base.Optional; +/** + * Concretization of AbstractTreeNode for leaf nodes which only contain data. + * Instances of this class report all children as absent, subtree version + * equal to this node's version and do not support mutable view. + */ final class ValueNode extends AbstractTreeNode { private static final Logger LOG = LoggerFactory.getLogger(ValueNode.class);