Revert
Revert key IN record TO timestamp
void revert(String key, long record, long timestamp)
Set
SET key AS value IN record
//NOTE: cannot do automatic retry for this method, so caller must handle that boolean set(String key, TObject value, long record){ AtomicOperation operation = AtomicOperation.start(store); Set<TObject> values = operation.fetch(key, record); for (TObject value : values){ operation.remove(key, value, record); } operation.add(key, value, record); return operation.commit(); }
Verify And Swap
See http://en.wikipedia.org/wiki/Compare-and-swap
Verify key AS value1 IN record AND SWAP WITH value2
//NOTE: cannot do automatic retry for this method, so caller must handle that boolean verifyAndSwap(String key, TObject expected, long record, TObject replacement){ AtomicOperation operation = AtomicOperation.start(store); if(operation.verify(key, expected, record){ operation.remove(key, expected, record); operation.add(key, replacement, record); return operation.commit(); } else{ return false; } }
Get And Increment
See http://en.wikipedia.org/wiki/Fetch-and-add
FETCH key AS value in record AND INCREMENT
The first value for key in record (get returns the first value of a fetch) must be a Number, otherwise this method should throw an exception.
TODO: how to handle floats and doubles?
Number getAndIncrement(String key,long record){ while(true){ value = get(key, record); if(verifyAndSet(key, value, record, value + 1){ return value; } } }