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