mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user