blob: 7b2cba2a1aa63130222a46bf26dd9492376de4f3 [file] [log] [blame]
Jordan Halterman2bf177c2017-06-29 01:49:08 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jordan Halterman2bf177c2017-06-29 01:49:08 -07003 *
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.primitives.resources.impl;
17
18import io.atomix.protocols.raft.operation.OperationId;
19import io.atomix.protocols.raft.operation.OperationType;
20import org.onlab.util.KryoNamespace;
21import org.onosproject.store.serializers.KryoNamespaces;
22
23/**
24 * Atomic counter map commands.
25 */
26public enum AtomixAtomicCounterMapOperations implements OperationId {
Jordan Halterman2b7501c2017-11-29 14:05:33 -080027 PUT(OperationType.COMMAND),
28 PUT_IF_ABSENT(OperationType.COMMAND),
29 GET(OperationType.QUERY),
30 REPLACE(OperationType.COMMAND),
31 REMOVE(OperationType.COMMAND),
32 REMOVE_VALUE(OperationType.COMMAND),
33 GET_AND_INCREMENT(OperationType.COMMAND),
34 GET_AND_DECREMENT(OperationType.COMMAND),
35 INCREMENT_AND_GET(OperationType.COMMAND),
36 DECREMENT_AND_GET(OperationType.COMMAND),
37 ADD_AND_GET(OperationType.COMMAND),
38 GET_AND_ADD(OperationType.COMMAND),
39 SIZE(OperationType.QUERY),
40 IS_EMPTY(OperationType.QUERY),
41 CLEAR(OperationType.COMMAND);
Jordan Halterman2bf177c2017-06-29 01:49:08 -070042
Jordan Halterman2bf177c2017-06-29 01:49:08 -070043 private final OperationType type;
44
Jordan Halterman2b7501c2017-11-29 14:05:33 -080045 AtomixAtomicCounterMapOperations(OperationType type) {
Jordan Halterman2bf177c2017-06-29 01:49:08 -070046 this.type = type;
47 }
48
49 @Override
50 public String id() {
Jordan Halterman2b7501c2017-11-29 14:05:33 -080051 return name();
Jordan Halterman2bf177c2017-06-29 01:49:08 -070052 }
53
54 @Override
55 public OperationType type() {
56 return type;
57 }
58
59 public static final KryoNamespace NAMESPACE = KryoNamespace.newBuilder()
60 .register(KryoNamespaces.BASIC)
61 .nextId(KryoNamespaces.BEGIN_USER_CUSTOM_ID)
62 .register(IncrementAndGet.class)
63 .register(DecrementAndGet.class)
64 .register(GetAndIncrement.class)
65 .register(GetAndDecrement.class)
66 .register(AddAndGet.class)
67 .register(GetAndAdd.class)
68 .register(Get.class)
69 .register(Put.class)
70 .register(PutIfAbsent.class)
71 .register(Replace.class)
72 .register(Remove.class)
73 .register(RemoveValue.class)
74 .build("AtomixAtomicCounterMapOperations");
75
76 public abstract static class AtomicCounterMapOperation<V> {
77 }
78
79 public abstract static class KeyOperation extends AtomicCounterMapOperation {
80 private String key;
81
82 public KeyOperation() {
83 }
84
85 public KeyOperation(String key) {
86 this.key = key;
87 }
88
89 public String key() {
90 return key;
91 }
92 }
93
94 public static class KeyValueOperation extends KeyOperation {
95 private long value;
96
97 public KeyValueOperation() {
98 }
99
100 public KeyValueOperation(String key, long value) {
101 super(key);
102 this.value = value;
103 }
104
105 public long value() {
106 return value;
107 }
108 }
109
110 public static class Get extends KeyOperation {
111 public Get() {
112 }
113
114 public Get(String key) {
115 super(key);
116 }
117 }
118
119 public static class Put extends KeyValueOperation {
120 public Put() {
121 }
122
123 public Put(String key, long value) {
124 super(key, value);
125 }
126 }
127
128 public static class PutIfAbsent extends KeyValueOperation {
129 public PutIfAbsent() {
130 }
131
132 public PutIfAbsent(String key, long value) {
133 super(key, value);
134 }
135 }
136
137 public static class Replace extends KeyOperation {
138 private long replace;
139 private long value;
140
141 public Replace() {
142 }
143
144 public Replace(String key, long replace, long value) {
145 super(key);
146 this.replace = replace;
147 this.value = value;
148 }
149
150 public long replace() {
151 return replace;
152 }
153
154 public long value() {
155 return value;
156 }
157 }
158
159 public static class Remove extends KeyOperation {
160 public Remove() {
161 }
162
163 public Remove(String key) {
164 super(key);
165 }
166 }
167
168 public static class RemoveValue extends KeyValueOperation {
169 public RemoveValue() {
170 }
171
172 public RemoveValue(String key, long value) {
173 super(key, value);
174 }
175 }
176
177 public static class IncrementAndGet extends KeyOperation {
178 public IncrementAndGet() {
179 }
180
181 public IncrementAndGet(String key) {
182 super(key);
183 }
184 }
185
186 public static class DecrementAndGet extends KeyOperation {
187 public DecrementAndGet(String key) {
188 super(key);
189 }
190
191 public DecrementAndGet() {
192 }
193 }
194
195 public static class GetAndIncrement extends KeyOperation {
196 public GetAndIncrement() {
197 }
198
199 public GetAndIncrement(String key) {
200 super(key);
201 }
202 }
203
204 public static class GetAndDecrement extends KeyOperation {
205 public GetAndDecrement() {
206 }
207
208 public GetAndDecrement(String key) {
209 super(key);
210 }
211 }
212
213 public abstract static class DeltaOperation extends KeyOperation {
214 private long delta;
215
216 public DeltaOperation() {
217 }
218
219 public DeltaOperation(String key, long delta) {
220 super(key);
221 this.delta = delta;
222 }
223
224 public long delta() {
225 return delta;
226 }
227 }
228
229 public static class AddAndGet extends DeltaOperation {
230 public AddAndGet() {
231 }
232
233 public AddAndGet(String key, long delta) {
234 super(key, delta);
235 }
236 }
237
238 public static class GetAndAdd extends DeltaOperation {
239 public GetAndAdd() {
240 }
241
242 public GetAndAdd(String key, long delta) {
243 super(key, delta);
244 }
245 }
246}