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