Added DistributedPrimitive interface
Added AsyncDistributedSet that provides async set operations
Change-Id: I83494075a7973694ea6b7445ff4799b7a1a50641
diff --git a/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicCounter.java b/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicCounter.java
index cfaf314..aa20f4e 100644
--- a/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicCounter.java
+++ b/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicCounter.java
@@ -20,7 +20,12 @@
/**
* An async atomic counter dispenses monotonically increasing values.
*/
-public interface AsyncAtomicCounter {
+public interface AsyncAtomicCounter extends DistributedPrimitive {
+
+ @Override
+ default DistributedPrimitive.Type type() {
+ return DistributedPrimitive.Type.COUNTER;
+ }
/**
* Atomically increment by one the current value.
diff --git a/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicValue.java b/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicValue.java
index 531721a..60d8337 100644
--- a/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicValue.java
+++ b/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicValue.java
@@ -27,7 +27,12 @@
*
* @param <V> value type
*/
-public interface AsyncAtomicValue<V> {
+public interface AsyncAtomicValue<V> extends DistributedPrimitive {
+
+ @Override
+ default DistributedPrimitive.Type type() {
+ return DistributedPrimitive.Type.VALUE;
+ }
/**
* Atomically sets the value to the given updated value if the current value is equal to the expected value.
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 c7b6eac..d83c553 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
@@ -49,7 +49,12 @@
* the returned future will be {@link CompletableFuture#complete completed} when the
* operation finishes.
*/
-public interface AsyncConsistentMap<K, V> {
+public interface AsyncConsistentMap<K, V> extends DistributedPrimitive {
+
+ @Override
+ default DistributedPrimitive.Type type() {
+ return DistributedPrimitive.Type.CONSISTENT_MAP;
+ }
/**
* Returns the number of entries in the map.
diff --git a/core/api/src/main/java/org/onosproject/store/service/AsyncDistributedSet.java b/core/api/src/main/java/org/onosproject/store/service/AsyncDistributedSet.java
new file mode 100644
index 0000000..df63f99
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/store/service/AsyncDistributedSet.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright 2015-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 java.util.Collection;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+
+/**
+ * A distributed collection designed for holding unique elements.
+ * <p>
+ * All methods of {@code AsyncDistributedSet} immediately return a {@link CompletableFuture future}.
+ * The returned future will be {@link CompletableFuture#complete completed} when the operation
+ * completes.
+ *
+ * @param <E> set entry type
+ */
+public interface AsyncDistributedSet<E> extends DistributedPrimitive {
+
+ @Override
+ default DistributedPrimitive.Type type() {
+ return DistributedPrimitive.Type.SET;
+ }
+
+ /**
+ * Registers the specified listener to be notified whenever
+ * the set is updated.
+ *
+ * @param listener listener to notify about set update events
+ */
+ CompletableFuture<Void> addListener(SetEventListener<E> listener);
+
+ /**
+ * Unregisters the specified listener.
+ *
+ * @param listener listener to unregister.
+ * @return CompletableFuture that is completed when the operation completes
+ */
+ CompletableFuture<Void> removeListener(SetEventListener<E> listener);
+
+ /**
+ * Adds the specified element to this set if it is not already present (optional operation).
+ * @param element element to add
+ * @return {@code true} if this set did not already contain the specified element.
+ */
+ CompletableFuture<Boolean> add(E element);
+
+ /**
+ * Removes the specified element to this set if it is present (optional operation).
+ * @param element element to remove
+ * @return {@code true} if this set contained the specified element
+ */
+ CompletableFuture<Boolean> remove(E element);
+
+ /**
+ * Returns the number of elements in the set.
+ * @return size of the set
+ */
+ CompletableFuture<Integer> size();
+
+ /**
+ * Returns if the set is empty.
+ * @return {@code true} if this set is empty
+ */
+ CompletableFuture<Boolean> isEmpty();
+
+ /**
+ * Removes all elements from the set.
+ */
+ CompletableFuture<Void> clear();
+
+ /**
+ * Returns if this set contains the specified element.
+ * @param element element to check
+ * @return {@code true} if this set contains the specified element
+ */
+ CompletableFuture<Boolean> contains(E element);
+
+ /**
+ * Adds all of the elements in the specified collection to this set if they're not
+ * already present (optional operation).
+ * @param c collection containing elements to be added to this set
+ * @return {@code true} if this set contains all elements in the collection
+ */
+ CompletableFuture<Boolean> addAll(Collection<? extends E> c);
+
+ /**
+ * Returns if this set contains all the elements in specified collection.
+ * @param c collection
+ * @return {@code true} if this set contains all elements in the collection
+ */
+ CompletableFuture<Boolean> containsAll(Collection<? extends E> c);
+
+ /**
+ * Retains only the elements in this set that are contained in the specified collection (optional operation).
+ * @param c collection containing elements to be retained in this set
+ * @return {@code true} if this set changed as a result of the call
+ */
+ CompletableFuture<Boolean> retainAll(Collection<? extends E> c);
+
+ /**
+ * Removes from this set all of its elements that are contained in the specified collection (optional operation).
+ * If the specified collection is also a set, this operation effectively modifies this set so that its
+ * value is the asymmetric set difference of the two sets.
+ * @param c collection containing elements to be removed from this set
+ * @return {@code true} if this set changed as a result of the call
+ */
+ CompletableFuture<Boolean> removeAll(Collection<? extends E> c);
+
+ /**
+ * Returns the entries as a immutable set. The returned set is a snapshot and will not reflect new changes made to
+ * this AsyncDistributedSet
+ * @return immutable set copy
+ */
+ CompletableFuture<? extends Set<E>> getAsImmutableSet();
+}
diff --git a/core/api/src/main/java/org/onosproject/store/service/AtomicCounter.java b/core/api/src/main/java/org/onosproject/store/service/AtomicCounter.java
index 3c9e02c..592f67a0 100644
--- a/core/api/src/main/java/org/onosproject/store/service/AtomicCounter.java
+++ b/core/api/src/main/java/org/onosproject/store/service/AtomicCounter.java
@@ -18,7 +18,12 @@
/**
* Distributed version of java.util.concurrent.atomic.AtomicLong.
*/
-public interface AtomicCounter {
+public interface AtomicCounter extends DistributedPrimitive {
+
+ @Override
+ default DistributedPrimitive.Type type() {
+ return DistributedPrimitive.Type.COUNTER;
+ }
/**
* Atomically increment by one the current value.
diff --git a/core/api/src/main/java/org/onosproject/store/service/AtomicValue.java b/core/api/src/main/java/org/onosproject/store/service/AtomicValue.java
index dfa0fb3..bb9b56b 100644
--- a/core/api/src/main/java/org/onosproject/store/service/AtomicValue.java
+++ b/core/api/src/main/java/org/onosproject/store/service/AtomicValue.java
@@ -20,7 +20,7 @@
*
* @param <V> value type
*/
-public interface AtomicValue<V> {
+public interface AtomicValue<V> extends DistributedPrimitive {
/**
* Atomically sets the value to the given updated value if the current value is equal to the expected value.
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 93abf78..19f8954 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
@@ -44,7 +44,7 @@
* (which extends RuntimeException) to indicate failures.
*
*/
-public interface ConsistentMap<K, V> {
+public interface ConsistentMap<K, V> extends DistributedPrimitive {
/**
* Returns the number of entries in the map.
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
new file mode 100644
index 0000000..342a110
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/store/service/DistributedPrimitive.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2015-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.core.ApplicationId;
+
+/**
+ * Interface for all distributed primitives.
+ */
+public interface DistributedPrimitive {
+
+ /**
+ * Type of distributed primitive.
+ */
+ public enum Type {
+ /**
+ * Map with strong consistency semantics.
+ */
+ CONSISTENT_MAP,
+
+ /**
+ * Map with eventual consistency semantics.
+ */
+ EVENTUALLY_CONSISTENT_MAP,
+
+ /**
+ * distributed set.
+ */
+ SET,
+
+ /**
+ * atomic counter.
+ */
+ COUNTER,
+
+ /**
+ * Atomic value.
+ */
+ VALUE,
+
+ /**
+ * Distributed queue.
+ */
+ QUEUE
+ }
+
+ /**
+ * Returns the name of this primitive.
+ * @return name
+ */
+ String name();
+
+ /**
+ * Returns the type of primitive.
+ * @return primitive type
+ */
+ Type type();
+
+ /**
+ * Returns the application owning this primitive.
+ */
+ default ApplicationId applicationId() {
+ return null;
+ }
+}
diff --git a/core/api/src/main/java/org/onosproject/store/service/DistributedQueue.java b/core/api/src/main/java/org/onosproject/store/service/DistributedQueue.java
index cc0b00d..777152c 100644
--- a/core/api/src/main/java/org/onosproject/store/service/DistributedQueue.java
+++ b/core/api/src/main/java/org/onosproject/store/service/DistributedQueue.java
@@ -24,7 +24,7 @@
*
* @param <E> queue entry type
*/
-public interface DistributedQueue<E> {
+public interface DistributedQueue<E> extends DistributedPrimitive {
/**
* Returns total number of entries in the queue.
diff --git a/core/api/src/main/java/org/onosproject/store/service/DistributedSet.java b/core/api/src/main/java/org/onosproject/store/service/DistributedSet.java
index 460206e..c59462b 100644
--- a/core/api/src/main/java/org/onosproject/store/service/DistributedSet.java
+++ b/core/api/src/main/java/org/onosproject/store/service/DistributedSet.java
@@ -22,7 +22,7 @@
*
* @param <E> set entry type
*/
-public interface DistributedSet<E> extends Set<E> {
+public interface DistributedSet<E> extends Set<E>, DistributedPrimitive {
/**
* Registers the specified listener to be notified whenever
diff --git a/core/api/src/main/java/org/onosproject/store/service/DistributedSetBuilder.java b/core/api/src/main/java/org/onosproject/store/service/DistributedSetBuilder.java
index f5a44c9..09ba794 100644
--- a/core/api/src/main/java/org/onosproject/store/service/DistributedSetBuilder.java
+++ b/core/api/src/main/java/org/onosproject/store/service/DistributedSetBuilder.java
@@ -129,4 +129,13 @@
* @throws java.lang.RuntimeException if a mandatory parameter is missing
*/
DistributedSet<E> build();
+
+ /**
+ * Builds an {@link AsyncDistributedSet async set} based on the configuration options
+ * supplied to this builder.
+ *
+ * @return new AsyncDistributedSet
+ * @throws java.lang.RuntimeException if a mandatory parameter is missing
+ */
+ AsyncDistributedSet<E> buildAsyncSet();
}
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 06395b8..2369619 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
@@ -39,7 +39,12 @@
* Null values are not allowed in this map.
* </p>
*/
-public interface EventuallyConsistentMap<K, V> {
+public interface EventuallyConsistentMap<K, V> extends DistributedPrimitive {
+
+ @Override
+ default DistributedPrimitive.Type type() {
+ return DistributedPrimitive.Type.EVENTUALLY_CONSISTENT_MAP;
+ }
/**
* Returns the number of key-value mappings in this map.
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
new file mode 100644
index 0000000..be65382
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/store/service/Synchronous.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2015-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;
+
+/**
+ * DistributedPrimitive that is a synchronous (blocking) version of
+ * another.
+ *
+ * @param <T> type of DistributedPrimitive
+ */
+public abstract class Synchronous<T extends DistributedPrimitive> implements DistributedPrimitive {
+
+ private final T primitive;
+
+ public Synchronous(T primitive) {
+ this.primitive = primitive;
+ }
+
+ @Override
+ public String name() {
+ return primitive.name();
+ }
+
+ @Override
+ public Type type() {
+ return primitive.type();
+ }
+}