HCOLL-81 make it clear that mapForKey is read only as it uses a Function and updateForKey is read/write and takes a mutator.

This commit is contained in:
Peter Lawrey
2014-11-15 12:56:37 +00:00
parent 80ba83a669
commit 3750bc4f8e
7 changed files with 120 additions and 35 deletions
@@ -91,7 +91,8 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
PUT_ALL,
PUT_ALL_WITHOUT_ACC,
HASH_CODE,
MAP_FOR_KEY
MAP_FOR_KEY,
UPDATE_FOR_KEY
}
private long transactionID;
@@ -470,6 +471,19 @@ class StatelessChronicleMap<K, V> implements ChronicleMap<K, V>, Closeable {
return (R) keyValueSerializer.readObject(reader);
}
@Override
public synchronized <R> R updateForKey(K key, @NotNull Mutator<? super V, R> mutator) {
final ThreadLocalCopies local = keyValueSerializer.threadLocalCopies();
final long sizeLocation = writeEventAnSkip(UPDATE_FOR_KEY);
writeKey(key, local);
writeObject(mutator);
final Bytes reader = blockingFetch(sizeLocation);
return (R) keyValueSerializer.readObject(reader);
}
private <R> void writeObject(@NotNull Object function) {
long start = bytes.position();