[ONOS-6869] Move blocking DocumentTree to core primitives package and implement default methods for constructing blocking primitives
Change-Id: I9c227a690a120dba7d9d89c6c9178c8b357b52aa
diff --git a/core/api/src/main/java/org/onosproject/store/service/AsyncDocumentTree.java b/core/api/src/main/java/org/onosproject/store/service/AsyncDocumentTree.java
index 00bccda..04f015a 100644
--- a/core/api/src/main/java/org/onosproject/store/service/AsyncDocumentTree.java
+++ b/core/api/src/main/java/org/onosproject/store/service/AsyncDocumentTree.java
@@ -21,6 +21,8 @@
import javax.annotation.concurrent.NotThreadSafe;
+import org.onosproject.store.primitives.DefaultDocumentTree;
+
/**
* A hierarchical <a href="https://en.wikipedia.org/wiki/Document_Object_Model">document tree</a> data structure.
*
@@ -29,6 +31,11 @@
@NotThreadSafe
public interface AsyncDocumentTree<V> extends DistributedPrimitive {
+ @Override
+ default Type primitiveType() {
+ return Type.DOCUMENT_TREE;
+ }
+
/**
* Returns the {@link DocumentPath path} to root of the tree.
*
@@ -148,4 +155,23 @@
default CompletableFuture<Void> addListener(DocumentTreeListener<V> listener) {
return addListener(root(), listener);
}
+
+ /**
+ * Returns a new {@link DocumentTree} that is backed by this instance.
+ *
+ * @return new {@code DocumentTree} instance
+ */
+ default DocumentTree<V> asDocumentTree() {
+ return asDocumentTree(DistributedPrimitive.DEFAULT_OPERATION_TIMEOUT_MILLIS);
+ }
+
+ /**
+ * Returns a new {@link DocumentTree} that is backed by this instance.
+ *
+ * @param timeoutMillis timeout duration for the returned DocumentTree operations
+ * @return new {@code DocumentTree} instance
+ */
+ default DocumentTree<V> asDocumentTree(long timeoutMillis) {
+ return new DefaultDocumentTree<V>(this, timeoutMillis);
+ }
}