blob: 6ac096f9d2a8fe3da69377933eace1380df9a504 [file] [log] [blame]
Jihwan Kim1f536272015-12-18 03:10:09 +09001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Jihwan Kim1f536272015-12-18 03:10:09 +09003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.store.service;
17
18import java.util.concurrent.CompletableFuture;
19
20/**
21 * An async atomic counter map dispenses monotonically increasing values associated with key.
22 */
Jihwan Kimcf8f6b22016-11-12 13:07:04 +090023public interface AsyncAtomicCounterMap<K> extends DistributedPrimitive {
24
25 @Override
26 default DistributedPrimitive.Type primitiveType() {
27 return DistributedPrimitive.Type.COUNTER_MAP;
28 }
Jihwan Kim1f536272015-12-18 03:10:09 +090029
30 /**
31 * Increments by one the value currently associated with key, and returns the new value.
32 *
33 * @param key key with which the specified value is to be associated
Ray Milkeyd7909ca2016-03-04 08:46:13 -080034 * @return incremented value
Jihwan Kim1f536272015-12-18 03:10:09 +090035 */
36 CompletableFuture<Long> incrementAndGet(K key);
37
38 /**
39 * Decrements by one the value currently associated with key, and returns the new value.
40 *
41 * @param key key with which the specified value is to be associated
42 * @return updated value
43 */
44 CompletableFuture<Long> decrementAndGet(K key);
45
46 /**
47 * Increments by one the value currently associated with key, and returns the old value.
48 *
49 * @param key key with which the specified value is to be associated
50 * @return previous value
51 */
52 CompletableFuture<Long> getAndIncrement(K key);
53
54 /**
55 * Decrements by one the value currently associated with key, and returns the old value.
56 *
57 * @param key key with which the specified value is to be associated
58 * @return previous value
59 */
60 CompletableFuture<Long> getAndDecrement(K key);
61
62 /**
63 * Adds delta to the value currently associated with key, and returns the new value.
64 *
65 * @param key key with which the specified value is to be associated
66 * @param delta the value to add
67 * @return updated value
68 */
69 CompletableFuture<Long> addAndGet(K key, long delta);
70
71 /**
72 * Adds delta to the value currently associated with key, and returns the old value.
73 *
74 * @param key key with which the specified value is to be associated
75 * @param delta the value to add
76 * @return previous value
77 */
78 CompletableFuture<Long> getAndAdd(K key, long delta);
79
80 /**
81 * Returns the value associated with key, or zero if there is no value associated with key.
82 *
83 * @param key key with which the specified value is to be associated
84 * @return current value
85 */
86 CompletableFuture<Long> get(K key);
87
88 /**
89 * Associates ewValue with key in this map, and returns the value previously
90 * associated with key, or zero if there was no such value.
91 *
92 * @param key key with which the specified value is to be associated
93 * @param newValue the value to put
94 * @return previous value or zero
95 */
96 CompletableFuture<Long> put(K key, long newValue);
97
98
99 /**
100 * If key is not already associated with a value or if key is associated with
101 * zero, associate it with newValue. Returns the previous value associated with
102 * key, or zero if there was no mapping for key.
103 *
104 * @param key key with which the specified value is to be associated
105 * @param newValue the value to put
106 * @return previous value or zero
107 */
108 CompletableFuture<Long> putIfAbsent(K key, long newValue);
109
110 /**
111 * If (key, expectedOldValue) is currently in the map, this method replaces
112 * expectedOldValue with newValue and returns true; otherwise, this method return false.
113 *
114 * If expectedOldValue is zero, this method will succeed if (key, zero)
115 * is currently in the map, or if key is not in the map at all.
116 *
117 * @param key key with which the specified value is to be associated
118 * @param expectedOldValue the expected value
119 * @param newValue the value to replace
120 * @return true if the value was replaced, false otherwise
121 */
122 CompletableFuture<Boolean> replace(K key, long expectedOldValue, long newValue);
123
124 /**
125 * Removes and returns the value associated with key. If key is not
126 * in the map, this method has no effect and returns zero.
127 *
128 * @param key key with which the specified value is to be associated
129 * @return the previous value associated with the specified key or null
130 */
131 CompletableFuture<Long> remove(K key);
132
133 /**
134 * If (key, value) is currently in the map, this method removes it and returns
135 * true; otherwise, this method returns false.
136 *
137 * @param key key with which the specified value is to be associated
138 * @param value the value to remove
139 * @return true if the value was removed, false otherwise
140 */
141 CompletableFuture<Boolean> remove(K key, long value);
142}