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