Creating new creators for multimap primitive and a name based getter for treemap primitive.
Change-Id: I981b3f1f8ee01fbdd0677c3eedc3d5024b8bcf1e
diff --git a/core/api/src/main/java/org/onosproject/store/primitives/DistributedPrimitiveCreator.java b/core/api/src/main/java/org/onosproject/store/primitives/DistributedPrimitiveCreator.java
index b0a25f2..2e986c4 100644
--- a/core/api/src/main/java/org/onosproject/store/primitives/DistributedPrimitiveCreator.java
+++ b/core/api/src/main/java/org/onosproject/store/primitives/DistributedPrimitiveCreator.java
@@ -20,6 +20,7 @@
import org.onosproject.store.service.AsyncAtomicCounter;
import org.onosproject.store.service.AsyncAtomicValue;
import org.onosproject.store.service.AsyncConsistentMap;
+import org.onosproject.store.service.AsyncConsistentMultimap;
import org.onosproject.store.service.AsyncConsistentTreeMap;
import org.onosproject.store.service.AsyncDistributedSet;
import org.onosproject.store.service.AsyncDocumentTree;
@@ -51,7 +52,20 @@
* @param <V> value type
* @return distributedTreeMap
*/
- <V> AsyncConsistentTreeMap<V> newAsyncConsistentTreeMap(String name, Serializer serializer);
+ <V> AsyncConsistentTreeMap<V> newAsyncConsistentTreeMap(
+ String name, Serializer serializer);
+
+ /**
+ * Creates a new set backed {@code AsyncConsistentMultimap}.
+ *
+ * @param name multimap name
+ * @param serializer serializer to use for serializing/deserializing
+ * @param <K> key type
+ * @param <V> value type
+ * @return set backed distributedMultimap
+ */
+ <K, V> AsyncConsistentMultimap<K, V> newAsyncConsistentSetMultimap(
+ String name, Serializer serializer);
/**
* Creates a new {@code AsyncAtomicCounter}.
diff --git a/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMultimap.java b/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMultimap.java
index a0f3b84..da121c9 100644
--- a/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMultimap.java
+++ b/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMultimap.java
@@ -17,6 +17,7 @@
package org.onosproject.store.service;
import com.google.common.collect.Multiset;
+import org.onosproject.store.primitives.DefaultConsistentMultimap;
import java.util.Collection;
import java.util.Map;
@@ -229,4 +230,32 @@
* values, the returned map may be empty.
*/
CompletableFuture<Map<K, Collection<V>>> asMap();
+
+ /**
+ * Returns a {@code ConsistentMultimap} instance that wraps this map. All
+ * calls will have the same behavior as this map but will be blocking
+ * instead of asynchronous. If a call does not complete within the
+ * default timeout an exception will be produced.
+ *
+ * @return a {@code ConsistentMultimap} which wraps this map, providing
+ * synchronous access to this map
+ */
+ default ConsistentMultimap<K, V> asMultimap() {
+ return asMultimap(DEFAULT_OPERTATION_TIMEOUT_MILLIS);
+ }
+
+ /**
+ * Returns a {@code ConsistentMultimap} instance that wraps this map. All
+ * calls will have the same behavior as this map but will be blocking
+ * instead of asynchronous. If a call does not complete within the
+ * specified timeout an exception will be produced.
+ *
+ * @param timeoutMillis the number of millis to block while waiting for a
+ * call to return
+ * @return a {@code ConsistentMultimap} which wraps this map, providing
+ * synchronous access to this map
+ */
+ default ConsistentMultimap<K, V> asMultimap(long timeoutMillis) {
+ return new DefaultConsistentMultimap(this, timeoutMillis);
+ }
}
diff --git a/core/api/src/main/java/org/onosproject/store/service/ConsistentMultimapBuilder.java b/core/api/src/main/java/org/onosproject/store/service/ConsistentMultimapBuilder.java
new file mode 100644
index 0000000..1881d795
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/store/service/ConsistentMultimapBuilder.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.store.service;
+
+import org.onosproject.store.primitives.DistributedPrimitiveBuilder;
+
+/**
+ * A builder class for {@code AsyncConsistentMultimap}.
+ */
+public abstract class ConsistentMultimapBuilder<K, V>
+ extends DistributedPrimitiveBuilder<ConsistentMultimapBuilder<K, V>,
+ ConsistentMultimap<K, V>> {
+
+ private boolean purgeOnUninstall = false;
+
+ public ConsistentMultimapBuilder() {
+ super(DistributedPrimitive.Type.CONSISTENT_MULTIMAP);
+ }
+
+ /**
+ * Clears multimap contents when the owning application is uninstalled.
+ *
+ * @return this builder
+ */
+ public ConsistentMultimapBuilder<K, V> withPurgeOnUninstall() {
+ purgeOnUninstall = true;
+ return this;
+ }
+
+ /**
+ * Returns if multimap entries need to be cleared when owning application
+ * is uninstalled.
+ *
+ * @return true if items are to be cleared on uninstall
+ */
+ public boolean purgeOnUninstall() {
+ return purgeOnUninstall;
+ }
+
+ /**
+ * Builds the distributed multimap based on the configuration options
+ * supplied to this builder.
+ *
+ * @return new distributed multimap
+ * @throws java.lang.RuntimeException if a mandatory parameter is missing
+ */
+ public abstract AsyncConsistentMultimap<K, V> buildMultimap();
+}
diff --git a/core/api/src/main/java/org/onosproject/store/service/StorageService.java b/core/api/src/main/java/org/onosproject/store/service/StorageService.java
index 21fdfda..d532be2 100644
--- a/core/api/src/main/java/org/onosproject/store/service/StorageService.java
+++ b/core/api/src/main/java/org/onosproject/store/service/StorageService.java
@@ -60,6 +60,15 @@
<V> ConsistentTreeMapBuilder<V> consistentTreeMapBuilder();
/**
+ * Creates a new {@code AsyncConsistentSetMultimapBuilder}.
+ *
+ * @param <K> key type
+ * @param <V> value type
+ * @return builder for a set based async consistent multimap
+ */
+ <K, V> ConsistentMultimapBuilder<K, V> consistentMultimapBuilder();
+
+ /**
* Creates a new DistributedSetBuilder.
*
* @param <E> set element type
@@ -136,6 +145,30 @@
*/
<V> AsyncDocumentTree<V> getDocumentTree(String name, Serializer serializer);
+ /** Returns a set backed instance of {@code AsyncConsistentMultimap} with
+ * the specified name.
+ *
+ * @param name the multimap name
+ * @param serializer serializer
+ * @param <K> key type
+ * @param <V> value type
+ * @return set backed {@code AsyncConsistentMultimap} instance
+ */
+ <K, V> AsyncConsistentMultimap<K, V> getAsyncSetMultimap(String name,
+ Serializer serializer);
+
+ /**
+ * Returns an instance of {@code AsyncConsistentTreeMap} with the specified
+ * name.
+ *
+ * @param name the treemap name
+ * @param serializer serializer
+ * @param <V> value type
+ * @return set backed {@code AsyncConsistentTreeMap} instance
+ */
+ <V> AsyncConsistentTreeMap<V> getAsyncTreeMap(String name,
+ Serializer serializer);
+
/**
* Returns an instance of {@code Topic} with specified name.
*
diff --git a/core/api/src/test/java/org/onosproject/store/service/StorageServiceAdapter.java b/core/api/src/test/java/org/onosproject/store/service/StorageServiceAdapter.java
index 29dd72d..c44d3c7 100644
--- a/core/api/src/test/java/org/onosproject/store/service/StorageServiceAdapter.java
+++ b/core/api/src/test/java/org/onosproject/store/service/StorageServiceAdapter.java
@@ -65,11 +65,23 @@
}
@Override
+ public <K, V> AsyncConsistentMultimap<K, V> getAsyncSetMultimap(
+ String name, Serializer serializer) {
+ return null;
+ }
+
+ @Override
public <T> Topic<T> getTopic(String name, Serializer serializer) {
return null;
}
@Override
+ public <V> AsyncConsistentTreeMap<V> getAsyncTreeMap(
+ String name, Serializer serializer) {
+ return null;
+ }
+
+ @Override
public <V> ConsistentTreeMapBuilder<V> consistentTreeMapBuilder() {
return null;
}
@@ -78,4 +90,8 @@
public <V> AsyncDocumentTree<V> getDocumentTree(String name, Serializer serializer) {
return null;
}
+ @Override
+ public <K, V> ConsistentMultimapBuilder<K, V> consistentMultimapBuilder() {
+ return null;
+ }
}