public abstract class AbstractCacheRecordStore<R extends CacheRecord,CRM extends SampleableCacheRecordMap<Data,R>> extends Object implements ICacheRecordStore, EvictionListener<Data,R>
UNIT_PERCENTAGE
NO_LISTENER
Constructor and Description |
---|
AbstractCacheRecordStore(String cacheNameWithPrefix,
int partitionId,
NodeEngine nodeEngine,
AbstractCacheService cacheService) |
Modifier and Type | Method and Description |
---|---|
R |
accessRecord(Data key,
R record,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
long now) |
void |
clear()
clears all internal data without publishing any events
|
void |
close(boolean onShutdown)
Close is equivalent to below operations in the given order:
close resources.
unregister all listeners.
|
protected void |
closeListeners() |
protected boolean |
compare(Object v1,
Object v2) |
boolean |
contains(Data key)
Determines if this store contains an entry for the specified key.
|
protected abstract CacheEntryProcessorEntry |
createCacheEntryProcessorEntry(Data key,
R record,
long now,
int completionId) |
protected EvictionChecker |
createCacheEvictionChecker(int size,
EvictionConfig.MaxSizePolicy maxSizePolicy)
Creates an instance for checking if the maximum cache size has been reached.
|
protected EvictionPolicyEvaluator<Data,R> |
createEvictionPolicyEvaluator(EvictionConfig evictionConfig) |
protected SamplingEvictionStrategy<Data,R,CRM> |
createEvictionStrategy(EvictionConfig cacheEvictionConfig) |
protected R |
createRecord(Data keyData,
Object value,
long expirationTime,
int completionId) |
protected R |
createRecord(Data key,
Object value,
long expiryTime,
long now,
boolean disableWriteThrough,
int completionId,
String origin) |
protected R |
createRecord(long expiryTime) |
protected R |
createRecord(Object value,
long expiryTime) |
protected abstract R |
createRecord(Object value,
long creationTime,
long expiryTime) |
protected abstract CRM |
createRecordCacheMap() |
protected R |
createRecordWithExpiry(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
long now,
boolean disableWriteThrough,
int completionId) |
protected R |
createRecordWithExpiry(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
long now,
boolean disableWriteThrough,
int completionId,
String origin) |
protected R |
createRecordWithExpiry(Data key,
Object value,
long expiryTime,
long now,
boolean disableWriteThrough,
int completionId) |
protected R |
createRecordWithExpiry(Data key,
Object value,
long expiryTime,
long now,
boolean disableWriteThrough,
int completionId,
String origin) |
protected abstract Object |
dataToValue(Data data) |
protected void |
deleteAllCacheEntry(Set<Data> keys) |
protected void |
deleteCacheEntry(Data key) |
protected boolean |
deleteRecord(Data key,
int completionId) |
protected boolean |
deleteRecord(Data key,
int completionId,
String source) |
protected boolean |
deleteRecord(Data key,
int completionId,
String source,
String origin) |
void |
destroy()
Destroy is equivalent to below operations in the given order:
clear all.
close resources.
unregister all listeners.
|
R |
doPutRecord(Data key,
R record) |
protected R |
doPutRecord(Data key,
R record,
String source) |
protected R |
doRemoveRecord(Data key) |
protected R |
doRemoveRecord(Data key,
String source) |
boolean |
evictIfRequired()
Evict cache record store if eviction is required.
|
CacheEntryIterationResult |
fetchEntries(int tableIndex,
int size)
Starting from the provided table index, a set of entries are returned with a maximum size of
size |
CacheKeyIterationResult |
fetchKeys(int tableIndex,
int size)
Starting from the provided table index, a set of keys are returned with a maximum size of
size |
Object |
get(Data key,
javax.cache.expiry.ExpiryPolicy expiryPolicy)
Gets the value to which the specified key is mapped,
or
null if this cache contains no mapping for the key. |
MapEntries |
getAll(Set<Data> keySet,
javax.cache.expiry.ExpiryPolicy expiryPolicy)
Gets a collection of entries from the store, returning them as
Map of the values associated with the set of keys requested. |
Object |
getAndPut(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
int completionId)
Associates the specified value with the specified key in this cache,
returning an existing value if one existed.
|
Object |
getAndRemove(Data key,
String source,
int completionId)
Atomically removes the entry for a key only if it is currently mapped to some
value.
|
Object |
getAndRemove(Data key,
String source,
int completionId,
String origin) |
Object |
getAndReplace(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
int completionId)
Atomically replaces the value for a given key if and only if there is a
value currently mapped by the key.
|
CacheStatisticsImpl |
getCacheStats()
Gets the Cache statistics associated with this
CacheService . |
CacheConfig |
getConfig()
Gets the configuration of the cache that this store belongs to.
|
protected javax.cache.expiry.ExpiryPolicy |
getExpiryPolicy(javax.cache.expiry.ExpiryPolicy expiryPolicy) |
String |
getName()
Gets the name of the distributed object name of the cache.
|
ObjectNamespace |
getObjectNamespace()
Returns
ObjectNamespace associated with this record store. |
Map<Data,CacheRecord> |
getReadOnlyRecords()
Returns a readonly map of the internal key value store.
|
CacheRecord |
getRecord(Data key)
Gets internal record of the store by key.
|
void |
init()
Initializes record store.
|
void |
instrument(NodeEngine nodeEngine) |
protected void |
invalidateAllEntries() |
protected void |
invalidateAllEntries(String source) |
protected void |
invalidateEntry(Data key) |
protected void |
invalidateEntry(Data key,
String source) |
Object |
invoke(Data key,
javax.cache.processor.EntryProcessor entryProcessor,
Object[] arguments,
int completionId)
Invokes an
EntryProcessor against the Cache.Entry specified by
the provided key. |
protected boolean |
isEventsEnabled() |
protected boolean |
isEvictionEnabled() |
protected boolean |
isInvalidationEnabled() |
protected boolean |
isReadThrough() |
protected boolean |
isStatisticsEnabled() |
boolean |
isWanReplicationEnabled()
Determines whether wan replication is enabled or not for this record store.
|
protected boolean |
isWriteThrough() |
Set<Data> |
loadAll(Set<Data> keys,
boolean replaceExistingValues)
Synchronously loads the specified entries into the cache using the
configured
CacheLoader for the given keys. |
protected Map<Data,Object> |
loadAllCacheEntry(Set<Data> keys) |
protected void |
onCreateRecordError(Data key,
Object value,
long expiryTime,
long now,
boolean disableWriteThrough,
int completionId,
String origin,
R record,
Throwable error) |
protected void |
onDeleteRecord(Data key,
R record,
Data dataValue,
boolean deleted) |
protected void |
onDeleteRecordError(Data key,
R record,
Data dataValue,
boolean deleted,
Throwable error) |
protected void |
onDestroy() |
void |
onEvict(Data key,
R record,
boolean wasExpired)
Called when an
Evictable entry is evicted. |
protected void |
onGet(Data key,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
Object value,
R record) |
protected void |
onGetError(Data key,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
Object value,
R record,
Throwable error) |
protected void |
onProcessExpiredEntry(Data key,
R record,
long expiryTime,
long now,
String source,
String origin) |
protected void |
onPut(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
boolean getValue,
boolean disableWriteThrough,
R record,
Object oldValue,
boolean isExpired,
boolean isNewPut,
boolean isSaveSucceed) |
protected void |
onPutError(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
boolean getValue,
boolean disableWriteThrough,
R record,
Object oldValue,
boolean wouldBeNewPut,
Throwable error) |
protected void |
onPutIfAbsent(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
boolean disableWriteThrough,
R record,
boolean isExpired,
boolean isSaveSucceed) |
protected void |
onPutIfAbsentError(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
boolean disableWriteThrough,
R record,
Throwable error) |
protected long |
onRecordAccess(Data key,
R record,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
long now) |
protected void |
onRemove(Data key,
Object value,
String source,
boolean getValue,
R record,
boolean removed) |
protected void |
onRemoveError(Data key,
Object value,
String source,
boolean getValue,
R record,
boolean removed,
Throwable error) |
protected void |
onReplace(Data key,
Object oldValue,
Object newValue,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
boolean getValue,
R record,
boolean isExpired,
boolean replaced) |
protected void |
onReplaceError(Data key,
Object oldValue,
Object newValue,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
boolean getValue,
R record,
boolean isExpired,
boolean replaced,
Throwable error) |
protected void |
onUpdateRecord(Data key,
R record,
Object value,
Data oldDataValue) |
protected void |
onUpdateRecordError(Data key,
R record,
Object value,
Data newDataValue,
Data oldDataValue,
Throwable error) |
protected boolean |
processExpiredEntry(Data key,
R record,
long now) |
protected R |
processExpiredEntry(Data key,
R record,
long expiryTime,
long now,
String source) |
protected R |
processExpiredEntry(Data key,
R record,
long expiryTime,
long now,
String source,
String origin) |
protected boolean |
processExpiredEntry(Data key,
R record,
long now,
String source) |
protected boolean |
processExpiredEntry(Data key,
R record,
long now,
String source,
String origin) |
protected void |
publishBatchedEvents(String cacheName,
CacheEventType cacheEventType,
int orderKey) |
protected void |
publishEvent(CacheEventContext cacheEventContext) |
protected Object |
put(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
boolean getValue,
boolean disableWriteThrough,
int completionId) |
protected Object |
put(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
boolean getValue,
int completionId) |
R |
put(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
int completionId)
Associates the specified value with the specified key in this cache,
returning an existing value if one existed.
|
protected boolean |
putIfAbsent(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
boolean disableWriteThrough,
int completionId) |
boolean |
putIfAbsent(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
int completionId)
Removes the mapping for a key from this cache if it is present.
|
void |
putRecord(Data key,
CacheRecord record)
Associates the specified record with the specified key.
|
Object |
readThroughCache(Data key) |
R |
readThroughRecord(Data key,
long now) |
protected abstract Data |
recordToData(R record) |
protected abstract Object |
recordToValue(R record) |
boolean |
remove(Data key,
Object value,
String source,
int completionId)
Atomically removes the mapping for a key only if currently mapped to the
given value.
|
boolean |
remove(Data key,
Object value,
String source,
int completionId,
String origin) |
boolean |
remove(Data key,
String source,
int completionId)
Removes the mapping for a key from this cache if it is present.
|
boolean |
remove(Data key,
String source,
int completionId,
String origin) |
void |
removeAll(Set<Data> keys,
int completionId)
records of keys will be deleted one by one and will publish a REMOVE event
for each key.
|
CacheRecord |
removeRecord(Data key)
Removes the record for a key.
|
boolean |
replace(Data key,
Object value,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
int completionId)
Atomically replaces the entry for a key only if currently mapped to some
value.
|
boolean |
replace(Data key,
Object oldValue,
Object newValue,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
String source,
int completionId)
Atomically replaces the entry for a key only if currently mapped to a
given value.
|
int |
size()
Calculates the entry size of this store which reflects the partition size of the cache.
|
protected Data |
toData(Object obj) |
Data |
toEventData(Object obj) |
protected abstract Data |
toHeapData(Object obj) |
protected Object |
toStorageValue(Object obj) |
protected Object |
toValue(Object obj) |
protected long |
updateAccessDuration(Data key,
R record,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
long now) |
protected void |
updateGetAndPutStat(boolean isPutSucceed,
boolean getValue,
boolean oldValueNull,
long start) |
protected void |
updateRecord(Data key,
R record,
Object value,
long expiryTime,
long now,
boolean disableWriteThrough,
int completionId,
String source,
String origin) |
protected void |
updateRecordValue(R record,
Object recordValue) |
protected boolean |
updateRecordWithExpiry(Data key,
Object value,
R record,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
long now,
boolean disableWriteThrough,
int completionId) |
protected boolean |
updateRecordWithExpiry(Data key,
Object value,
R record,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
long now,
boolean disableWriteThrough,
int completionId,
String source) |
protected boolean |
updateRecordWithExpiry(Data key,
Object value,
R record,
javax.cache.expiry.ExpiryPolicy expiryPolicy,
long now,
boolean disableWriteThrough,
int completionId,
String source,
String origin) |
protected boolean |
updateRecordWithExpiry(Data key,
Object value,
R record,
long expiryTime,
long now,
boolean disableWriteThrough,
int completionId) |
protected boolean |
updateRecordWithExpiry(Data key,
Object value,
R record,
long expiryTime,
long now,
boolean disableWriteThrough,
int completionId,
String source) |
protected boolean |
updateRecordWithExpiry(Data key,
Object value,
R record,
long expiryTime,
long now,
boolean disableWriteThrough,
int completionId,
String source,
String origin) |
protected void |
updateReplaceStat(boolean result,
boolean isHit,
long start) |
protected abstract Data |
valueToData(Object value) |
void |
writeThroughCache(Data key,
Object value) |
public static final String SOURCE_NOT_AVAILABLE
protected static final int DEFAULT_INITIAL_CAPACITY
protected final String name
protected final int partitionId
protected final int partitionCount
protected final NodeEngine nodeEngine
protected final AbstractCacheService cacheService
protected final CacheConfig cacheConfig
protected final EventJournalConfig eventJournalConfig
protected final EvictionConfig evictionConfig
protected final Map<CacheEventType,Set<CacheEventData>> batchEvent
protected final EvictionChecker evictionChecker
protected final EvictionPolicyEvaluator<Data,R extends CacheRecord> evictionPolicyEvaluator
protected final SamplingEvictionStrategy<Data,R extends CacheRecord,CRM extends SampleableCacheRecordMap<Data,R>> evictionStrategy
protected final ObjectNamespace objectNamespace
protected final boolean wanReplicationEnabled
protected final boolean disablePerEntryInvalidationEvents
protected CRM extends SampleableCacheRecordMap<Data,R> records
protected CacheContext cacheContext
protected CacheStatisticsImpl statistics
protected javax.cache.integration.CacheLoader cacheLoader
protected javax.cache.integration.CacheWriter cacheWriter
protected boolean eventsEnabled
protected boolean eventsBatchingEnabled
protected javax.cache.expiry.ExpiryPolicy defaultExpiryPolicy
protected boolean primary
public AbstractCacheRecordStore(String cacheNameWithPrefix, int partitionId, NodeEngine nodeEngine, AbstractCacheService cacheService)
public void instrument(NodeEngine nodeEngine)
public void init()
ICacheRecordStore
init
in interface ICacheRecordStore
protected boolean isReadThrough()
protected boolean isWriteThrough()
protected boolean isStatisticsEnabled()
protected abstract CRM createRecordCacheMap()
protected abstract CacheEntryProcessorEntry createCacheEntryProcessorEntry(Data key, R record, long now, int completionId)
protected EvictionChecker createCacheEvictionChecker(int size, EvictionConfig.MaxSizePolicy maxSizePolicy)
EvictionConfig.MaxSizePolicy.ENTRY_COUNT
policy. Returns null if other maxSizePolicy
is used.size
- the maximum number of entriesmaxSizePolicy
- the way in which the size is interpreted, only the EvictionConfig.MaxSizePolicy.ENTRY_COUNT
policy is
supported.maxSizePolicy
is not EvictionConfig.MaxSizePolicy.ENTRY_COUNT
IllegalArgumentException
- if the maxSizePolicy
is nullprotected EvictionPolicyEvaluator<Data,R> createEvictionPolicyEvaluator(EvictionConfig evictionConfig)
protected SamplingEvictionStrategy<Data,R,CRM> createEvictionStrategy(EvictionConfig cacheEvictionConfig)
protected boolean isEvictionEnabled()
protected boolean isEventsEnabled()
protected boolean isInvalidationEnabled()
public boolean evictIfRequired()
ICacheRecordStore
Eviction logic is handled as specified EvictionPolicy
in CacheConfig
for this record store
evictIfRequired
in interface ICacheRecordStore
protected javax.cache.expiry.ExpiryPolicy getExpiryPolicy(javax.cache.expiry.ExpiryPolicy expiryPolicy)
protected boolean processExpiredEntry(Data key, R record, long now, String source)
protected boolean processExpiredEntry(Data key, R record, long now, String source, String origin)
protected R processExpiredEntry(Data key, R record, long expiryTime, long now, String source)
protected R processExpiredEntry(Data key, R record, long expiryTime, long now, String source, String origin)
protected void onProcessExpiredEntry(Data key, R record, long expiryTime, long now, String source, String origin)
public R accessRecord(Data key, R record, javax.cache.expiry.ExpiryPolicy expiryPolicy, long now)
public void onEvict(Data key, R record, boolean wasExpired)
EvictionListener
Evictable
entry is evicted.onEvict
in interface EvictionListener<Data,R extends CacheRecord>
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
otherwiseprotected void invalidateEntry(Data key)
protected void invalidateAllEntries()
protected void invalidateAllEntries(String source)
protected void updateGetAndPutStat(boolean isPutSucceed, boolean getValue, boolean oldValueNull, long start)
protected long updateAccessDuration(Data key, R record, javax.cache.expiry.ExpiryPolicy expiryPolicy, long now)
protected long onRecordAccess(Data key, R record, javax.cache.expiry.ExpiryPolicy expiryPolicy, long now)
protected void updateReplaceStat(boolean result, boolean isHit, long start)
protected void publishEvent(CacheEventContext cacheEventContext)
protected void publishBatchedEvents(String cacheName, CacheEventType cacheEventType, int orderKey)
protected R createRecord(long expiryTime)
protected R createRecord(Data keyData, Object value, long expirationTime, int completionId)
protected void onCreateRecordError(Data key, Object value, long expiryTime, long now, boolean disableWriteThrough, int completionId, String origin, R record, Throwable error)
protected R createRecord(Data key, Object value, long expiryTime, long now, boolean disableWriteThrough, int completionId, String origin)
protected R createRecordWithExpiry(Data key, Object value, long expiryTime, long now, boolean disableWriteThrough, int completionId, String origin)
protected R createRecordWithExpiry(Data key, Object value, long expiryTime, long now, boolean disableWriteThrough, int completionId)
protected R createRecordWithExpiry(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, long now, boolean disableWriteThrough, int completionId)
protected R createRecordWithExpiry(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, long now, boolean disableWriteThrough, int completionId, String origin)
protected void onUpdateRecordError(Data key, R record, Object value, Data newDataValue, Data oldDataValue, Throwable error)
protected void updateRecord(Data key, R record, Object value, long expiryTime, long now, boolean disableWriteThrough, int completionId, String source, String origin)
protected boolean updateRecordWithExpiry(Data key, Object value, R record, long expiryTime, long now, boolean disableWriteThrough, int completionId, String source, String origin)
protected boolean updateRecordWithExpiry(Data key, Object value, R record, long expiryTime, long now, boolean disableWriteThrough, int completionId)
protected boolean updateRecordWithExpiry(Data key, Object value, R record, long expiryTime, long now, boolean disableWriteThrough, int completionId, String source)
protected boolean updateRecordWithExpiry(Data key, Object value, R record, javax.cache.expiry.ExpiryPolicy expiryPolicy, long now, boolean disableWriteThrough, int completionId)
protected boolean updateRecordWithExpiry(Data key, Object value, R record, javax.cache.expiry.ExpiryPolicy expiryPolicy, long now, boolean disableWriteThrough, int completionId, String source)
protected boolean updateRecordWithExpiry(Data key, Object value, R record, javax.cache.expiry.ExpiryPolicy expiryPolicy, long now, boolean disableWriteThrough, int completionId, String source, String origin)
protected void onDeleteRecordError(Data key, R record, Data dataValue, boolean deleted, Throwable error)
protected boolean deleteRecord(Data key, int completionId)
protected boolean deleteRecord(Data key, int completionId, String source, String origin)
public Object readThroughCache(Data key) throws javax.cache.integration.CacheLoaderException
javax.cache.integration.CacheLoaderException
public void writeThroughCache(Data key, Object value) throws javax.cache.integration.CacheWriterException
javax.cache.integration.CacheWriterException
protected void deleteCacheEntry(Data key)
public CacheRecord getRecord(Data key)
ICacheRecordStore
getRecord
in interface ICacheRecordStore
key
- the key to the entry.CacheRecord
instance mapped.public void putRecord(Data key, CacheRecord record)
ICacheRecordStore
putRecord
in interface ICacheRecordStore
key
- the key to the entry.record
- the value to be associated with the specified key.public CacheRecord removeRecord(Data key)
ICacheRecordStore
removeRecord
in interface ICacheRecordStore
key
- the key to the entry.protected void onGet(Data key, javax.cache.expiry.ExpiryPolicy expiryPolicy, Object value, R record)
protected void onGetError(Data key, javax.cache.expiry.ExpiryPolicy expiryPolicy, Object value, R record, Throwable error)
public Object get(Data key, javax.cache.expiry.ExpiryPolicy expiryPolicy)
ICacheRecordStore
null
if this cache contains no mapping for the key.
If the cache is configured to use read-through, and get would return null
because the entry is missing from the cache, the Cache's CacheLoader
is called in an attempt to load the entry.
get
in interface ICacheRecordStore
key
- the key whose associated value is to be returned.expiryPolicy
- custom expiry policy or null to use configured default value.public boolean contains(Data key)
ICacheRecordStore
More formally, returns true if and only if this store contains a mapping for a key k such that key.equals(k) (There can be at most one such mapping.)
contains
in interface ICacheRecordStore
key
- key whose presence in this store is to be tested.protected void onPut(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, boolean getValue, boolean disableWriteThrough, R record, Object oldValue, boolean isExpired, boolean isNewPut, boolean isSaveSucceed)
protected void onPutError(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, boolean getValue, boolean disableWriteThrough, R record, Object oldValue, boolean wouldBeNewPut, Throwable error)
protected Object put(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, boolean getValue, boolean disableWriteThrough, int completionId)
protected Object put(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, boolean getValue, int completionId)
public R put(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, int completionId)
ICacheRecordStore
If the cache previously contained a mapping for
the key, the old value is replaced by the specified value. (A cache
c is said to contain a mapping for a key k if and only
if c.contains(k)
would return
true.)
The previous value is returned, or null if there was no value associated with the key previously.
put
in interface ICacheRecordStore
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.expiryPolicy
- custom expiry policy or null to use configured default value.source
- uuid of the calling node or client.CacheRecord
(added as new record or updated). null
if record has expired.public Object getAndPut(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, int completionId)
ICacheRecordStore
If the cache previously contained a mapping for
the key, the old value is replaced by the specified value. (A cache
c is said to contain a mapping for a key k if and only
if c.contains(k)
would return
true.)
The previous value is returned, or null if there was no value associated with the key previously.
getAndPut
in interface ICacheRecordStore
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.expiryPolicy
- custom expiry policy or null to use configured default value.source
- uuid of the calling node or client.protected void onPutIfAbsent(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, boolean disableWriteThrough, R record, boolean isExpired, boolean isSaveSucceed)
protected void onPutIfAbsentError(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, boolean disableWriteThrough, R record, Throwable error)
protected boolean putIfAbsent(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, boolean disableWriteThrough, int completionId)
public boolean putIfAbsent(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, int completionId)
ICacheRecordStore
More formally, if this cache contains a mapping from key k to
value v such that
(key==null ? k==null : key.equals(k))
, that mapping is removed.
(The cache can contain at most one such mapping.)
Returns true if this cache previously associated the key, or false if the cache contained no mapping for the key.
The cache will not contain a mapping for the specified key once the call returns.
putIfAbsent
in interface ICacheRecordStore
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.expiryPolicy
- custom expiry policy or null to use configured default value.source
- uuid of the calling node or client.protected void onReplace(Data key, Object oldValue, Object newValue, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, boolean getValue, R record, boolean isExpired, boolean replaced)
protected void onReplaceError(Data key, Object oldValue, Object newValue, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, boolean getValue, R record, boolean isExpired, boolean replaced, Throwable error)
public boolean replace(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, int completionId)
ICacheRecordStore
This is equivalent to
if (cache.containsKey(key)) {
cache.put(key, value);
return true;
} else {
return false;
}
except that the action is performed atomically.replace
in interface ICacheRecordStore
key
- the key with which the specified value is associated.value
- the value to be associated with the specified key.expiryPolicy
- custom expiry policy or null to use configured default value.source
- uuid of the calling node or client.public boolean replace(Data key, Object oldValue, Object newValue, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, int completionId)
ICacheRecordStore
This is equivalent to:
if (cache.containsKey(key) && equals(cache.get(key), oldValue)) {
cache.put(key, newValue);
return true;
} else {
return false;
}
except that the action is performed atomically.replace
in interface ICacheRecordStore
key
- key with which the specified value is associated.oldValue
- value expected to be associated with the specified key.newValue
- value to be associated with the specified key.expiryPolicy
- custom expiry policy or null to use configured default value.source
- uuid of the calling node or client.public Object getAndReplace(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String source, int completionId)
ICacheRecordStore
This is equivalent to
if (cache.containsKey(key)) {
V oldValue = cache.get(key);
cache.put(key, value);
return oldValue;
} else {
return null;
}
except that the action is performed atomically.getAndReplace
in interface ICacheRecordStore
key
- key with which the specified value is associated.value
- value to be associated with the specified key.expiryPolicy
- custom expiry policy or null to use configured default value.source
- uuid of the calling node or client.protected void onRemove(Data key, Object value, String source, boolean getValue, R record, boolean removed)
protected void onRemoveError(Data key, Object value, String source, boolean getValue, R record, boolean removed, Throwable error)
public boolean remove(Data key, String source, int completionId)
ICacheRecordStore
More formally, if this cache contains a mapping from key k to
value v such that
(key==null ? k==null : key.equals(k))
, that mapping is removed.
(The cache can contain at most one such mapping.)
Returns true if this cache previously associated the key, or false if the cache contained no mapping for the key.
The cache will not contain a mapping for the specified key once the call returns.
remove
in interface ICacheRecordStore
key
- key whose mapping is to be removed from the cache.source
- uuid of the calling node or client.public boolean remove(Data key, Object value, String source, int completionId)
ICacheRecordStore
This is equivalent to:
if (cache.containsKey(key) && equals(cache.get(key), oldValue) {
cache.remove(key);
return true;
} else {
return false;
}
except that the action is performed atomically.remove
in interface ICacheRecordStore
key
- key whose mapping is to be removed from the cache.value
- value expected to be associated with the specified key.source
- uuid of the calling node or client.public boolean remove(Data key, Object value, String source, int completionId, String origin)
public Object getAndRemove(Data key, String source, int completionId)
ICacheRecordStore
This is equivalent to:
if (cache.containsKey(key)) {
V oldValue = cache.get(key);
cache.remove(key);
return oldValue;
} else {
return null;
}
except that the action is performed atomically.getAndRemove
in interface ICacheRecordStore
key
- key with which the specified value is associated.source
- uuid of the calling node or client.public MapEntries getAll(Set<Data> keySet, javax.cache.expiry.ExpiryPolicy expiryPolicy)
ICacheRecordStore
Map
of the values associated with the set of keys requested.
If the cache is configured read-through, and a get for a key would
return null because an entry is missing from the cache, the Cache's
CacheLoader
is called in an attempt to load the entry. If an
entry cannot be loaded for a given key, the key will not be present in
the returned Map.
getAll
in interface ICacheRecordStore
keySet
- keys whose associated values are to be returned.expiryPolicy
- custom expiry policy or null to use configured default value.public void removeAll(Set<Data> keys, int completionId)
ICacheRecordStore
removeAll
in interface ICacheRecordStore
keys
- set of keys to be cleaned.public Set<Data> loadAll(Set<Data> keys, boolean replaceExistingValues)
ICacheRecordStore
CacheLoader
for the given keys.
If an entry for a key already exists in the cache, a value will be loaded
if and only if replaceExistingValues
is true. If no loader
is configured for the cache, no objects will be loaded.
loadAll
in interface ICacheRecordStore
keys
- the keys to be loaded.replaceExistingValues
- when true, existing values in the cache will
be replaced by those loaded from a CacheLoader.public CacheKeyIterationResult fetchKeys(int tableIndex, int size)
ICacheRecordStore
size
fetchKeys
in interface ICacheRecordStore
tableIndex
- initial table index.size
- maximum key set size.CacheKeyIterationResult
which wraps keys and last tableIndex.public CacheEntryIterationResult fetchEntries(int tableIndex, int size)
ICacheRecordStore
size
fetchEntries
in interface ICacheRecordStore
tableIndex
- initial table index.size
- maximum entry set size.CacheEntryIterationResult
which wraps entries and last tableIndex.public Object invoke(Data key, javax.cache.processor.EntryProcessor entryProcessor, Object[] arguments, int completionId)
ICacheRecordStore
EntryProcessor
against the Cache.Entry
specified by
the provided key. If an Cache.Entry
does not exist for the specified key,
an attempt is made to load it (if a loader is configured) or a surrogate
Cache.Entry
, consisting of the key with a null value is used instead.
invoke
in interface ICacheRecordStore
key
- the key of the entry.entryProcessor
- the EntryProcessor
to be invoked.arguments
- additional arguments to be passed to the
EntryProcessor
.EntryProcessor
implementation.public int size()
ICacheRecordStore
size
in interface ICacheRecordStore
public CacheStatisticsImpl getCacheStats()
ICacheRecordStore
CacheService
.getCacheStats
in interface ICacheRecordStore
CacheStatisticsImpl
cache statistics.public CacheConfig getConfig()
ICacheRecordStore
getConfig
in interface ICacheRecordStore
CacheConfig
public String getName()
getName
in interface ICacheRecordStore
public Map<Data,CacheRecord> getReadOnlyRecords()
ICacheRecordStore
getReadOnlyRecords
in interface ICacheRecordStore
public void clear()
ICacheRecordStore
clear
in interface ICacheRecordStore
public void close(boolean onShutdown)
ICacheRecordStore
close
in interface ICacheRecordStore
onShutdown
- true if close
is called during CacheService shutdown,
false otherwise.ICacheRecordStore.clear()
,
ICacheRecordStore.destroy()
public void destroy()
ICacheRecordStore
destroy
in interface ICacheRecordStore
ICacheRecordStore.clear()
,
ICacheRecordStore.close(boolean)
protected void onDestroy()
protected void closeListeners()
public boolean isWanReplicationEnabled()
ICacheRecordStore
isWanReplicationEnabled
in interface ICacheRecordStore
public ObjectNamespace getObjectNamespace()
ICacheRecordStore
ObjectNamespace
associated with this record store.getObjectNamespace
in interface ICacheRecordStore
Copyright © 2018 Hazelcast, Inc.. All Rights Reserved.