com.hazelcast.cache.impl
Interface ICacheRecordStore

All Known Implementing Classes:
AbstractCacheRecordStore, CacheRecordStore

public interface ICacheRecordStore

ICacheRecordStore is the core contract providing internal functionality to ICache implementations on partition scope. All of the ICache methods actually map to a method on this interface through Hazelcast's RPC mechanism. Hazelcast Operation is sent to the relevant partition to be executed and the final results are returned to the callers. For each partition, there is only one ICacheRecordStore in the cluster.

Implementations of this interface may provide different internal data persistence like on-heap storage.

Each expirible cache entry is actually a Data, CacheRecord pair.

Key type: always serialized form of Data.

Value types: depend on the configuration.

See Also:
CacheRecordStore

Field Summary
static int ONE_HUNDRED_PERCENT
           
 
Method Summary
 void clear()
          clears all internal data without publishing any events
 boolean contains(Data key)
          Determines if this store contains an entry for the specified key.
 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.
 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.
 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.
 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.
 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.
 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.
 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.
 

Field Detail

ONE_HUNDRED_PERCENT

static final int ONE_HUNDRED_PERCENT
See Also:
Constant Field Values
Method Detail

get

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.

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.

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.

put

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.

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.

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

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.

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.

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.

putIfAbsent

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.

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.

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

getAndRemove

Object getAndRemove(Data key,
                    String caller,
                    int completionId)
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.

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.

remove

boolean remove(Data key,
               String caller,
               int completionId)
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.

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

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.

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.

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.

replace

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.

This is equivalent to


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

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

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.

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.

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

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.

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.

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.

contains

boolean contains(Data key)
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.)

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

getAll

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.

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.

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.

size

int size()
Calculates the entry size of this store which reflects the partition size of the cache.

Returns:
partition size of the cache.

clear

void clear()
clears all internal data without publishing any events


removeAll

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.

Parameters:
keys - set of keys to be cleaned.

destroy

void destroy()
Destroy is equivalent to below operations in the given order:


getConfig

CacheConfig getConfig()
Gets the configuration of the cache that this store belongs to.

Returns:
CacheConfig

getName

String getName()
Gets the name of the distributed object name of the cache.

Returns:
name.

getReadOnlyRecords

Map<Data,CacheRecord> getReadOnlyRecords()
Returns a readonly map of the internal key value store.

Returns:
readonly map of the internal key value store.

getRecord

CacheRecord getRecord(Data key)
Gets internal record of the store by key.

Parameters:
key - the key to the entry.
Returns:
CacheRecord instance mapped.

setRecord

void setRecord(Data key,
               CacheRecord record)
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!

Parameters:
key - the key to the entry.
record - the value to be associated with the specified key.

putRecord

void putRecord(Data key,
               CacheRecord record)
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!

Parameters:
key - the key to the entry.
record - the value to be associated with the specified key.

removeRecord

CacheRecord removeRecord(Data key)
Removes the record for a key.

Parameters:
key - the key to the entry.
Returns:
the removed record if one exists.

iterator

CacheKeyIteratorResult iterator(int tableIndex,
                                int size)
Starting from the provided table index, a set of keys are returned with a maximum size of size

Parameters:
tableIndex - initial table index.
size - maximum key set size.
Returns:
CacheKeyIteratorResult which wraps keys and last tableIndex.

invoke

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

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.

loadAll

Set<Data> loadAll(Set<Data> keys,
                  boolean replaceExistingValues)
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.

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.

getCacheStats

CacheStatisticsImpl getCacheStats()
Gets the Cache statistics associated with this CacheService.

Returns:
CacheStatisticsImpl cache statistics.

evictIfRequired

int evictIfRequired()
Evict cache record store if eviction is required.

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

Returns:
the number of evicted records.


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