Package org.onosproject.store.service
Interface DocumentTree<V>
-
- Type Parameters:
V- document tree value type
- All Superinterfaces:
DistributedPrimitive
- All Known Implementing Classes:
DefaultDocumentTree
@NotThreadSafe public interface DocumentTree<V> extends DistributedPrimitive
A hierarchical document tree data structure.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.onosproject.store.service.DistributedPrimitive
DistributedPrimitive.Status, DistributedPrimitive.Type
-
-
Field Summary
-
Fields inherited from interface org.onosproject.store.service.DistributedPrimitive
DEFAULT_OPERATION_TIMEOUT_MILLIS
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidaddListener(DocumentPath path, DocumentTreeListener<V> listener)Registers a listener to be notified when a subtree rooted at the specified path is modified.default voidaddListener(DocumentTreeListener<V> listener)Registers a listener to be notified when the tree is modified.booleancreate(DocumentPath path, V value)Creates a document tree node if one does not exist already.booleancreateRecursive(DocumentPath path, V value)Creates a document tree node by first creating any missing intermediate nodes in the path.Versioned<V>get(DocumentPath path)Returns a document tree node.java.util.Map<java.lang.String,Versioned<V>>getChildren(DocumentPath path)Returns the child values for this node.default DistributedPrimitive.TypeprimitiveType()Returns the type of primitive.voidremoveListener(DocumentTreeListener<V> listener)Unregisters a previously added listener.Versioned<V>removeNode(DocumentPath path)Removes the node with the specified path.booleanreplace(DocumentPath path, V newValue, long version)Conditionally updates a tree node if the current version matches a specified version.booleanreplace(DocumentPath path, V newValue, V currentValue)Conditionally updates a tree node if the current value matches a specified value.DocumentPathroot()Returns thepathto root of the tree.Versioned<V>set(DocumentPath path, V value)Creates or updates a document tree node.-
Methods inherited from interface org.onosproject.store.service.DistributedPrimitive
addStatusChangeListener, applicationId, destroy, name, removeStatusChangeListener, statusChangeListeners
-
-
-
-
Method Detail
-
primitiveType
default DistributedPrimitive.Type primitiveType()
Description copied from interface:DistributedPrimitiveReturns the type of primitive.- Specified by:
primitiveTypein interfaceDistributedPrimitive- Returns:
- primitive type
-
root
DocumentPath root()
Returns thepathto root of the tree.- Returns:
- path to root of the tree
-
getChildren
java.util.Map<java.lang.String,Versioned<V>> getChildren(DocumentPath path)
Returns the child values for this node.- Parameters:
path- path to the node- Returns:
- mapping from a child name to its value
- Throws:
NoSuchDocumentPathException- if the path does not point to a valid node
-
get
Versioned<V> get(DocumentPath path)
Returns a document tree node.- Parameters:
path- path to node- Returns:
- node value or
nullif path does not point to a valid node
-
set
Versioned<V> set(DocumentPath path, V value)
Creates or updates a document tree node.- Parameters:
path- path for the node to create or updatevalue- the non-null value to be associated with the key- Returns:
- the previous mapping or
nullif there was no previous mapping - Throws:
NoSuchDocumentPathException- if the parent node (for the node to create/update) does not exist
-
create
boolean create(DocumentPath path, V value)
Creates a document tree node if one does not exist already.- Parameters:
path- path for the node to createvalue- the non-null value to be associated with the key- Returns:
- returns
trueif the mapping could be added successfully,falseotherwise - Throws:
NoSuchDocumentPathException- if the parent node (for the node to create) does not exist
-
createRecursive
boolean createRecursive(DocumentPath path, V value)
Creates a document tree node by first creating any missing intermediate nodes in the path.- Parameters:
path- path for the node to createvalue- the non-null value to be associated with the key- Returns:
- returns
trueif the mapping could be added successfully,falseif a node already exists at that path - Throws:
IllegalDocumentModificationException- ifpathpoints to root
-
replace
boolean replace(DocumentPath path, V newValue, long version)
Conditionally updates a tree node if the current version matches a specified version.- Parameters:
path- path for the node to createnewValue- the non-null value to be associated with the keyversion- current version of the value for update to occur- Returns:
- returns
trueif the update was made and the tree was modified,falseotherwise - Throws:
NoSuchDocumentPathException- if the parent node (for the node to create) does not exist
-
replace
boolean replace(DocumentPath path, V newValue, V currentValue)
Conditionally updates a tree node if the current value matches a specified value.- Parameters:
path- path for the node to createnewValue- the non-null value to be associated with the keycurrentValue- current value for update to occur- Returns:
- returns
trueif the update was made and the tree was modified,falseotherwise. This method returnsfalseif the newValue and currentValue are same. - Throws:
NoSuchDocumentPathException- if the parent node (for the node to create) does not exist
-
removeNode
Versioned<V> removeNode(DocumentPath path)
Removes the node with the specified path.- Parameters:
path- path for the node to remove- Returns:
- the previous value of the node or
nullif it did not exist - Throws:
IllegalDocumentModificationException- if the remove to be removed
-
addListener
void addListener(DocumentPath path, DocumentTreeListener<V> listener)
Registers a listener to be notified when a subtree rooted at the specified path is modified.- Parameters:
path- path to root of subtree to monitor for updateslistener- listener to be notified
-
removeListener
void removeListener(DocumentTreeListener<V> listener)
Unregisters a previously added listener.- Parameters:
listener- listener to unregister
-
addListener
default void addListener(DocumentTreeListener<V> listener)
Registers a listener to be notified when the tree is modified.- Parameters:
listener- listener to be notified
-
-