blob: 6609fb8c91e0b8d6ec1288037ee0f9c1c0800136 [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 */
23public interface AsyncAtomicCounterMap<K> {
24
25 /**
26 * Increments by one the value currently associated with key, and returns the new value.
27 *
28 * @param key key with which the specified value is to be associated
Ray Milkeyd7909ca2016-03-04 08:46:13 -080029 * @return incremented value
Jihwan Kim1f536272015-12-18 03:10:09 +090030 */
31 CompletableFuture<Long> incrementAndGet(K key);
32
33 /**
34 * Decrements by one the value currently associated with key, and returns the new value.
35 *
36 * @param key key with which the specified value is to be associated
37 * @return updated value
38 */
39 CompletableFuture<Long> decrementAndGet(K key);
40
41 /**
42 * Increments by one the value currently associated with key, and returns the old value.
43 *
44 * @param key key with which the specified value is to be associated
45 * @return previous value
46 */
47 CompletableFuture<Long> getAndIncrement(K key);
48
49 /**
50 * Decrements by one the value currently associated with key, and returns the old value.
51 *
52 * @param key key with which the specified value is to be associated
53 * @return previous value
54 */
55 CompletableFuture<Long> getAndDecrement(K key);
56
57 /**
58 * Adds delta to the value currently associated with key, and returns the new value.
59 *
60 * @param key key with which the specified value is to be associated
61 * @param delta the value to add
62 * @return updated value
63 */
64 CompletableFuture<Long> addAndGet(K key, long delta);
65
66 /**
67 * Adds delta to the value currently associated with key, and returns the old value.
68 *
69 * @param key key with which the specified value is to be associated
70 * @param delta the value to add
71 * @return previous value
72 */
73 CompletableFuture<Long> getAndAdd(K key, long delta);
74
75 /**
76 * Returns the value associated with key, or zero if there is no value associated with key.
77 *
78 * @param key key with which the specified value is to be associated
79 * @return current value
80 */
81 CompletableFuture<Long> get(K key);
82
83 /**
84 * Associates ewValue with key in this map, and returns the value previously
85 * associated with key, or zero if there was no such value.
86 *
87 * @param key key with which the specified value is to be associated
88 * @param newValue the value to put
89 * @return previous value or zero
90 */
91 CompletableFuture<Long> put(K key, long newValue);
92
93
94 /**
95 * If key is not already associated with a value or if key is associated with
96 * zero, associate it with newValue. Returns the previous value associated with
97 * key, or zero if there was no mapping for key.
98 *
99 * @param key key with which the specified value is to be associated
100 * @param newValue the value to put
101 * @return previous value or zero
102 */
103 CompletableFuture<Long> putIfAbsent(K key, long newValue);
104
105 /**
106 * If (key, expectedOldValue) is currently in the map, this method replaces
107 * expectedOldValue with newValue and returns true; otherwise, this method return false.
108 *
109 * If expectedOldValue is zero, this method will succeed if (key, zero)
110 * is currently in the map, or if key is not in the map at all.
111 *
112 * @param key key with which the specified value is to be associated
113 * @param expectedOldValue the expected value
114 * @param newValue the value to replace
115 * @return true if the value was replaced, false otherwise
116 */
117 CompletableFuture<Boolean> replace(K key, long expectedOldValue, long newValue);
118
119 /**
120 * Removes and returns the value associated with key. If key is not
121 * in the map, this method has no effect and returns zero.
122 *
123 * @param key key with which the specified value is to be associated
124 * @return the previous value associated with the specified key or null
125 */
126 CompletableFuture<Long> remove(K key);
127
128 /**
129 * If (key, value) is currently in the map, this method removes it and returns
130 * true; otherwise, this method returns false.
131 *
132 * @param key key with which the specified value is to be associated
133 * @param value the value to remove
134 * @return true if the value was removed, false otherwise
135 */
136 CompletableFuture<Boolean> remove(K key, long value);
137}