com.hazelcast.cache.impl
Class AbstractCacheRecordStore<R extends CacheRecord,CRM extends SampleableCacheRecordMap<Data,R>>

java.lang.Object
  extended by com.hazelcast.cache.impl.AbstractCacheRecordStore<R,CRM>
All Implemented Interfaces:
ICacheRecordStore
Direct Known Subclasses:
CacheRecordStore

public abstract class AbstractCacheRecordStore<R extends CacheRecord,CRM extends SampleableCacheRecordMap<Data,R>>
extends Object
implements ICacheRecordStore

Author:
sozal 14/10/14

Nested Class Summary
protected  class AbstractCacheRecordStore.MaxSizeEvictionChecker
           
 
Field Summary
protected  Map<CacheEventType,Set<CacheEventData>> batchEvent
           
protected  CacheConfig cacheConfig
           
protected  javax.cache.integration.CacheLoader cacheLoader
           
protected  AbstractCacheService cacheService
           
protected  javax.cache.integration.CacheWriter cacheWriter
           
protected static int DEFAULT_INITIAL_CAPACITY
           
protected  javax.cache.expiry.ExpiryPolicy defaultExpiryPolicy
           
protected  EvictionChecker evictionChecker
           
protected  CacheEvictionConfig evictionConfig
           
protected  EvictionPolicyEvaluator<Data,R> evictionPolicyEvaluator
           
protected  EvictionStrategy<Data,R,CRM> evictionStrategy
           
protected  boolean hasExpiringEntry
           
protected  boolean isEventBatchingEnabled
           
protected  boolean isEventsEnabled
           
protected  CacheMaxSizeChecker maxSizeChecker
           
protected  String name
           
protected  NodeEngine nodeEngine
           
protected  int partitionCount
           
protected  int partitionId
           
protected  CRM records
           
protected  CacheStatisticsImpl statistics
           
 
Fields inherited from interface com.hazelcast.cache.impl.ICacheRecordStore
ONE_HUNDRED_PERCENT
 
Constructor Summary
AbstractCacheRecordStore(String name, int partitionId, NodeEngine nodeEngine, AbstractCacheService cacheService)
           
 
Method Summary
 R accessRecord(R record, javax.cache.expiry.ExpiryPolicy expiryPolicy, long now)
           
 void clear()
          clears all internal data without publishing any events
protected  void closeListeners()
           
protected  void closeResources()
           
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  CacheMaxSizeChecker createCacheMaxSizeChecker(int size, CacheEvictionConfig.CacheMaxSizePolicy maxSizePolicy)
           
protected  EvictionChecker createEvictionChecker(CacheEvictionConfig cacheEvictionConfig)
           
protected  R createRecord(Data keyData, Object value, long expirationTime, int completionId)
           
protected  R createRecord(long expiryTime)
           
protected  R createRecord(Object value, long expiryTime)
           
protected abstract
<T> R
createRecord(T value, long creationTime, long expiryTime)
           
protected abstract  CRM createRecordCacheMap()
           
 R createRecordWithExpiry(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, long now, boolean disableWriteThrough, int completionId)
           
protected  EvictionPolicyEvaluator<Data,R> creatEvictionPolicyEvaluator(CacheEvictionConfig cacheEvictionConfig)
           
protected  EvictionStrategy<Data,R,CRM> creatEvictionStrategy(CacheEvictionConfig cacheEvictionConfig)
           
protected abstract  R dataToRecord(Data data)
           
protected abstract
<T> T
dataToValue(Data data)
           
protected  void deleteAllCacheEntry(Set<Data> keys)
           
protected  void deleteCacheEntry(Data key)
           
protected  boolean deleteRecord(Data key, int completionId)
           
 void destroy()
          Destroy is equivalent to below operations in the given order: clear all. close resources. unregister all listeners.
 int evictIfRequired()
          Evict cache record store if eviction is required.
