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