Package org.onosproject.store.primitives
Class DefaultDocumentTree<V>
- java.lang.Object
-
- org.onosproject.store.service.Synchronous<AsyncDocumentTree<V>>
-
- org.onosproject.store.primitives.DefaultDocumentTree<V>
-
- Type Parameters:
V- the type of the values
- All Implemented Interfaces:
DistributedPrimitive,DocumentTree<V>
public class DefaultDocumentTree<V> extends Synchronous<AsyncDocumentTree<V>> implements DocumentTree<V>
Synchronous wrapper for aAsyncDocumentTree. All operations are made by making the equivalent calls to a backingAsyncDocumentTreethen blocking until the operations complete or timeout.
-
-
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
-
-
Constructor Summary
Constructors Constructor Description DefaultDocumentTree(AsyncDocumentTree<V> backingTree, long operationTimeoutMillis)
-
Method Summary
All Methods Instance Methods Concrete 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.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.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 class org.onosproject.store.service.Synchronous
destroy, name, primitiveType
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.onosproject.store.service.DistributedPrimitive
addStatusChangeListener, applicationId, destroy, name, removeStatusChangeListener, statusChangeListeners
-
Methods inherited from interface org.onosproject.store.service.DocumentTree
primitiveType
-
-
-
-
Constructor Detail
-
DefaultDocumentTree
public DefaultDocumentTree(AsyncDocumentTree<V> backingTree, long operationTimeoutMillis)
-
-
Method Detail
-
root
public DocumentPath root()
Description copied from interface:DocumentTreeReturns thepathto root of the tree.- Specified by:
rootin interfaceDocumentTree<V>- Returns:
- path to root of the tree
-
getChildren
public java.util.Map<java.lang.String,Versioned<V>> getChildren(DocumentPath path)
Description copied from interface:DocumentTreeReturns the child values for this node.- Specified by:
getChildrenin interfaceDocumentTree<V>- Parameters:
path- path to the node- Returns:
- mapping from a child name to its value
-
get
public Versioned<V> get(DocumentPath path)
Description copied from interface:DocumentTreeReturns a document tree node.- Specified by:
getin interfaceDocumentTree<V>- Parameters:
path- path to node- Returns:
- node value or
nullif path does not point to a valid node
-
set
public Versioned<V> set(DocumentPath path, V value)
Description copied from interface:DocumentTreeCreates or updates a document tree node.- Specified by:
setin interfaceDocumentTree<V>- 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
-
create
public boolean create(DocumentPath path, V value)
Description copied from interface:DocumentTreeCreates a document tree node if one does not exist already.- Specified by:
createin interfaceDocumentTree<V>- 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
-
createRecursive
public boolean createRecursive(DocumentPath path, V value)
Description copied from interface:DocumentTreeCreates a document tree node by first creating any missing intermediate nodes in the path.- Specified by:
createRecursivein interfaceDocumentTree<V>- 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
-
replace
public boolean replace(DocumentPath path, V newValue, long version)
Description copied from interface:DocumentTreeConditionally updates a tree node if the current version matches a specified version.- Specified by:
replacein interfaceDocumentTree<V>- 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
-
replace
public boolean replace(DocumentPath path, V newValue, V currentValue)
Description copied from interface:DocumentTreeConditionally updates a tree node if the current value matches a specified value.- Specified by:
replacein interfaceDocumentTree<V>- 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.
-
removeNode
public Versioned<V> removeNode(DocumentPath path)
Description copied from interface:DocumentTreeRemoves the node with the specified path.- Specified by:
removeNodein interfaceDocumentTree<V>- Parameters:
path- path for the node to remove- Returns:
- the previous value of the node or
nullif it did not exist
-
addListener
public void addListener(DocumentPath path, DocumentTreeListener<V> listener)
Description copied from interface:DocumentTreeRegisters a listener to be notified when a subtree rooted at the specified path is modified.- Specified by:
addListenerin interfaceDocumentTree<V>- Parameters:
path- path to root of subtree to monitor for updateslistener- listener to be notified
-
removeListener
public void removeListener(DocumentTreeListener<V> listener)
Description copied from interface:DocumentTreeUnregisters a previously added listener.- Specified by:
removeListenerin interfaceDocumentTree<V>- Parameters:
listener- listener to unregister
-
addListener
public void addListener(DocumentTreeListener<V> listener)
Description copied from interface:DocumentTreeRegisters a listener to be notified when the tree is modified.- Specified by:
addListenerin interfaceDocumentTree<V>- Parameters:
listener- listener to be notified
-
-