protected  long expiryPolicyToTTL(javax.cache.expiry.ExpiryPolicy expiryPolicy)
           
 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.
 MapEntrySet 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 caller, 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 caller, int completionId)
          Atomically removes the entry for a key only if it is currently mapped to some value.
 Object getAndReplace(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, 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.
 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.
 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.
 boolean isEvictionEnabled()
           
protected  boolean isEvictionRequired()
           
protected  boolean isReadThrough()
           
protected  boolean isStatisticsEnabled()
           
protected  boolean isWriteThrough()
           
 CacheKeyIteratorResult iterator(int tableIndex, int size)
          Starting from the provided table index, a set of keys are returned with a maximum size of size
 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 onDeleteRecord(Data key, R record, Data dataValue, boolean deleted)
           
protected  void onDeleteRecordError(Data key, R record, Data dataValue, boolean deleted, Throwable error)
           
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 onPut(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, 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 caller, 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 caller, boolean disableWriteThrough, R record, boolean isExpired, boolean isSaveSucceed)
           
protected  void onPutIfAbsentError(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, boolean disableWriteThrough, R record, Throwable error)
           
protected  long onRecordAccess(R record, javax.cache.expiry.ExpiryPolicy expiryPolicy, long now)
           
protected  void onRemove(Data key, Object value, String caller, boolean getValue, R record, boolean removed)
           
protected  void onRemoveError(Data key, Object value, String caller, boolean getValue, R record, boolean removed, Throwable error)
           
protected  void onReplace(Data key, Object oldValue, Object newValue, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, boolean getValue, R record, boolean isExpired, boolean replaced)
           
protected  void onReplaceError(Data key, Object oldValue, Object newValue, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, 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)
           
 boolean processExpiredEntry(Data key, R record, long now)
           
 R processExpiredEntry(Data key, R record, long expiryTime, long now)
           
protected  void publishBatchedEvents(String cacheName, CacheEventType cacheEventType, int orderKey)
           
protected  void publishEvent(CacheEventType eventType, Data dataKey, Data dataOldValue, Data dataValue, boolean isOldValueAvailable, int completionId)
           
protected  Object put(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, boolean getValue, boolean disableWriteThrough, int completionId)
           
protected  Object put(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, boolean getValue, int completionId)
           
 void put(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, 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 caller, boolean disableWriteThrough, int completionId)
           
 boolean putIfAbsent(Data key, Object value, javax.cache.expiry.ExpiryPolicy expiryPolicy, String caller, 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
<T> T
recordToValue(R record)
           
 boolean remove(Data key, Object value, String caller, int completionId)
          Atomically removes the mapping for a key only if currently mapped to the given value.
 boolean remove(Data key, String caller, int completionId)
          Removes the mapping for a key from this cache if it is present.
 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 caller, 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 caller, int completionId)
          Atomically replaces the entry for a key only if currently mapped to a given value.
 void setRecord(Data key, CacheRecord record)
          Associates the specified record with the specified key.
 int size()
          Calculates the entry size of this store which reflects the partition size of the cache.
protected  Data toData(Object obj)
           
protected  Data toEventData(Object obj)
           
protected abstract  Data toHeapData(Object obj)
           
protected  R toRecord(Object obj)
           
protected
<T> T
toValue(Object obj)
           
protected  javax.cache.expiry.ExpiryPolicy ttlToExpirePolicy(long ttl)
           
protected  long updateAccessDuration(R record, javax.cache.expiry.ExpiryPolicy expiryPolicy, long now)
           
protected  void updateGetAndPutStat(boolean isPutSucceed, boolean getValue, boolean oldValueNull, long start)
           
protected  void updateHasExpiringEntry(R record)
           
protected  R updateRecord(Data key, R record, Object value, int completionId)
           
 boolean updateRecordWithExpiry(Data key, Object value, R record, javax.cache.expiry.ExpiryPolicy expiryPolicy, long now, boolean disableWriteThrough, int completionId)
           
protected  void updateReplaceStat(boolean result, boolean isHit, long start)
           
protected abstract
<T> Data
valueToData(T value)
           
protected abstract
<T> R
valueToRecord(T value)
           
 void writeThroughCache(Data key, Object value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_INITIAL_CAPACITY

protected static final int DEFAULT_INITIAL_CAPACITY
See Also:
Constant Field Values

name

protected final String name

partitionId

protected final int partitionId

partitionCount

protected final int partitionCount

nodeEngine

protected final NodeEngine nodeEngine

cacheService

protected final AbstractCacheService cacheService

cacheConfig

protected final CacheConfig cacheConfig

records

protected CRM extends SampleableCacheRecordMap<Data,R> records

statistics

protected CacheStatisticsImpl statistics

cacheLoader

protected javax.cache.integration.CacheLoader cacheLoader

cacheWriter

protected javax.cache.integration.CacheWriter cacheWriter

isEventsEnabled

protected boolean isEventsEnabled

isEventBatchingEnabled

protected boolean isEventBatchingEnabled

defaultExpiryPolicy

protected javax.cache.expiry.ExpiryPolicy defaultExpiryPolicy

evictionConfig

protected final CacheEvictionConfig evictionConfig

hasExpiringEntry

protected volatile boolean hasExpiringEntry

batchEvent

protected final Map<CacheEventType,Set<CacheEventData>> batchEvent

maxSizeChecker

protected final CacheMaxSizeChecker maxSizeChecker

evictionPolicyEvaluator

protected final EvictionPolicyEvaluator<Data,R extends CacheRecord> evictionPolicyEvaluator

evictionChecker

protected final EvictionChecker evictionChecker

evictionStrategy

protected final EvictionStrategy<Data,R extends CacheRecord,CRM extends SampleableCacheRecordMap<Data,R>> evictionStrategy
Constructor Detail

AbstractCacheRecordStore

public AbstractCacheRecordStore(String name,
                                int partitionId,
                                NodeEngine nodeEngine,
                                AbstractCacheService cacheService)
Method Detail

isReadThrough

protected boolean isReadThrough()

isWriteThrough

protected boolean isWriteThrough()

isStatisticsEnabled

protected boolean isStatisticsEnabled()

createRecordCacheMap

protected abstract CRM createRecordCacheMap()

createCacheEntryProcessorEntry

protected abstract CacheEntryProcessorEntry createCacheEntryProcessorEntry(Data key,
                                                                           R record,
                                                                           long now,
                                                                           int completionId)

createRecord

protected abstract <T> R createRecord(T value,
                                      long creationTime,
                                      long expiryTime)

valueToData

protected abstract <T> Data valueToData(T value)

dataToValue

protected abstract <T> T dataToValue(Data data)

valueToRecord

protected abstract <T> R valueToRecord(T value)

recordToValue

protected abstract <T> T recordToValue(R record)

recordToData

protected abstract Data recordToData(R record)

dataToRecord

protected abstract R dataToRecord(Data data)

toHeapData

protected abstract Data toHeapData(Object obj)

createCacheMaxSizeChecker

protected CacheMaxSizeChecker createCacheMaxSizeChecker(int size,
                                                        CacheEvictionConfig.CacheMaxSizePolicy maxSizePolicy)

creatEvictionPolicyEvaluator

protected EvictionPolicyEvaluator<Data,R> creatEvictionPolicyEvaluator(CacheEvictionConfig cacheEvictionConfig)

createEvictionChecker

protected EvictionChecker createEvictionChecker(CacheEvictionConfig cacheEvictionConfig)

creatEvictionStrategy

protected EvictionStrategy<Data,R,CRM> creatEvictionStrategy(CacheEvictionConfig cacheEvictionConfig)

isEvictionRequired

protected boolean isEvictionRequired()

updateHasExpiringEntry

protected void updateHasExpiringEntry(R record)

isEvictionEnabled

public boolean isEvictionEnabled()

evictIfRequired

public int evictIfRequired()
Description copied from interface: ICacheRecordStore
Evict cache record store if eviction is required.

Eviction logic is handled as specified EvictionPolicy in CacheConfig for this record store

Specified by:
evictIfRequired in interface ICacheRecordStore
Returns:
the number of evicted records.

toData

protected Data toData(Object obj)

toValue

protected <T> T toValue(Object obj)

toRecord

protected R toRecord(Object obj)

toEventData

protected Data toEventData(Object obj)

getExpiryPolicy

protected javax.cache.expiry.ExpiryPolicy getExpiryPolicy(javax.cache.expiry.ExpiryPolicy expiryPolicy)

processExpiredEntry

public boolean processExpiredEntry(Data key,
                                   R record,
                                   long now)

processExpiredEntry

public R processExpiredEntry(Data key,
                             R record,
                             long expiryTime,
                             long now)

accessRecord

public R accessRecord(R record,
                      javax.cache.expiry.ExpiryPolicy expiryPolicy,
                      long now)

updateGetAndPutStat

protected void updateGetAndPutStat(boolean isPutSucceed,
                                   boolean getValue,
                                   boolean oldValueNull,
                                   long start)

updateAccessDuration

protected long updateAccessDuration(R record,
                                    javax.cache.expiry.ExpiryPolicy expiryPolicy,
                                    long now)

onRecordAccess

protected long onRecordAccess(R record,
                              javax.cache.expiry.ExpiryPolicy expiryPolicy,
                              long now)

updateReplaceStat

protected void updateReplaceStat(boolean result,
                                 boolean isHit,
                                 long start)

publishEvent

protected void publishEvent(CacheEventType eventType,
                            Data dataKey,
                            Data dataOldValue,
                            Data dataValue,
                            boolean isOldValueAvailable,
                            int completionId)

publishBatchedEvents

protected void publishBatchedEvents(String cacheName,
                                    CacheEventType cacheEventType,
                                    int orderKey)

compare

protected boolean compare(Object v1,
                          Object v2)

expiryPolicyToTTL

protected long expiryPolicyToTTL(javax.cache.expiry.ExpiryPolicy expiryPolicy)

ttlToExpirePolicy

protected javax.cache.expiry.ExpiryPolicy ttlToExpirePolicy(long ttl)

createRecord

protected R createRecord(long expiryTime)

createRecord

protected R createRecord(Object value,
                         long expiryTime)

createRecord

protected R createRecord(Data keyData,
                         Object value,
                         long expirationTime,
                         int completionId)

createRecordWithExpiry

public R createRecordWithExpiry(Data key,
                                Object value,
                                javax.cache.expiry.ExpiryPolicy expiryPolicy,
                                long now,
                                boolean disableWriteThrough,
                                int completionId)

onUpdateRecord

protected void onUpdateRecord(Data key,
                              R record,
                              Object value,
                              Data oldDataValue)

onUpdateRecordError

protected void onUpdateRecordError(Data key,
                                   R record,
                                   Object value,
                                   Data newDataValue,
                                   Data oldDataValue,
                                   Throwable error)

updateRecord

protected R updateRecord(Data key,
                         R record,
                         Object value,
                         int completionId)

updateRecordWithExpiry

public boolean updateRecordWithExpiry(Data key,
                                      Object value,
                                      R record,
                                      javax.cache.expiry.ExpiryPolicy expiryPolicy,
                                      long now,
                                      boolean disableWriteThrough,
                                      int completionId)

onDeleteRecord

protected void onDeleteRecord(Data key,
                              R record,
                              Data dataValue,
                              boolean deleted)

onDeleteRecordError

protected void onDeleteRecordError(Data key,
                                   R record,
                                   Data dataValue,
                                   boolean deleted,
                                   Throwable error)

deleteRecord

protected boolean deleteRecord(Data key,
                               int completionId)

readThroughRecord

public R readThroughRecord(Data key,
                           long now)

readThroughCache

public Object readThroughCache(Data key)
                        throws javax.cache.integration.CacheLoaderException
Throws:
javax.cache.integration.CacheLoaderException

writeThroughCache

public void writeThroughCache(Data key,
                              Object value)
                       throws javax.cache.integration.CacheWriterException
Throws:
javax.cache.integration.CacheWriterException

deleteCacheEntry

protected void deleteCacheEntry(Data key)

deleteAllCacheEntry

protected void deleteAllCacheEntry(Set<Data> keys)

loadAllCacheEntry

protected Map<Data,Object> loadAllCacheEntry(Set<Data> keys)

getRecord

public CacheRecord getRecord(Data key)
Description copied from interface: ICacheRecordStore
Gets internal record of the store by key.

Specified by:
getRecord in interface ICacheRecordStore
Parameters:
key - the key to the entry.
Returns:
CacheRecord instance mapped.

setRecord

public void setRecord(Data key,
                      CacheRecord record)
Description copied from interface: ICacheRecordStore
Associates the specified record with the specified key. This is simply a put operation on the internal map data without any CacheLoad. It also DOES NOT trigger eviction, be aware of the fact it might cause an OutOfMemoryException!

Specified by:
setRecord in interface ICacheRecordStore
Parameters:
key - the key to the entry.
record - the value to be associated with the specified key.

putRecord

public void putRecord(Data key,
                      CacheRecord record)
Description copied from interface: ICacheRecordStore
Associates the specified record with the specified key. This is simply a put operation on the internal map data without any CacheLoad. It also DOES trigger eviction!

Specified by:
putRecord in interface ICacheRecordStore
Parameters:
key - the key to the entry.
record - the value to be associated with the specified key.

removeRecord

public CacheRecord removeRecord(Data key)
Description copied from interface: ICacheRecordStore
Removes the record for a key.

Specified by:
removeRecord in interface ICacheRecordStore
Parameters:
key - the key to the entry.
Returns:
the removed record if one exists.

onGet

protected void onGet(Data key,
                     javax.cache.expiry.ExpiryPolicy expiryPolicy,
                     Object value,
                     R record)

onGetError

protected void onGetError(Data key,
                          javax.cache.expiry.ExpiryPolicy expiryPolicy,
                          Object value,
                          R record,
                          Throwable error)

get

public Object get(Data key,
                  javax.cache.expiry.ExpiryPolicy expiryPolicy)
Description copied from interface: ICacheRecordStore
Gets the value to which the specified key is mapped, or 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.

Specified by:
get in interface ICacheRecordStore
Parameters:
key - the key whose associated value is to be returned.
expiryPolicy - custom expiry policy or null to use configured default value.
Returns:
the element, or null, if it does not exist.

contains

public boolean contains(Data key)
Description copied from interface: ICacheRecordStore
Determines if this store contains an entry for the specified key.

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.)

Specified by:
contains in interface ICacheRecordStore
Parameters:
key - key whose presence in this store is to be tested.
Returns:
true if this map contains a mapping for the specified key.

onPut

protected void onPut(Data key,
                     Object value,
                     javax.cache.expiry.ExpiryPolicy expiryPolicy,
                     String caller,
                     boolean getValue,
                     boolean disableWriteThrough,
                     R record,
                     Object oldValue,
                     boolean isExpired,
                     boolean isNewPut,
                     boolean isSaveSucceed)

onPutError

protected void onPutError(Data key,
                          Object value,
                          javax.cache.expiry.ExpiryPolicy expiryPolicy,
                          String caller,
                          boolean getValue,
                          boolean disableWriteThrough,
                          R record,
                          Object oldValue,
                          boolean wouldBeNewPut,
                          Throwable error)

put

protected Object put(Data key,
                     Object value,
                     javax.cache.expiry.ExpiryPolicy expiryPolicy,
                     String caller,
                     boolean getValue,
                     boolean disableWriteThrough,
                     int completionId)

put

protected Object put(Data key,
                     Object value,
                     javax.cache.expiry.ExpiryPolicy expiryPolicy,
                     String caller,
                     boolean getValue,
                     int completionId)

put

public void put(Data key,
                Object value,
                javax.cache.expiry.ExpiryPolicy expiryPolicy,
                String caller,
                int completionId)
Description copied from interface: ICacheRecordStore
Associates the specified value with the specified key in this cache, returning an existing value if one existed.

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.

Specified by:
put in interface ICacheRecordStore
Parameters:
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.
caller - uuid of the calling node or client.

getAndPut

public Object getAndPut(Data key,
                        Object value,
                        javax.cache.expiry.ExpiryPolicy expiryPolicy,
                        String caller,
                        int completionId)
Description copied from interface: ICacheRecordStore
Associates the specified value with the specified key in this cache, returning an existing value if one existed.

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.

Specified by:
getAndPut in interface ICacheRecordStore
Parameters:
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.
caller - uuid of the calling node or client.
Returns:
the value associated with the key at the start of the operation or null if none was associated.

onPutIfAbsent

protected void onPutIfAbsent(Data key,
                             Object value,
                             javax.cache.expiry.ExpiryPolicy expiryPolicy,
                             String caller,
                             boolean disableWriteThrough,
                             R record,
                             boolean isExpired,
                             boolean isSaveSucceed)

onPutIfAbsentError

protected void onPutIfAbsentError(Data key,
                                  Object value,
                                  javax.cache.expiry.ExpiryPolicy expiryPolicy,
                                  String caller,
                                  boolean disableWriteThrough,
                                  R record,
                                  Throwable error)

putIfAbsent

protected boolean putIfAbsent(Data key,
                              Object value,
                              javax.cache.expiry.ExpiryPolicy expiryPolicy,
                              String caller,
                              boolean disableWriteThrough,
                              int completionId)

putIfAbsent

public boolean putIfAbsent(Data key,
                           Object value,
                           javax.cache.expiry.ExpiryPolicy expiryPolicy,
                           String caller,
                           int completionId)
Description copied from interface: ICacheRecordStore
Removes the mapping for a key from this cache if it is present.

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.

Specified by:
putIfAbsent in interface ICacheRecordStore
Parameters:
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.
caller - uuid of the calling node or client.
Returns:
true if a value was set..

onReplace

protected void onReplace(Data key,
                         Object oldValue,
                         Object newValue,
                         javax.cache.expiry.ExpiryPolicy expiryPolicy,
                         String caller,
                         boolean getValue,
                         R record,
                         boolean isExpired,
                         boolean replaced)

onReplaceError

protected void onReplaceError(Data key,
                              Object oldValue,
                              Object newValue,
                              javax.cache.expiry.ExpiryPolicy expiryPolicy,
                              String caller,
                              boolean getValue,
                              R record,
                              boolean isExpired,
                              boolean replaced,
                              Throwable error)

replace

public boolean replace(Data key,
                       Object value,
                       javax.cache.expiry.ExpiryPolicy expiryPolicy,
                       String caller,
                       int completionId)
Description copied from interface: ICacheRecordStore
Atomically replaces the entry for a key only if currently mapped to some value.

This is equivalent to


 if (cache.containsKey(key)) {
   cache.put(key, value);
   return true;
 } else {
   return false;
 }
except that the action is performed atomically.

Specified by:
replace in interface ICacheRecordStore
Parameters:
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.
caller - uuid of the calling node or client.
Returns:
true if the value was replaced.

replace

public boolean replace(Data key,
                       Object oldValue,
                       Object newValue,
                       javax.cache.expiry.ExpiryPolicy expiryPolicy,
                       String caller,
                       int completionId)
Description copied from interface: ICacheRecordStore
Atomically replaces the entry for a key only if currently mapped to a given value.

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.

Specified by:
replace in interface ICacheRecordStore
Parameters:
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.
caller - uuid of the calling node or client.
Returns:
true if the value was replaced.

getAndReplace

public Object getAndReplace(Data key,
                            Object value,
                            javax.cache.expiry.ExpiryPolicy expiryPolicy,
                            String caller,
                            int completionId)
Description copied from interface: ICacheRecordStore
Atomically replaces the value for a given key if and only if there is a value currently mapped by the key.

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.

Specified by:
getAndReplace in interface ICacheRecordStore
Parameters:
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.
caller - uuid of the calling node or client.
Returns:
the previous value associated with the specified key, or null if there was no mapping for the key.

onRemove

protected void onRemove(Data key,
                        Object value,
                        String caller,
                        boolean getValue,
                        R record,
                        boolean removed)

onRemoveError

protected void onRemoveError(Data key,
                             Object value,
                             String caller,
                             boolean getValue,
                             R record,
                             boolean removed,
                             Throwable error)

remove

public boolean remove(Data key,
                      String caller,
                      int completionId)
Description copied from interface: ICacheRecordStore
Removes the mapping for a key from this cache if it is present.

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.

Specified by:
remove in interface ICacheRecordStore
Parameters:
key - key whose mapping is to be removed from the cache.
caller - uuid of the calling node or client.
Returns:
returns false if there was no matching key.

remove

public boolean remove(Data key,
                      Object value,
                      String caller,
                      int completionId)
Description copied from interface: ICacheRecordStore
Atomically removes the mapping for a key only if currently mapped to the given value.

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.

Specified by:
remove in interface ICacheRecordStore
Parameters:
key - key whose mapping is to be removed from the cache.
value - value expected to be associated with the specified key.
caller - uuid of the calling node or client.
Returns:
returns false if there was no matching key.

getAndRemove

public Object getAndRemove(Data key,
                           String caller,
                           int completionId)
Description copied from interface: ICacheRecordStore
Atomically removes the entry for a key only if it is currently mapped to some value.

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.

Specified by:
getAndRemove in interface ICacheRecordStore
Parameters:
key - key with which the specified value is associated.
caller - uuid of the calling node or client.
Returns:
the value if one existed or null if no mapping existed for this key.

clear

public void clear()
Description copied from interface: ICacheRecordStore
clears all internal data without publishing any events

Specified by:
clear in interface ICacheRecordStore

getAll

public MapEntrySet getAll(Set<Data> keySet,
                          javax.cache.expiry.ExpiryPolicy expiryPolicy)
Description copied from interface: ICacheRecordStore
Gets a collection of entries from the store, returning them as 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.

Specified by:
getAll in interface ICacheRecordStore
Parameters:
keySet - keys whose associated values are to be returned.
expiryPolicy - custom expiry policy or null to use configured default value.
Returns:
A simple wrapper for map of entries that were found for the given keys. Keys not found in the cache are not in the result.

removeAll

public void removeAll(Set<Data> keys,
                      int completionId)
Description copied from interface: ICacheRecordStore
records of keys will be deleted one by one and will publish a REMOVE event for each key.

Specified by:
removeAll in interface ICacheRecordStore
Parameters:
keys - set of keys to be cleaned.

loadAll

public Set<Data> loadAll(Set<Data> keys,
                         boolean replaceExistingValues)
Description copied from interface: ICacheRecordStore
Synchronously loads the specified entries into the cache using the configured 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.

Specified by:
loadAll in interface ICacheRecordStore
Parameters:
keys - the keys to be loaded.
replaceExistingValues - when true, existing values in the cache will be replaced by those loaded from a CacheLoader.
Returns:
Set of keys which are successfully loaded.

iterator

public CacheKeyIteratorResult iterator(int tableIndex,
                                       int size)
Description copied from interface: ICacheRecordStore
Starting from the provided table index, a set of keys are returned with a maximum size of size

Specified by:
iterator in interface ICacheRecordStore
Parameters:
tableIndex - initial table index.
size - maximum key set size.
Returns:
CacheKeyIteratorResult which wraps keys and last tableIndex.

invoke

public Object invoke(Data key,
                     javax.cache.processor.EntryProcessor entryProcessor,
                     Object[] arguments,
                     int completionId)
Description copied from interface: ICacheRecordStore
Invokes an 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.

Specified by:
invoke in interface ICacheRecordStore
Parameters:
key - the key of the entry.
entryProcessor - the EntryProcessor to be invoked.
arguments - additional arguments to be passed to the EntryProcessor.
Returns:
the result of the processing, if any, defined by the EntryProcessor implementation.

size

public int size()
Description copied from interface: ICacheRecordStore
Calculates the entry size of this store which reflects the partition size of the cache.

Specified by:
size in interface ICacheRecordStore
Returns:
partition size of the cache.

getCacheStats

public CacheStatisticsImpl getCacheStats()
Description copied from interface: ICacheRecordStore
Gets the Cache statistics associated with this CacheService.

Specified by:
getCacheStats in interface ICacheRecordStore
Returns:
CacheStatisticsImpl cache statistics.

getConfig

public CacheConfig getConfig()
Description copied from interface: ICacheRecordStore
Gets the configuration of the cache that this store belongs to.

Specified by:
getConfig in interface ICacheRecordStore
Returns:
CacheConfig

getName

public String getName()
Description copied from interface: ICacheRecordStore
Gets the name of the distributed object name of the cache.

Specified by:
getName in interface ICacheRecordStore
Returns:
name.

getReadOnlyRecords

public Map<Data,CacheRecord> getReadOnlyRecords()
Description copied from interface: ICacheRecordStore
Returns a readonly map of the internal key value store.

Specified by:
getReadOnlyRecords in interface ICacheRecordStore
Returns:
readonly map of the internal key value store.

destroy

public void destroy()
Description copied from interface: ICacheRecordStore
Destroy is equivalent to below operations in the given order:

Specified by:
destroy in interface ICacheRecordStore

closeListeners

protected void closeListeners()

closeResources

protected void closeResources()


Copyright © 2015 Hazelcast, Inc.. All Rights Reserved.