Added destroy() method to DistributedPrimitive interface
Implement replace method in ConsistentMap
Using Versioned#valueOrNull in place of Versioned#valueOrElse where appropriate
Change-Id: Ief3f3547d589d35f5c821a1c47035f91078e8316
diff --git a/core/api/src/main/java/org/onosproject/cluster/DefaultPartition.java b/core/api/src/main/java/org/onosproject/cluster/DefaultPartition.java
index 5832608..07a5d71 100644
--- a/core/api/src/main/java/org/onosproject/cluster/DefaultPartition.java
+++ b/core/api/src/main/java/org/onosproject/cluster/DefaultPartition.java
@@ -42,6 +42,11 @@
this.members = ImmutableSet.copyOf(members);
}
+ public DefaultPartition(Partition other) {
+ this.id = checkNotNull(other.getId());
+ this.members = ImmutableSet.copyOf(other.getMembers());
+ }
+
@Override
public PartitionId getId() {
return this.id;
diff --git a/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMap.java b/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMap.java
index d83c553..2bec77a 100644
--- a/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMap.java
+++ b/core/api/src/main/java/org/onosproject/store/service/AsyncConsistentMap.java
@@ -37,12 +37,12 @@
* a temporary disruption in network connectivity between participating nodes
* or due to a node being temporarily down.
* </p><p>
- * All values stored in this map are versioned and the API supports optimistic
- * concurrency by allowing conditional updates that take into consideration
- * the version or value that was previously read.
+ * All values stored in this map are {@link Versioned versioned} and the API
+ * supports optimistic concurrency by allowing conditional updates that take into
+ * consideration the version or value that was previously read.
* </p><p>
* This map does not allow null values. All methods can throw a ConsistentMapException
- * (which extends RuntimeException) to indicate failures.
+ * (which extends {@code RuntimeException}) to indicate failures.
* <p>
* All methods of this interface return a {@link CompletableFuture future} immediately
* after a successful invocation. The operation itself is executed asynchronous and
@@ -56,6 +56,11 @@
return DistributedPrimitive.Type.CONSISTENT_MAP;
}
+ @Override
+ default CompletableFuture<Void> destroy() {
+ return clear();
+ }
+
/**
* Returns the number of entries in the map.
*
diff --git a/core/api/src/main/java/org/onosproject/store/service/ConsistentMap.java b/core/api/src/main/java/org/onosproject/store/service/ConsistentMap.java
index 19f8954..805c995 100644
--- a/core/api/src/main/java/org/onosproject/store/service/ConsistentMap.java
+++ b/core/api/src/main/java/org/onosproject/store/service/ConsistentMap.java
@@ -25,24 +25,11 @@
import java.util.function.Predicate;
/**
- * A distributed, strongly consistent key-value map.
- * <p>
- * This map offers strong read-after-update (where update == create/update/delete)
- * consistency. All operations to the map are serialized and applied in a consistent
- * manner.
- * <p>
- * The stronger consistency comes at the expense of availability in
- * the event of a network partition. A network partition can be either due to
- * a temporary disruption in network connectivity between participating nodes
- * or due to a node being temporarily down.
- * </p><p>
- * All values stored in this map are versioned and the API supports optimistic
- * concurrency by allowing conditional updates that take into consideration
- * the version or value that was previously read.
- * </p><p>
- * This map does not allow null values. All methods can throw a ConsistentMapException
- * (which extends RuntimeException) to indicate failures.
+ * {@code ConsistentMap} provides the same functionality as {@link AsyncConsistentMap} with
+ * the only difference that all its methods block until the corresponding operation completes.
*
+ * @param <K> type of key
+ * @param <V> type of value
*/
public interface ConsistentMap<K, V> extends DistributedPrimitive {
diff --git a/core/api/src/main/java/org/onosproject/store/service/DistributedPrimitive.java b/core/api/src/main/java/org/onosproject/store/service/DistributedPrimitive.java
index 6a6c09e..ed2e9c9 100644
--- a/core/api/src/main/java/org/onosproject/store/service/DistributedPrimitive.java
+++ b/core/api/src/main/java/org/onosproject/store/service/DistributedPrimitive.java
@@ -15,6 +15,8 @@
*/
package org.onosproject.store.service;
+import java.util.concurrent.CompletableFuture;
+
import org.onosproject.core.ApplicationId;
/**
@@ -76,4 +78,15 @@
default ApplicationId applicationId() {
return null;
}
+
+ /**
+ * Purges state associated with this primitive.
+ * <p>
+ * Implementations can override and provide appropriate clean up logic for purging
+ * any state state associated with the primitive. Whether modifications made within the
+ * destroy method have local or global visibility is left unspecified.
+ */
+ default CompletableFuture<Void> destroy() {
+ return CompletableFuture.completedFuture(null);
+ }
}
diff --git a/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMap.java b/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMap.java
index 2369619..5399422 100644
--- a/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMap.java
+++ b/core/api/src/main/java/org/onosproject/store/service/EventuallyConsistentMap.java
@@ -201,12 +201,4 @@
* @param listener listener to deregister for events
*/
void removeListener(EventuallyConsistentMapListener<K, V> listener);
-
- /**
- * Shuts down the map and breaks communication between different instances.
- * This allows the map objects to be cleaned up and garbage collected.
- * Calls to any methods on the map subsequent to calling destroy() will
- * throw a {@link java.lang.RuntimeException}.
- */
- void destroy();
}
diff --git a/core/api/src/main/java/org/onosproject/store/service/Synchronous.java b/core/api/src/main/java/org/onosproject/store/service/Synchronous.java
index be65382..d938e48 100644
--- a/core/api/src/main/java/org/onosproject/store/service/Synchronous.java
+++ b/core/api/src/main/java/org/onosproject/store/service/Synchronous.java
@@ -15,6 +15,8 @@
*/
package org.onosproject.store.service;
+import java.util.concurrent.CompletableFuture;
+
/**
* DistributedPrimitive that is a synchronous (blocking) version of
* another.
@@ -38,4 +40,9 @@
public Type type() {
return primitive.type();
}
+
+ @Override
+ public CompletableFuture<Void> destroy() {
+ return primitive.destroy();
+ }
}
diff --git a/core/api/src/test/java/org/onosproject/store/service/EventuallyConsistentMapAdapter.java b/core/api/src/test/java/org/onosproject/store/service/EventuallyConsistentMapAdapter.java
index 1f4af9e..d03213a 100644
--- a/core/api/src/test/java/org/onosproject/store/service/EventuallyConsistentMapAdapter.java
+++ b/core/api/src/test/java/org/onosproject/store/service/EventuallyConsistentMapAdapter.java
@@ -18,6 +18,7 @@
import java.util.Collection;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;
import org.onosproject.store.service.DistributedPrimitive.Type;
@@ -118,7 +119,7 @@
}
@Override
- public void destroy() {
-
+ public CompletableFuture<Void> destroy() {
+ return CompletableFuture.completedFuture(null);
}
}