[ONOS-3558] Define interfaces for supporting a AtomicLongMap
Change-Id: I7c03d3d4e9c501fbf0f9d8d28dcc43875e0987ab
diff --git a/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicCounterMap.java b/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicCounterMap.java
new file mode 100644
index 0000000..3c11cf2
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/store/service/AsyncAtomicCounterMap.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2015 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.concurrent.CompletableFuture;
+
+/**
+ * An async atomic counter map dispenses monotonically increasing values associated with key.
+ */
+public interface AsyncAtomicCounterMap<K> {
+
+ /**
+ * Increments by one the value currently associated with key, and returns the new value.
+ *
+ * @param key key with which the specified value is to be associated
+ */
+ CompletableFuture<Long> incrementAndGet(K key);
+
+ /**
+ * Decrements by one the value currently associated with key, and returns the new value.
+ *
+ * @param key key with which the specified value is to be associated
+ * @return updated value
+ */
+ CompletableFuture<Long> decrementAndGet(K key);
+
+ /**
+ * Increments by one the value currently associated with key, and returns the old value.
+ *
+ * @param key key with which the specified value is to be associated
+ * @return previous value
+ */
+ CompletableFuture<Long> getAndIncrement(K key);
+
+ /**
+ * Decrements by one the value currently associated with key, and returns the old value.
+ *
+ * @param key key with which the specified value is to be associated
+ * @return previous value
+ */
+ CompletableFuture<Long> getAndDecrement(K key);
+
+ /**
+ * Adds delta to the value currently associated with key, and returns the new value.
+ *
+ * @param key key with which the specified value is to be associated
+ * @param delta the value to add
+ * @return updated value
+ */
+ CompletableFuture<Long> addAndGet(K key, long delta);
+
+ /**
+ * Adds delta to the value currently associated with key, and returns the old value.
+ *
+ * @param key key with which the specified value is to be associated
+ * @param delta the value to add
+ * @return previous value
+ */
+ CompletableFuture<Long> getAndAdd(K key, long delta);
+
+ /**
+ * Returns the value associated with key, or zero if there is no value associated with key.
+ *
+ * @param key key with which the specified value is to be associated
+ * @return current value
+ */
+ CompletableFuture<Long> get(K key);
+
+ /**
+ * Associates ewValue with key in this map, and returns the value previously
+ * associated with key, or zero if there was no such value.
+ *
+ * @param key key with which the specified value is to be associated
+ * @param newValue the value to put
+ * @return previous value or zero
+ */
+ CompletableFuture<Long> put(K key, long newValue);
+
+
+ /**
+ * If key is not already associated with a value or if key is associated with
+ * zero, associate it with newValue. Returns the previous value associated with
+ * key, or zero if there was no mapping for key.
+ *
+ * @param key key with which the specified value is to be associated
+ * @param newValue the value to put
+ * @return previous value or zero
+ */
+ CompletableFuture<Long> putIfAbsent(K key, long newValue);
+
+ /**
+ * If (key, expectedOldValue) is currently in the map, this method replaces
+ * expectedOldValue with newValue and returns true; otherwise, this method return false.
+ *
+ * If expectedOldValue is zero, this method will succeed if (key, zero)
+ * is currently in the map, or if key is not in the map at all.
+ *
+ * @param key key with which the specified value is to be associated
+ * @param expectedOldValue the expected value
+ * @param newValue the value to replace
+ * @return true if the value was replaced, false otherwise
+ */
+ CompletableFuture<Boolean> replace(K key, long expectedOldValue, long newValue);
+
+ /**
+ * Removes and returns the value associated with key. If key is not
+ * in the map, this method has no effect and returns zero.
+ *
+ * @param key key with which the specified value is to be associated
+ * @return the previous value associated with the specified key or null
+ */
+ CompletableFuture<Long> remove(K key);
+
+ /**
+ * If (key, value) is currently in the map, this method removes it and returns
+ * true; otherwise, this method returns false.
+ *
+ * @param key key with which the specified value is to be associated
+ * @param value the value to remove
+ * @return true if the value was removed, false otherwise
+ */
+ CompletableFuture<Boolean> remove(K key, long value);
+}
diff --git a/core/api/src/main/java/org/onosproject/store/service/AtomicCounterMap.java b/core/api/src/main/java/org/onosproject/store/service/AtomicCounterMap.java
new file mode 100644
index 0000000..a21f178
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/store/service/AtomicCounterMap.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2015 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;
+
+/**
+ * Distributed version of com.google.common.util.concurrent.AtomicLongMap.
+ */
+public interface AtomicCounterMap<K> {
+
+ /**
+ * Increments by one the value currently associated with key, and returns the new value.
+ *
+ * @param key key with which the specified value is to be associated
+ */
+ long incrementAndGet(K key);
+
+ /**
+ * Decrements by one the value currently associated with key, and returns the new value.
+ *
+ * @param key key with which the specified value is to be associated
+ * @return updated value
+ */
+ long decrementAndGet(K key);
+
+ /**
+ * Increments by one the value currently associated with key, and returns the old value.
+ *
+ * @param key key with which the specified value is to be associated
+ * @return previous value
+ */
+ long getAndIncrement(K key);
+
+ /**
+ * Decrements by one the value currently associated with key, and returns the old value.
+ *
+ * @param key key with which the specified value is to be associated
+ * @return previous value
+ */
+ long getAndDecrement(K key);
+
+ /**
+ * Adds delta to the value currently associated with key, and returns the new value.
+ *
+ * @param key key with which the specified value is to be associated
+ * @param delta the value to add
+ * @return updated value
+ */
+ long addAndGet(K key, long delta);
+
+ /**
+ * Adds delta to the value currently associated with key, and returns the old value.
+ *
+ * @param key key with which the specified value is to be associated
+ * @param delta the value to add
+ * @return previous value
+ */
+ long getAndAdd(K key, long delta);
+
+ /**
+ * Returns the value associated with key, or zero if there is no value associated with key.
+ *
+ * @param key key with which the specified value is to be associated
+ * @return current value
+ */
+ long get(K key);
+
+ /**
+ * Associates ewValue with key in this map, and returns the value previously
+ * associated with key, or zero if there was no such value.
+ *
+ * @param key key with which the specified value is to be associated
+ * @param newValue the value to put
+ * @return previous value or zero
+ */
+ long put(K key, long newValue);
+
+
+ /**
+ * If key is not already associated with a value or if key is associated with
+ * zero, associate it with newValue. Returns the previous value associated with
+ * key, or zero if there was no mapping for key.
+ *
+ * @param key key with which the specified value is to be associated
+ * @param newValue the value to put
+ * @return previous value or zero
+ */
+ long putIfAbsent(K key, long newValue);
+
+ /**
+ * If (key, expectedOldValue) is currently in the map, this method replaces
+ * expectedOldValue with newValue and returns true; otherwise, this method return false.
+ *
+ * If expectedOldValue is zero, this method will succeed if (key, zero)
+ * is currently in the map, or if key is not in the map at all.
+ *
+ * @param key key with which the specified value is to be associated
+ * @param expectedOldValue the expected value
+ * @param newValue the value to replace
+ * @return true if the value was replaced, false otherwise
+ */
+ boolean replace(K key, long expectedOldValue, long newValue);
+
+ /**
+ * Removes and returns the value associated with key. If key is not
+ * in the map, this method has no effect and returns zero.
+ *
+ * @param key key with which the specified value is to be associated
+ * @return the previous value associated with the specified key or null
+ */
+ long remove(K key);
+
+ /**
+ * If (key, value) is currently in the map, this method removes it and returns
+ * true; otherwise, this method returns false.
+ *
+ * @param key key with which the specified value is to be associated
+ * @param value the value to remove
+ * @return true if the value was removed, false otherwise
+ */
+ boolean remove(K key, long value);
+}
diff --git a/core/api/src/main/java/org/onosproject/store/service/AtomicCounterMapBuilder.java b/core/api/src/main/java/org/onosproject/store/service/AtomicCounterMapBuilder.java
new file mode 100644
index 0000000..174791c
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/store/service/AtomicCounterMapBuilder.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2015 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;
+
+/**
+ * Builder for AtomicCounterMap.
+ */
+public interface AtomicCounterMapBuilder<K> {
+
+ /**
+ * Sets the name for the atomic counter map.
+ * <p>
+ * Each atomic counter map is identified by a unique name.
+ * </p>
+ * <p>
+ * Note: This is a mandatory parameter.
+ * </p>
+ *
+ * @param name name of the atomic counter
+ * @return this AtomicCounterMapBuilder
+ */
+ AtomicCounterMapBuilder<K> withName(String name);
+
+ /**
+ * Creates this counter map on the partition that spans the entire cluster.
+ * <p>
+ * When partitioning is disabled, the counter state will be
+ * ephemeral and does not survive a full cluster restart.
+ * </p>
+ * <p>
+ * Note: By default partitions are enabled.
+ * </p>
+ * @return this AtomicCounterMapBuilder
+ */
+ AtomicCounterMapBuilder<K> withPartitionsDisabled();
+
+ /**
+ * Instantiates Metering service to gather usage and performance metrics.
+ * By default, usage data will be stored.
+ *
+ * @return this AtomicCounterMapBuilder
+ */
+ AtomicCounterMapBuilder<K> withMeteringDisabled();
+
+ /**
+ * Builds a AtomicCounterMap based on the configuration options
+ * supplied to this builder.
+ *
+ * @return new AtomicCounterMap
+ * @throws java.lang.RuntimeException if a mandatory parameter is missing
+ */
+ AtomicCounterMap<K> build();
+
+ /**
+ * Builds a AsyncAtomicCounterMap based on the configuration options
+ * supplied to this builder.
+ *
+ * @return new AsyncAtomicCounterMap
+ * @throws java.lang.RuntimeException if a mandatory parameter is missing
+ */
+ AsyncAtomicCounterMap<K> buildAsyncAtomicCounterMap();
+}