K - the type of the key stored in Near CacheV - the type of the value stored in Near CacheKS - the type of the key of the underlying NearCacheRecordMapR - the type of the value of the underlying NearCacheRecordMapNCRM - the type of the underlying NearCacheRecordMappublic abstract class AbstractNearCacheRecordStore<K,V,KS,R extends NearCacheRecord,NCRM extends SampleableNearCacheRecordMap<KS,R>> extends Object implements NearCacheRecordStore<K,V>, EvictionListener<KS,R>
NearCacheRecordStore and EvictionListener.| Modifier and Type | Class and Description |
|---|---|
protected class |
AbstractNearCacheRecordStore.ReserveForUpdateFunction |
| Modifier and Type | Field and Description |
|---|---|
protected ClassLoader |
classLoader |
protected EvictionChecker |
evictionChecker |
protected boolean |
evictionDisabled |
protected EvictionPolicyEvaluator<KS,R> |
evictionPolicyEvaluator |
protected SamplingEvictionStrategy<KS,R,NCRM> |
evictionStrategy |
protected InMemoryFormat |
inMemoryFormat |
protected long |
maxIdleMillis |
protected static long |
MILLI_SECONDS_IN_A_SECOND |
protected NearCacheConfig |
nearCacheConfig |
protected NearCacheStatsImpl |
nearCacheStats |
protected NCRM |
records |
protected static long |
REFERENCE_SIZE
If Unsafe is available, Object array index scale (every index represents a reference)
can be assumed as reference size.
|
protected static AtomicLongFieldUpdater<AbstractNearCacheRecordStore> |
RESERVATION_ID |
protected long |
reservationId |
protected SerializationService |
serializationService |
protected StaleReadDetector |
staleReadDetector |
protected long |
timeToLiveMillis |
NO_LISTENER| Modifier | Constructor and Description |
|---|---|
protected |
AbstractNearCacheRecordStore(NearCacheConfig nearCacheConfig,
NearCacheStatsImpl nearCacheStats,
SerializationService serializationService,
ClassLoader classLoader) |
|
AbstractNearCacheRecordStore(NearCacheConfig nearCacheConfig,
SerializationService serializationService,
ClassLoader classLoader) |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
canUpdateStats(R record) |
protected void |
checkAvailable() |
void |
clear()
Removes all stored values.
|
protected abstract boolean |
containsRecordKey(K key) |
protected abstract EvictionChecker |
createNearCacheEvictionChecker(EvictionConfig evictionConfig,
NearCacheConfig nearCacheConfig) |
protected abstract NCRM |
createNearCacheRecordMap(NearCacheConfig nearCacheConfig) |
protected abstract R |
createRecord(V value) |
void |
destroy()
Clears the record store and destroys it.
|
void |
doEviction(boolean withoutMaxSizeCheck)
Does eviction as specified configuration
EvictionConfig
in NearCacheConfig. |
V |
get(K key)
Gets the value associated with the given
key. |
protected abstract long |
getKeyStorageMemoryCost(K key) |
NearCacheStats |
getNearCacheStats()
Get the
NearCacheStats instance to monitor this record store. |
protected abstract R |
getOrCreateToReserve(K key,
Data keyData) |
abstract R |
getRecord(K key)
Gets the record associated with the given
key. |
protected abstract long |
getRecordStorageMemoryCost(R record) |
StaleReadDetector |
getStaleReadDetector() |
protected long |
getTotalStorageMemoryCost(K key,
R record) |
void |
initialize() |
protected boolean |
isRecordExpired(R record) |
void |
onEvict(KS key,
R record,
boolean wasExpired)
Called when an
Evictable entry is evicted. |
protected void |
onExpire(K key,
R record) |
protected void |
onGet(K key,
V value,
R record) |
protected void |
onGetError(K key,
V value,
R record,
Throwable error) |
protected void |
onPut(K key,
V value,
R record,
R oldRecord) |
protected void |
onPutError(K key,
V value,
R record,
R oldRecord,
Throwable error) |
protected void |
onRecordCreate(K key,
Data keyData,
R record) |
protected void |
onRemove(K key,
R record,
boolean removed) |
protected void |
onRemoveError(K key,
R record,
boolean removed,
Throwable error) |
void |
put(K key,
Data keyData,
V value,
Data valueData)
Puts (associates) a value with the given
key. |
protected abstract R |
putRecord(K key,
R record) |
protected V |
recordToValue(R record) |
void |
setStaleReadDetector(StaleReadDetector staleReadDetector) |
int |
size()
Gets the number of stored records.
|
protected Data |
toData(Object obj) |
protected V |
toValue(Object obj) |
V |
tryPublishReserved(K key,
V value,
long reservationId,
boolean deserialize)
Tries to update reserved key with supplied value.
|
long |
tryReserveForUpdate(K key,
Data keyData)
Tries to reserve supplied key for update.
|
protected abstract V |
updateAndGetReserved(K key,
V value,
long reservationId,
boolean deserialize) |
protected abstract void |
updateRecordValue(R record,
V value) |
protected R |
updateReservedRecordInternal(K key,
V value,
R reservedRecord,
long reservationId) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdoExpiration, invalidate, loadKeys, storeKeysprotected static final AtomicLongFieldUpdater<AbstractNearCacheRecordStore> RESERVATION_ID
protected static final long REFERENCE_SIZE
Otherwise, we assume reference size as integer size that means we assume 32 bit JVM or compressed-references enabled 64 bit JVM by ignoring compressed-references disable mode on 64 bit JVM.
protected static final long MILLI_SECONDS_IN_A_SECOND
protected final long timeToLiveMillis
protected final long maxIdleMillis
protected final boolean evictionDisabled
protected final ClassLoader classLoader
protected final InMemoryFormat inMemoryFormat
protected final NearCacheConfig nearCacheConfig
protected final NearCacheStatsImpl nearCacheStats
protected final SerializationService serializationService
protected NCRM extends SampleableNearCacheRecordMap<KS,R> records
protected EvictionChecker evictionChecker
protected SamplingEvictionStrategy<KS,R extends NearCacheRecord,NCRM extends SampleableNearCacheRecordMap<KS,R>> evictionStrategy
protected EvictionPolicyEvaluator<KS,R extends NearCacheRecord> evictionPolicyEvaluator
protected volatile long reservationId
protected volatile StaleReadDetector staleReadDetector
public AbstractNearCacheRecordStore(NearCacheConfig nearCacheConfig, SerializationService serializationService, ClassLoader classLoader)
protected AbstractNearCacheRecordStore(NearCacheConfig nearCacheConfig, NearCacheStatsImpl nearCacheStats, SerializationService serializationService, ClassLoader classLoader)
public void initialize()
initialize in interface InitializingObjectpublic void setStaleReadDetector(StaleReadDetector staleReadDetector)
setStaleReadDetector in interface NearCacheRecordStore<K,V>StaleReadDetectorpublic abstract R getRecord(K key)
NearCacheRecordStorekey.getRecord in interface NearCacheRecordStore<K,V>key - the key from which to get the associated NearCacheRecord.NearCacheRecord associated with the given key.protected abstract EvictionChecker createNearCacheEvictionChecker(EvictionConfig evictionConfig, NearCacheConfig nearCacheConfig)
protected abstract NCRM createNearCacheRecordMap(NearCacheConfig nearCacheConfig)
protected abstract long getKeyStorageMemoryCost(K key)
protected abstract long getRecordStorageMemoryCost(R record)
protected abstract V updateAndGetReserved(K key, V value, long reservationId, boolean deserialize)
protected abstract boolean containsRecordKey(K key)
protected void checkAvailable()
protected boolean isRecordExpired(R record)
public void onEvict(KS key, R record, boolean wasExpired)
EvictionListenerEvictable entry is evicted.onEvict in interface EvictionListener<KS,R extends NearCacheRecord>key - Accessor of the Evictable entry that is evicted.record - Evictable entry that is evicted.wasExpired - true if the entry was evicted due to expiration, false otherwisepublic V get(K key)
NearCacheRecordStorekey.get in interface NearCacheRecordStore<K,V>key - the key from which to get the associated value.key.public void put(K key, Data keyData, V value, Data valueData)
NearCacheRecordStorekey.put in interface NearCacheRecordStore<K,V>key - the key to which the given value will be associated.keyData - the key as Data to which the given value will be associated.value - the value that will be associated with the key.protected boolean canUpdateStats(R record)
public void clear()
NearCacheRecordStoreclear in interface NearCacheRecordStore<K,V>public void destroy()
NearCacheRecordStoredestroy in interface NearCacheRecordStore<K,V>public NearCacheStats getNearCacheStats()
NearCacheRecordStoreNearCacheStats instance to monitor this record store.getNearCacheStats in interface NearCacheRecordStore<K,V>NearCacheStats instance to monitor this record store.public int size()
NearCacheRecordStoresize in interface NearCacheRecordStore<K,V>public void doEviction(boolean withoutMaxSizeCheck)
NearCacheRecordStoreEvictionConfig
in NearCacheConfig.doEviction in interface NearCacheRecordStore<K,V>withoutMaxSizeCheck - set true to evict regardless of a max
size check, otherwise set false to evict
after a max size check.public long tryReserveForUpdate(K key, Data keyData)
NearCacheRecordStoreIf one thread takes reservation, only that thread can update the key.
tryReserveForUpdate in interface NearCacheRecordStore<K,V>key - key to be reserved for updatekeyData - key to be reserved for update as DataNearCacheRecord.NOT_RESERVEDpublic V tryPublishReserved(K key, V value, long reservationId, boolean deserialize)
NearCacheRecordStoretryPublishReserved in interface NearCacheRecordStore<K,V>key - reserved key for updatevalue - value to be associated with reserved keyreservationId - ID for this reservationdeserialize - eagerly deserialize
returning valuetrue and update succeeds, otherwise returns nullpublic StaleReadDetector getStaleReadDetector()
Copyright © 2019 Hazelcast, Inc.. All Rights Reserved.