mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
HCOLL-155 implemented lookupUsing(K key, V value, LockType lockTypeType) for ReplicatedVanChronMap
This commit is contained in:
@@ -255,45 +255,47 @@ class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
return (Segment) segments[segmentNum];
|
||||
}
|
||||
|
||||
@Override
|
||||
<T extends Context> T lookupUsing(K key, V value, LockType lockTypeType) {
|
||||
checkKey(key);
|
||||
ThreadLocalCopies copies = keyInteropProvider.getCopies(null);
|
||||
KI keyInterop = keyInteropProvider.get(copies, originalKeyInterop);
|
||||
KI keyWriter = keyInteropProvider.get(copies, originalKeyInterop);
|
||||
copies = metaKeyInteropProvider.getCopies(copies);
|
||||
MKI metaKeyInterop =
|
||||
metaKeyInteropProvider.get(copies, originalMetaKeyInterop, keyInterop, key);
|
||||
long hash = metaKeyInterop.hash(keyInterop, key);
|
||||
MKI metaKeyWriter =
|
||||
metaKeyInteropProvider.get(copies, originalMetaKeyInterop, keyWriter, key);
|
||||
long hash = metaKeyWriter.hash(keyWriter, key);
|
||||
int segmentNum = getSegment(hash);
|
||||
long segmentHash = segmentHash(hash);
|
||||
|
||||
boolean create =lockTypeType == LockType.WRITE_LOCK;
|
||||
Segment segment = segment(segmentNum);
|
||||
|
||||
MutableLockedEntry<K, V, MKI, KI> lock = (lockTypeType == LockType.WRITE_LOCK)
|
||||
? segment.writeLock()
|
||||
: segment.readLock();
|
||||
|
||||
V v = segment.acquireWithoutLock(copies, metaKeyInterop, keyInterop, key, value,
|
||||
segmentHash, lockTypeType == LockType.WRITE_LOCK,
|
||||
(lockTypeType == LockType.WRITE_LOCK) ? timeProvider.currentTimeMillis() : 0L);
|
||||
V v = segment.acquireWithoutLock(copies, metaKeyWriter, keyWriter, key,
|
||||
value,
|
||||
segmentHash, create, create ? timeProvider.currentTimeMillis() : 0L);
|
||||
|
||||
lock.copies = copies;
|
||||
lock.metaKeyInterop = metaKeyWriter;
|
||||
lock.keyInterop = keyWriter;
|
||||
lock.segmentHash = segmentHash;
|
||||
|
||||
// we want to call put on heap objects that don't currently exist in the map
|
||||
if (v == null && !isNativeValueClass && lockTypeType == LockType.WRITE_LOCK) {
|
||||
lock.copies = copies;
|
||||
lock.metaKeyInterop = metaKeyInterop;
|
||||
lock.keyInterop = keyInterop;
|
||||
lock.segmentHash = segmentHash;
|
||||
if (!isNativeValueClass && lockTypeType == LockType.WRITE_LOCK && v == null)
|
||||
v = value;
|
||||
}
|
||||
|
||||
//todo set dirty when using replication on
|
||||
|
||||
lock.value(v);
|
||||
lock.key(key);
|
||||
|
||||
return (T) lock;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public V remove(final Object key) {
|
||||
return removeIfValueIs(key, null, localIdentifier, timeProvider.currentTimeMillis());
|
||||
|
||||
@@ -420,7 +420,6 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
lock.metaKeyInterop = metaKeyInterop;
|
||||
lock.keyInterop = keyInterop;
|
||||
lock.segmentHash = segmentHash;
|
||||
lock.value = null; // todo is this really needed?
|
||||
|
||||
if (!isNativeValueClass && lockTypeType == LockType.WRITE_LOCK && v == null)
|
||||
v = value;
|
||||
@@ -1419,8 +1418,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
|
||||
@Override
|
||||
public void removeEntry() {
|
||||
if (copies != null)
|
||||
removeWithoutLock(copies, metaKeyInterop, keyInterop, key(), null, segmentHash);
|
||||
removeWithoutLock(copies, metaKeyInterop, keyInterop, key(), null, segmentHash);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1434,9 +1432,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
putWithoutLock(copies, metaKeyInterop, keyInterop, key(), value(),
|
||||
segmentHash, true);
|
||||
|
||||
copies = null;
|
||||
putOnClose = true;
|
||||
|
||||
Segment.this.writeUnlock();
|
||||
}
|
||||
|
||||
@@ -1638,6 +1634,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
|
||||
KI keyInterop;
|
||||
long segmentHash;
|
||||
|
||||
|
||||
private K key;
|
||||
private V value;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user