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 backingAsyncDocumentTree
then 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 void
addListener(DocumentPath path, DocumentTreeListener<V> listener)
Registers a listener to be notified when a subtree rooted at the specified path is modified.void
addListener(DocumentTreeListener<V> listener)
Registers a listener to be notified when the tree is modified.boolean
create(DocumentPath path, V value)
Creates a document tree node if one does not exist already.boolean
createRecursive(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.Map<String,Versioned<V>>
getChildren(DocumentPath path)
Returns the child values for this node.void
removeListener(DocumentTreeListener<V> listener)
Unregisters a previously added listener.Versioned<V>
removeNode(DocumentPath path)
Removes the node with the specified path.boolean
replace(DocumentPath path, V newValue, long version)
Conditionally updates a tree node if the current version matches a specified version.boolean
replace(DocumentPath path, V newValue, V currentValue)
Conditionally updates a tree node if the current value matches a specified value.DocumentPath
root()
Returns thepath
to 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:DocumentTree
Returns thepath
to root of the tree.- Specified by:
root
in interfaceDocumentTree<V>
- Returns:
- path to root of the tree
-
getChildren
public Map<String,Versioned<V>> getChildren(DocumentPath path)
Description copied from interface:DocumentTree
Returns the child values for this node.- Specified by:
getChildren
in 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:DocumentTree
Returns a document tree node.- Specified by:
get
in interfaceDocumentTree<V>
- Parameters:
path
- path to node- Returns:
- node value or
null
if path does not point to a valid node
-
set
public Versioned<V> set(DocumentPath path, V value)
Description copied from interface:DocumentTree
Creates or updates a document tree node.- Specified by:
set
in 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
null
if there was no previous mapping
-
create
public boolean create(DocumentPath path, V value)
Description copied from interface:DocumentTree
Creates a document tree node if one does not exist already.- Specified by:
create
in interfaceDocumentTree<V>
- Parameters:
path
- path for the node to createvalue
- the non-null value to be associated with the key- Returns:
- returns
true
if the mapping could be added successfully,false
otherwise
-
createRecursive
public boolean createRecursive(DocumentPath path, V value)
Description copied from interface:DocumentTree
Creates a document tree node by first creating any missing intermediate nodes in the path.- Specified by:
createRecursive
in interfaceDocumentTree<V>
- Parameters:
path
- path for the node to createvalue
- the non-null value to be associated with the key- Returns:
- returns
true
if the mapping could be added successfully,false
if a node already exists at that path
-
replace
public boolean replace(DocumentPath path, V newValue, long version)
Description copied from interface:DocumentTree
Conditionally updates a tree node if the current version matches a specified version.- Specified by:
replace
in 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
true
if the update was made and the tree was modified,false
otherwise
-
replace
public boolean replace(DocumentPath path, V newValue, V currentValue)
Description copied from interface:DocumentTree
Conditionally updates a tree node if the current value matches a specified value.- Specified by:
replace
in 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
true
if the update was made and the tree was modified,false
otherwise. This method returnsfalse
if the newValue and currentValue are same.
-
removeNode
public Versioned<V> removeNode(DocumentPath path)
Description copied from interface:DocumentTree
Removes the node with the specified path.- Specified by:
removeNode
in interfaceDocumentTree<V>
- Parameters:
path
- path for the node to remove- Returns:
- the previous value of the node or
null
if it did not exist
-
addListener
public void addListener(DocumentPath path, DocumentTreeListener<V> listener)
Description copied from interface:DocumentTree
Registers a listener to be notified when a subtree rooted at the specified path is modified.- Specified by:
addListener
in 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:DocumentTree
Unregisters a previously added listener.- Specified by:
removeListener
in interfaceDocumentTree<V>
- Parameters:
listener
- listener to unregister
-
addListener
public void addListener(DocumentTreeListener<V> listener)
Description copied from interface:DocumentTree
Registers a listener to be notified when the tree is modified.- Specified by:
addListener
in interfaceDocumentTree<V>
- Parameters:
listener
- listener to be notified
-
-