mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Merge pull request #81 from zhyhang/2.1
open a protected method for subclass extending replicated map
This commit is contained in:
@@ -1378,13 +1378,22 @@ public class ChronicleMapBuilder<K, V> implements Cloneable,
|
||||
} else {
|
||||
replication = channel.hub();
|
||||
}
|
||||
return new ReplicatedChronicleMap<K, Object, MetaBytesInterop<K, Object>,
|
||||
V, Object, MetaBytesInterop<V, Object>>(this, replication);
|
||||
return newReplicatedMap(replication);
|
||||
} else {
|
||||
return new VanillaChronicleMap<K, Object, MetaBytesInterop<K, Object>,
|
||||
V, Object, MetaBytesInterop<V, Object>>(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create the replicated map, as subclass can self implements of map.
|
||||
* @param replication
|
||||
* @return
|
||||
*/
|
||||
protected ReplicatedChronicleMap<K, ?, ?, V, ?, ?> newReplicatedMap(AbstractReplication replication){
|
||||
return new ReplicatedChronicleMap<K, Object, MetaBytesInterop<K, Object>,
|
||||
V, Object, MetaBytesInterop<V, Object>>(this, replication);
|
||||
}
|
||||
|
||||
void preMapConstruction(boolean replicated) {
|
||||
keyBuilder.objectSerializer(acquireObjectSerializer(JDKObjectSerializer.INSTANCE));
|
||||
|
||||
@@ -1496,6 +1496,7 @@ class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
if (!keyEquals(keyInterop, metaKeyInterop, key, keySize, entry))
|
||||
continue;
|
||||
// key is found
|
||||
onRemoveEntry(this, pos);
|
||||
entry.skip(keySize);
|
||||
long timestampPos = entry.position();
|
||||
long replacedTimestamp = entry.readLong(timestampPos);
|
||||
@@ -1572,6 +1573,7 @@ class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
|
||||
hashLookup.putAfterFailedSearch(searchState, pos);
|
||||
hashLookup.removePosition(pos);
|
||||
onRemoveEntry(this, pos);
|
||||
// listener.onRemove() might be missing here
|
||||
// depends on onRemove() semantics
|
||||
}
|
||||
@@ -1583,6 +1585,15 @@ class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
return resultUnused ? null : readValue.readNull();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* call when remove an entry in segment, regardless of local or remote remove, entry found or not found.<br>
|
||||
* caller has held the segment write lock
|
||||
* @param segment
|
||||
* @param pos
|
||||
*/
|
||||
void onRemoveEntry(Segment segment, long pos){
|
||||
}
|
||||
|
||||
<KB, KBI, MKBI extends MetaBytesInterop<KB, ? super KBI>,
|
||||
RV, VB extends RV, VBI, MVBI extends MetaBytesInterop<RV, ? super VBI>>
|
||||
|
||||
@@ -155,7 +155,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
|
||||
lockTimeOutNS = builder.lockTimeOut(TimeUnit.NANOSECONDS);
|
||||
|
||||
boolean replicated = getClass() == ReplicatedChronicleMap.class;
|
||||
boolean replicated = this instanceof ReplicatedChronicleMap;
|
||||
this.chunkSize = builder.chunkSize(replicated);
|
||||
this.alignment = builder.valueAlignment();
|
||||
this.constantlySizedEntry = builder.constantlySizedEntries();
|
||||
@@ -2618,7 +2618,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
}
|
||||
}
|
||||
|
||||
private void free(long fromPos, int chunks) {
|
||||
void free(long fromPos, int chunks) {
|
||||
freeList.clear(fromPos, fromPos + chunks);
|
||||
if (fromPos < nextPosToSearchFrom)
|
||||
nextPosToSearchFrom = fromPos;
|
||||
|
||||
Reference in New Issue
Block a user