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