Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 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 | |
Jordan Halterman | 5f97a30 | 2017-04-26 23:41:31 -0700 | [diff] [blame] | 18 | import java.util.Collection; |
| 19 | import java.util.Map; |
| 20 | import java.util.Set; |
| 21 | |
| 22 | import com.google.common.base.MoreObjects; |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 23 | import io.atomix.catalyst.buffer.BufferInput; |
| 24 | import io.atomix.catalyst.buffer.BufferOutput; |
| 25 | import io.atomix.catalyst.serializer.CatalystSerializable; |
Madan Jampani | fc98177 | 2016-02-16 09:46:42 -0800 | [diff] [blame] | 26 | import io.atomix.catalyst.serializer.SerializableTypeResolver; |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 27 | import io.atomix.catalyst.serializer.Serializer; |
Madan Jampani | fc98177 | 2016-02-16 09:46:42 -0800 | [diff] [blame] | 28 | import io.atomix.catalyst.serializer.SerializerRegistry; |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 29 | import io.atomix.catalyst.util.Assert; |
Madan Jampani | 3a9911c | 2016-02-21 11:25:45 -0800 | [diff] [blame] | 30 | import io.atomix.copycat.Command; |
| 31 | import io.atomix.copycat.Query; |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 32 | import org.onlab.util.Match; |
Jordan Halterman | 948d659 | 2017-04-20 17:18:24 -0700 | [diff] [blame] | 33 | import org.onosproject.store.primitives.MapUpdate; |
Madan Jampani | cadd70b | 2016-02-08 13:45:43 -0800 | [diff] [blame] | 34 | import org.onosproject.store.primitives.TransactionId; |
Jordan Halterman | 948d659 | 2017-04-20 17:18:24 -0700 | [diff] [blame] | 35 | import org.onosproject.store.service.TransactionLog; |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 36 | import org.onosproject.store.service.Versioned; |
| 37 | |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 38 | /** |
| 39 | * {@link AtomixConsistentMap} resource state machine operations. |
| 40 | */ |
| 41 | public final class AtomixConsistentMapCommands { |
| 42 | |
| 43 | private AtomixConsistentMapCommands() { |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Abstract map command. |
| 48 | */ |
| 49 | @SuppressWarnings("serial") |
| 50 | public abstract static class MapCommand<V> implements Command<V>, CatalystSerializable { |
| 51 | |
| 52 | @Override |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 53 | public String toString() { |
| 54 | return MoreObjects.toStringHelper(getClass()) |
| 55 | .toString(); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void writeObject(BufferOutput<?> buffer, Serializer serializer) { |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public void readObject(BufferInput<?> buffer, Serializer serializer) { |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Abstract map query. |
| 69 | */ |
| 70 | @SuppressWarnings("serial") |
| 71 | public abstract static class MapQuery<V> implements Query<V>, CatalystSerializable { |
| 72 | |
| 73 | @Override |
| 74 | public ConsistencyLevel consistency() { |
Madan Jampani | 5ddaf19 | 2016-04-04 07:39:31 -0700 | [diff] [blame] | 75 | return ConsistencyLevel.SEQUENTIAL; |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public String toString() { |
| 80 | return MoreObjects.toStringHelper(getClass()) |
| 81 | .toString(); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public void writeObject(BufferOutput<?> buffer, Serializer serializer) { |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public void readObject(BufferInput<?> buffer, Serializer serializer) { |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Abstract key-based query. |
| 95 | */ |
| 96 | @SuppressWarnings("serial") |
| 97 | public abstract static class KeyQuery<V> extends MapQuery<V> { |
| 98 | protected String key; |
| 99 | |
| 100 | public KeyQuery() { |
| 101 | } |
| 102 | |
| 103 | public KeyQuery(String key) { |
| 104 | this.key = Assert.notNull(key, "key"); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Returns the key. |
| 109 | * @return key |
| 110 | */ |
| 111 | public String key() { |
| 112 | return key; |
| 113 | } |
| 114 | |
| 115 | @Override |
| 116 | public String toString() { |
| 117 | return MoreObjects.toStringHelper(getClass()) |
| 118 | .add("key", key) |
| 119 | .toString(); |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public void writeObject(BufferOutput<?> buffer, Serializer serializer) { |
| 124 | super.writeObject(buffer, serializer); |
| 125 | serializer.writeObject(key, buffer); |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public void readObject(BufferInput<?> buffer, Serializer serializer) { |
| 130 | super.readObject(buffer, serializer); |
| 131 | key = serializer.readObject(buffer); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | /** |
Aaron Kruglikov | 56423ba | 2016-04-19 13:39:16 -0700 | [diff] [blame] | 136 | * Abstract value-based query. |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 137 | */ |
| 138 | @SuppressWarnings("serial") |
| 139 | public abstract static class ValueQuery<V> extends MapQuery<V> { |
| 140 | protected byte[] value; |
| 141 | |
| 142 | public ValueQuery() { |
| 143 | } |
| 144 | |
| 145 | public ValueQuery(byte[] value) { |
| 146 | this.value = Assert.notNull(value, "value"); |
| 147 | } |
| 148 | |
| 149 | /** |
Aaron Kruglikov | 56423ba | 2016-04-19 13:39:16 -0700 | [diff] [blame] | 150 | * Returns the value. |
| 151 | * @return value |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 152 | */ |
| 153 | public byte[] value() { |
| 154 | return value; |
| 155 | } |
| 156 | |
| 157 | @Override |
Aaron Kruglikov | b56c296 | 2016-04-04 17:03:24 -0700 | [diff] [blame] | 158 | public String toString() { |
| 159 | return MoreObjects.toStringHelper(getClass()) |
| 160 | .add("value", value) |
| 161 | .toString(); |
| 162 | } |
| 163 | |
| 164 | @Override |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 165 | public void writeObject(BufferOutput<?> buffer, Serializer serializer) { |
| 166 | super.writeObject(buffer, serializer); |
| 167 | serializer.writeObject(value, buffer); |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public void readObject(BufferInput<?> buffer, Serializer serializer) { |
| 172 | super.readObject(buffer, serializer); |
| 173 | value = serializer.readObject(buffer); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Contains key command. |
| 179 | */ |
| 180 | @SuppressWarnings("serial") |
| 181 | public static class ContainsKey extends KeyQuery<Boolean> { |
| 182 | public ContainsKey() { |
| 183 | } |
| 184 | |
| 185 | public ContainsKey(String key) { |
| 186 | super(key); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | /** |
Aaron Kruglikov | 56423ba | 2016-04-19 13:39:16 -0700 | [diff] [blame] | 191 | * Contains value command. |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 192 | */ |
| 193 | @SuppressWarnings("serial") |
| 194 | public static class ContainsValue extends ValueQuery<Boolean> { |
| 195 | public ContainsValue() { |
| 196 | } |
| 197 | |
| 198 | public ContainsValue(byte[] value) { |
| 199 | super(value); |
| 200 | } |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /** |
Jordan Halterman | 5f97a30 | 2017-04-26 23:41:31 -0700 | [diff] [blame] | 204 | * Transaction begin command. |
Jordan Halterman | 948d659 | 2017-04-20 17:18:24 -0700 | [diff] [blame] | 205 | */ |
Jordan Halterman | 5f97a30 | 2017-04-26 23:41:31 -0700 | [diff] [blame] | 206 | public static class TransactionBegin extends MapCommand<Long> { |
| 207 | private TransactionId transactionId; |
| 208 | |
| 209 | public TransactionBegin() { |
| 210 | } |
| 211 | |
| 212 | public TransactionBegin(TransactionId transactionId) { |
| 213 | this.transactionId = transactionId; |
| 214 | } |
| 215 | |
| 216 | public TransactionId transactionId() { |
| 217 | return transactionId; |
| 218 | } |
| 219 | |
Jordan Halterman | 948d659 | 2017-04-20 17:18:24 -0700 | [diff] [blame] | 220 | @Override |
Jordan Halterman | 5f97a30 | 2017-04-26 23:41:31 -0700 | [diff] [blame] | 221 | public void writeObject(BufferOutput<?> buffer, Serializer serializer) { |
| 222 | super.writeObject(buffer, serializer); |
| 223 | serializer.writeObject(transactionId, buffer); |
| 224 | } |
| 225 | |
| 226 | @Override |
| 227 | public void readObject(BufferInput<?> buffer, Serializer serializer) { |
| 228 | super.readObject(buffer, serializer); |
| 229 | transactionId = serializer.readObject(buffer); |
Jordan Halterman | 948d659 | 2017-04-20 17:18:24 -0700 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
| 233 | /** |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 234 | * Map prepare command. |
| 235 | */ |
| 236 | @SuppressWarnings("serial") |
| 237 | public static class TransactionPrepare extends MapCommand<PrepareResult> { |
Jordan Halterman | 948d659 | 2017-04-20 17:18:24 -0700 | [diff] [blame] | 238 | private TransactionLog<MapUpdate<String, byte[]>> transactionLog; |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 239 | |
| 240 | public TransactionPrepare() { |
| 241 | } |
| 242 | |
Jordan Halterman | 948d659 | 2017-04-20 17:18:24 -0700 | [diff] [blame] | 243 | public TransactionPrepare(TransactionLog<MapUpdate<String, byte[]>> transactionLog) { |
| 244 | this.transactionLog = transactionLog; |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Jordan Halterman | 948d659 | 2017-04-20 17:18:24 -0700 | [diff] [blame] | 247 | public TransactionLog<MapUpdate<String, byte[]>> transactionLog() { |
| 248 | return transactionLog; |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | @Override |
| 252 | public void writeObject(BufferOutput<?> buffer, Serializer serializer) { |
| 253 | super.writeObject(buffer, serializer); |
Jordan Halterman | 948d659 | 2017-04-20 17:18:24 -0700 | [diff] [blame] | 254 | serializer.writeObject(transactionLog, buffer); |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | @Override |
| 258 | public void readObject(BufferInput<?> buffer, Serializer serializer) { |
| 259 | super.readObject(buffer, serializer); |
Jordan Halterman | 948d659 | 2017-04-20 17:18:24 -0700 | [diff] [blame] | 260 | transactionLog = serializer.readObject(buffer); |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public String toString() { |
| 265 | return MoreObjects.toStringHelper(getClass()) |
Jordan Halterman | 948d659 | 2017-04-20 17:18:24 -0700 | [diff] [blame] | 266 | .add("transactionLog", transactionLog) |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 267 | .toString(); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | /** |
Madan Jampani | 542d9e2 | 2016-04-05 15:39:55 -0700 | [diff] [blame] | 272 | * Map prepareAndCommit command. |
| 273 | */ |
| 274 | @SuppressWarnings("serial") |
| 275 | public static class TransactionPrepareAndCommit extends TransactionPrepare { |
| 276 | public TransactionPrepareAndCommit() { |
| 277 | } |
| 278 | |
Jordan Halterman | 948d659 | 2017-04-20 17:18:24 -0700 | [diff] [blame] | 279 | public TransactionPrepareAndCommit(TransactionLog<MapUpdate<String, byte[]>> transactionLog) { |
| 280 | super(transactionLog); |
Madan Jampani | 542d9e2 | 2016-04-05 15:39:55 -0700 | [diff] [blame] | 281 | } |
Jordan Halterman | 820e39f | 2017-02-05 22:15:36 -0800 | [diff] [blame] | 282 | |
| 283 | @Override |
| 284 | public CompactionMode compaction() { |
Jordan Halterman | 5f97a30 | 2017-04-26 23:41:31 -0700 | [diff] [blame] | 285 | return CompactionMode.TOMBSTONE; |
Jordan Halterman | 820e39f | 2017-02-05 22:15:36 -0800 | [diff] [blame] | 286 | } |
Madan Jampani | 542d9e2 | 2016-04-05 15:39:55 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /** |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 290 | * Map transaction commit command. |
| 291 | */ |
| 292 | @SuppressWarnings("serial") |
| 293 | public static class TransactionCommit extends MapCommand<CommitResult> { |
| 294 | private TransactionId transactionId; |
| 295 | |
| 296 | public TransactionCommit() { |
| 297 | } |
| 298 | |
| 299 | public TransactionCommit(TransactionId transactionId) { |
| 300 | this.transactionId = transactionId; |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Returns the transaction identifier. |
| 305 | * @return transaction id |
| 306 | */ |
| 307 | public TransactionId transactionId() { |
| 308 | return transactionId; |
| 309 | } |
| 310 | |
| 311 | @Override |
| 312 | public void writeObject(BufferOutput<?> buffer, Serializer serializer) { |
| 313 | super.writeObject(buffer, serializer); |
| 314 | serializer.writeObject(transactionId, buffer); |
| 315 | } |
| 316 | |
| 317 | @Override |
| 318 | public void readObject(BufferInput<?> buffer, Serializer serializer) { |
| 319 | super.readObject(buffer, serializer); |
| 320 | transactionId = serializer.readObject(buffer); |
| 321 | } |
| 322 | |
| 323 | @Override |
Jordan Halterman | 820e39f | 2017-02-05 22:15:36 -0800 | [diff] [blame] | 324 | public CompactionMode compaction() { |
| 325 | return CompactionMode.TOMBSTONE; |
| 326 | } |
| 327 | |
| 328 | @Override |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 329 | public String toString() { |
| 330 | return MoreObjects.toStringHelper(getClass()) |
| 331 | .add("transactionId", transactionId) |
| 332 | .toString(); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | /** |
| 337 | * Map transaction rollback command. |
| 338 | */ |
| 339 | @SuppressWarnings("serial") |
| 340 | public static class TransactionRollback extends MapCommand<RollbackResult> { |
| 341 | private TransactionId transactionId; |
| 342 | |
| 343 | public TransactionRollback() { |
| 344 | } |
| 345 | |
| 346 | public TransactionRollback(TransactionId transactionId) { |
| 347 | this.transactionId = transactionId; |
| 348 | } |
| 349 | |
| 350 | /** |
| 351 | * Returns the transaction identifier. |
| 352 | * @return transaction id |
| 353 | */ |
| 354 | public TransactionId transactionId() { |
| 355 | return transactionId; |
| 356 | } |
| 357 | |
| 358 | @Override |
| 359 | public void writeObject(BufferOutput<?> buffer, Serializer serializer) { |
| 360 | super.writeObject(buffer, serializer); |
| 361 | serializer.writeObject(transactionId, buffer); |
| 362 | } |
| 363 | |
| 364 | @Override |
| 365 | public void readObject(BufferInput<?> buffer, Serializer serializer) { |
| 366 | super.readObject(buffer, serializer); |
| 367 | transactionId = serializer.readObject(buffer); |
| 368 | } |
| 369 | |
| 370 | @Override |
Jordan Halterman | 820e39f | 2017-02-05 22:15:36 -0800 | [diff] [blame] | 371 | public CompactionMode compaction() { |
| 372 | return CompactionMode.TOMBSTONE; |
| 373 | } |
| 374 | |
| 375 | @Override |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 376 | public String toString() { |
| 377 | return MoreObjects.toStringHelper(getClass()) |
| 378 | .add("transactionId", transactionId) |
| 379 | .toString(); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * Map update command. |
| 385 | */ |
| 386 | @SuppressWarnings("serial") |
| 387 | public static class UpdateAndGet extends MapCommand<MapEntryUpdateResult<String, byte[]>> { |
| 388 | private String key; |
| 389 | private byte[] value; |
| 390 | private Match<byte[]> valueMatch; |
| 391 | private Match<Long> versionMatch; |
| 392 | |
| 393 | public UpdateAndGet() { |
| 394 | } |
| 395 | |
| 396 | public UpdateAndGet(String key, |
| 397 | byte[] value, |
| 398 | Match<byte[]> valueMatch, |
| 399 | Match<Long> versionMatch) { |
| 400 | this.key = key; |
| 401 | this.value = value; |
| 402 | this.valueMatch = valueMatch; |
| 403 | this.versionMatch = versionMatch; |
| 404 | } |
| 405 | |
| 406 | /** |
| 407 | * Returns the key. |
| 408 | * @return key |
| 409 | */ |
| 410 | public String key() { |
| 411 | return this.key; |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Returns the value. |
| 416 | * @return value |
| 417 | */ |
| 418 | public byte[] value() { |
| 419 | return this.value; |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * Returns the value match. |
| 424 | * @return value match |
| 425 | */ |
| 426 | public Match<byte[]> valueMatch() { |
| 427 | return this.valueMatch; |
| 428 | } |
| 429 | |
| 430 | /** |
| 431 | * Returns the version match. |
| 432 | * @return version match |
| 433 | */ |
| 434 | public Match<Long> versionMatch() { |
| 435 | return this.versionMatch; |
| 436 | } |
| 437 | |
| 438 | @Override |
| 439 | public CompactionMode compaction() { |
Jordan Halterman | 73e5cce | 2017-03-02 17:35:57 -0800 | [diff] [blame] | 440 | return value == null ? CompactionMode.TOMBSTONE : CompactionMode.FULL; |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | @Override |
| 444 | public void writeObject(BufferOutput<?> buffer, Serializer serializer) { |
| 445 | super.writeObject(buffer, serializer); |
| 446 | serializer.writeObject(key, buffer); |
| 447 | serializer.writeObject(value, buffer); |
| 448 | serializer.writeObject(valueMatch, buffer); |
| 449 | serializer.writeObject(versionMatch, buffer); |
| 450 | } |
| 451 | |
| 452 | @Override |
| 453 | public void readObject(BufferInput<?> buffer, Serializer serializer) { |
| 454 | super.readObject(buffer, serializer); |
| 455 | key = serializer.readObject(buffer); |
| 456 | value = serializer.readObject(buffer); |
| 457 | valueMatch = serializer.readObject(buffer); |
| 458 | versionMatch = serializer.readObject(buffer); |
| 459 | } |
| 460 | |
| 461 | @Override |
| 462 | public String toString() { |
| 463 | return MoreObjects.toStringHelper(getClass()) |
| 464 | .add("key", key) |
| 465 | .add("value", value) |
| 466 | .add("valueMatch", valueMatch) |
| 467 | .add("versionMatch", versionMatch) |
| 468 | .toString(); |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * Get query. |
| 474 | */ |
| 475 | @SuppressWarnings("serial") |
| 476 | public static class Get extends KeyQuery<Versioned<byte[]>> { |
| 477 | public Get() { |
| 478 | } |
| 479 | |
| 480 | public Get(String key) { |
| 481 | super(key); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | /** |
Jordan Halterman | f627244 | 2017-04-20 02:18:08 -0700 | [diff] [blame] | 486 | * Get or default query. |
| 487 | */ |
| 488 | @SuppressWarnings("serial") |
| 489 | public static class GetOrDefault extends KeyQuery<Versioned<byte[]>> { |
| 490 | private byte[] defaultValue; |
| 491 | |
| 492 | public GetOrDefault() { |
| 493 | } |
| 494 | |
| 495 | public GetOrDefault(String key, byte[] defaultValue) { |
| 496 | super(key); |
| 497 | this.defaultValue = defaultValue; |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * Returns the default value. |
| 502 | * |
| 503 | * @return the default value |
| 504 | */ |
| 505 | public byte[] defaultValue() { |
| 506 | return defaultValue; |
| 507 | } |
| 508 | |
| 509 | @Override |
| 510 | public void writeObject(BufferOutput<?> buffer, Serializer serializer) { |
| 511 | super.writeObject(buffer, serializer); |
| 512 | serializer.writeObject(defaultValue, buffer); |
| 513 | } |
| 514 | |
| 515 | @Override |
| 516 | public void readObject(BufferInput<?> buffer, Serializer serializer) { |
| 517 | super.readObject(buffer, serializer); |
| 518 | defaultValue = serializer.readObject(buffer); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | /** |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 523 | * Is empty query. |
| 524 | */ |
| 525 | @SuppressWarnings("serial") |
| 526 | public static class IsEmpty extends MapQuery<Boolean> { |
| 527 | } |
| 528 | |
| 529 | /** |
| 530 | * KeySet query. |
| 531 | */ |
| 532 | @SuppressWarnings("serial") |
| 533 | public static class KeySet extends MapQuery<Set<String>> { |
| 534 | } |
| 535 | |
| 536 | /** |
Aaron Kruglikov | b56c296 | 2016-04-04 17:03:24 -0700 | [diff] [blame] | 537 | * ValueSet query. |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 538 | */ |
| 539 | @SuppressWarnings("serial") |
| 540 | public static class Values extends MapQuery<Collection<Versioned<byte[]>>> { |
| 541 | } |
| 542 | |
| 543 | /** |
Aaron Kruglikov | b56c296 | 2016-04-04 17:03:24 -0700 | [diff] [blame] | 544 | * EntrySet query. |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 545 | */ |
| 546 | @SuppressWarnings("serial") |
| 547 | public static class EntrySet extends MapQuery<Set<Map.Entry<String, Versioned<byte[]>>>> { |
| 548 | } |
| 549 | |
| 550 | /** |
| 551 | * Size query. |
| 552 | */ |
| 553 | @SuppressWarnings("serial") |
| 554 | public static class Size extends MapQuery<Integer> { |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * Clear command. |
| 559 | */ |
| 560 | @SuppressWarnings("serial") |
| 561 | public static class Clear extends MapCommand<MapEntryUpdateResult.Status> { |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 562 | @Override |
| 563 | public CompactionMode compaction() { |
Jordan Halterman | 820e39f | 2017-02-05 22:15:36 -0800 | [diff] [blame] | 564 | return CompactionMode.TOMBSTONE; |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
| 568 | /** |
| 569 | * Change listen. |
| 570 | */ |
| 571 | @SuppressWarnings("serial") |
| 572 | public static class Listen implements Command<Void>, CatalystSerializable { |
| 573 | @Override |
| 574 | public void writeObject(BufferOutput<?> buffer, Serializer serializer) { |
| 575 | } |
| 576 | |
| 577 | @Override |
| 578 | public void readObject(BufferInput<?> buffer, Serializer serializer) { |
| 579 | } |
Jordan Halterman | 820e39f | 2017-02-05 22:15:36 -0800 | [diff] [blame] | 580 | |
| 581 | @Override |
| 582 | public CompactionMode compaction() { |
| 583 | return CompactionMode.QUORUM; |
| 584 | } |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | /** |
| 588 | * Change unlisten. |
| 589 | */ |
| 590 | @SuppressWarnings("serial") |
| 591 | public static class Unlisten implements Command<Void>, CatalystSerializable { |
| 592 | @Override |
| 593 | public void writeObject(BufferOutput<?> buffer, Serializer serializer) { |
| 594 | } |
| 595 | |
| 596 | @Override |
| 597 | public void readObject(BufferInput<?> buffer, Serializer serializer) { |
| 598 | } |
Jordan Halterman | 820e39f | 2017-02-05 22:15:36 -0800 | [diff] [blame] | 599 | |
| 600 | @Override |
| 601 | public CompactionMode compaction() { |
| 602 | return CompactionMode.TOMBSTONE; |
| 603 | } |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 604 | } |
Madan Jampani | fc98177 | 2016-02-16 09:46:42 -0800 | [diff] [blame] | 605 | |
| 606 | /** |
| 607 | * Map command type resolver. |
| 608 | */ |
| 609 | public static class TypeResolver implements SerializableTypeResolver { |
| 610 | @Override |
| 611 | public void resolve(SerializerRegistry registry) { |
| 612 | registry.register(ContainsKey.class, -761); |
| 613 | registry.register(ContainsValue.class, -762); |
| 614 | registry.register(Get.class, -763); |
Jordan Halterman | f627244 | 2017-04-20 02:18:08 -0700 | [diff] [blame] | 615 | registry.register(GetOrDefault.class, -778); |
Madan Jampani | fc98177 | 2016-02-16 09:46:42 -0800 | [diff] [blame] | 616 | registry.register(EntrySet.class, -764); |
| 617 | registry.register(Values.class, -765); |
| 618 | registry.register(KeySet.class, -766); |
| 619 | registry.register(Clear.class, -767); |
| 620 | registry.register(IsEmpty.class, -768); |
| 621 | registry.register(Size.class, -769); |
| 622 | registry.register(Listen.class, -770); |
| 623 | registry.register(Unlisten.class, -771); |
Jordan Halterman | 948d659 | 2017-04-20 17:18:24 -0700 | [diff] [blame] | 624 | registry.register(TransactionBegin.class, -777); |
Madan Jampani | fc98177 | 2016-02-16 09:46:42 -0800 | [diff] [blame] | 625 | registry.register(TransactionPrepare.class, -772); |
| 626 | registry.register(TransactionCommit.class, -773); |
| 627 | registry.register(TransactionRollback.class, -774); |
Madan Jampani | 542d9e2 | 2016-04-05 15:39:55 -0700 | [diff] [blame] | 628 | registry.register(TransactionPrepareAndCommit.class, -775); |
| 629 | registry.register(UpdateAndGet.class, -776); |
Madan Jampani | fc98177 | 2016-02-16 09:46:42 -0800 | [diff] [blame] | 630 | } |
| 631 | } |
Madan Jampani | 5e5b3d6 | 2016-02-01 16:03:33 -0800 | [diff] [blame] | 632 | } |