Package org.onosproject.store.service
Interface AsyncDocumentTree<V>
-
- Type Parameters:
V
- document tree value type
- All Superinterfaces:
DistributedPrimitive
,Transactional<NodeUpdate<V>>
@NotThreadSafe public interface AsyncDocumentTree<V> extends DistributedPrimitive, Transactional<NodeUpdate<V>>
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 CompletableFuture<Void>
addListener(DocumentPath path, DocumentTreeListener<V> listener)
Registers a listener to be notified when the subtree rooted at the specified path is modified.default CompletableFuture<Void>
addListener(DocumentTreeListener<V> listener)
Registers a listener to be notified when the tree is modified.default DocumentTree<V>
asDocumentTree()
Returns a newDocumentTree
that is backed by this instance.default DocumentTree<V>
asDocumentTree(long timeoutMillis)
Returns a newDocumentTree
that is backed by this instance.CompletableFuture<Boolean>
create(DocumentPath path, V value)
Creates a document tree node if one does not exist already.CompletableFuture<Boolean>
createRecursive(DocumentPath path, V value)
Creates a document tree node recursively by creating all missing intermediate nodes in the path.CompletableFuture<Versioned<V>>
get(DocumentPath path)
Returns the value of the tree node at specified path.CompletableFuture<Map<String,Versioned<V>>>
getChildren(DocumentPath path)
Returns the children of node at specified path in the form of a mapping from child name to child value.default DistributedPrimitive.Type
primitiveType()
Returns the type of primitive.CompletableFuture<Void>
removeListener(DocumentTreeListener<V> listener)
Unregisters a previously added listener.CompletableFuture<Versioned<V>>
removeNode(DocumentPath path)
Removes the node with the specified path.CompletableFuture<Boolean>
replace(DocumentPath path, V newValue, long version)
Conditionally updates a tree node if the current version matches a specified version.CompletableFuture<Boolean>
replace(DocumentPath path, V newValue, V currentValue)
Conditionally updates a tree node if the current node value matches a specified version.DocumentPath
root()
Returns thepath
to root of the tree.CompletableFuture<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
-
Methods inherited from interface org.onosproject.store.service.Transactional
begin, commit, prepare, prepareAndCommit, rollback
-
-
-
-
Method Detail
-
primitiveType
default DistributedPrimitive.Type primitiveType()
Description copied from interface:DistributedPrimitive
Returns the type of primitive.- Specified by:
primitiveType
in interfaceDistributedPrimitive
- Returns:
- primitive type
-
root
DocumentPath root()
Returns thepath
to root of the tree.- Returns:
- path to root of the tree
-
getChildren
CompletableFuture<Map<String,Versioned<V>>> getChildren(DocumentPath path)
Returns the children of node at specified path in the form of a mapping from child name to child value.- Parameters:
path
- path to the node- Returns:
- future for mapping from child name to child value
- Throws:
NoSuchDocumentPathException
- if the path does not point to a valid node
-
get
CompletableFuture<Versioned<V>> get(DocumentPath path)
Returns the value of the tree node at specified path.- Parameters:
path
- path to the node- Returns:
- future that will be either be completed with node's
versioned
value ornull
if path does not point to a valid node
-
set
CompletableFuture<Versioned<V>> set(DocumentPath path, V value)
Creates or updates a document tree node.- Parameters:
path
- path to the nodevalue
- value to be associated with the node (null
is a valid value)- Returns:
- future that will either be completed with the previous
versioned
value ornull
if there was no node previously at that path. Future will be completed with aIllegalDocumentModificationException
if the parent node (for the node to create/update) does not exist
-
create
CompletableFuture<Boolean> create(DocumentPath path, V value)
Creates a document tree node if one does not exist already.- Parameters:
path
- path to the nodevalue
- the non-null value to be associated with the node- Returns:
- future that is completed with
true
if the new node was successfully created. Future will be completed withfalse
if a node already exists at the specified path. Future will be completed exceptionally with aIllegalDocumentModificationException
if the parent node (for the node to create) does not exist
-
createRecursive
CompletableFuture<Boolean> createRecursive(DocumentPath path, V value)
Creates a document tree node recursively by creating all missing intermediate nodes in the path.- Parameters:
path
- path to the nodevalue
- value to be associated with the node (null
is a valid value)- Returns:
- future that is completed with
true
if the new node was successfully created. Future will be completed withfalse
if a node already exists at the specified path
-
replace
CompletableFuture<Boolean> replace(DocumentPath path, V newValue, long version)
Conditionally updates a tree node if the current version matches a specified version.- Parameters:
path
- path to the nodenewValue
- value to associate with the node (null
is a valid value)version
- current version of the node for update to occur- Returns:
- future that is either completed with
true
if the update was made orfalse
if update did not happen
-
replace
CompletableFuture<Boolean> replace(DocumentPath path, V newValue, V currentValue)
Conditionally updates a tree node if the current node value matches a specified version.- Parameters:
path
- path to the nodenewValue
- value to associate with the node (null
is a valid value)currentValue
- current value of the node for update to occur- Returns:
- future that is either completed with
true
if the update was made orfalse
if update did not happen
-
removeNode
CompletableFuture<Versioned<V>> removeNode(DocumentPath path)
Removes the node with the specified path.- Parameters:
path
- path to the node- Returns:
- future for the previous value. Future will be completed with a
IllegalDocumentModificationException
if the node to be removed is either the root node or has one or more children. Future will be completed with aNoSuchDocumentPathException
if the node to be removed does not exist
-
addListener
CompletableFuture<Void> addListener(DocumentPath path, DocumentTreeListener<V> listener)
Registers a listener to be notified when the subtree rooted at the specified path is modified.- Parameters:
path
- path to the nodelistener
- listener to be notified- Returns:
- a future that is completed when the operation completes
-
removeListener
CompletableFuture<Void> removeListener(DocumentTreeListener<V> listener)
Unregisters a previously added listener.- Parameters:
listener
- listener to unregister- Returns:
- a future that is completed when the operation completes
-
addListener
default CompletableFuture<Void> addListener(DocumentTreeListener<V> listener)
Registers a listener to be notified when the tree is modified.- Parameters:
listener
- listener to be notified- Returns:
- a future that is completed when the operation completes
-
asDocumentTree
default DocumentTree<V> asDocumentTree()
Returns a newDocumentTree
that is backed by this instance.- Returns:
- new
DocumentTree
instance
-
asDocumentTree
default DocumentTree<V> asDocumentTree(long timeoutMillis)
Returns a newDocumentTree
that is backed by this instance.- Parameters:
timeoutMillis
- timeout duration for the returned DocumentTree operations- Returns:
- new
DocumentTree
instance
-
-