public class DefaultNearCache<K,V> extends Object implements NearCache<K,V>
Modifier and Type | Field and Description |
---|---|
protected ClassLoader |
classLoader |
protected ScheduledFuture |
expirationTaskFuture |
protected String |
name |
protected NearCacheConfig |
nearCacheConfig |
protected NearCacheRecordStore<K,V> |
nearCacheRecordStore |
protected TaskScheduler |
scheduler |
protected SerializationService |
serializationService |
CACHED_AS_NULL, DEFAULT_EXPIRATION_TASK_DELAY_IN_SECONDS, DEFAULT_EXPIRATION_TASK_INITIAL_DELAY_IN_SECONDS, NOT_CACHED
Constructor and Description |
---|
DefaultNearCache(String name,
NearCacheConfig nearCacheConfig,
NearCacheRecordStore<K,V> nearCacheRecordStore,
SerializationService serializationService,
TaskScheduler scheduler,
ClassLoader classLoader) |
DefaultNearCache(String name,
NearCacheConfig nearCacheConfig,
SerializationService serializationService,
TaskScheduler scheduler,
ClassLoader classLoader) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all stored values.
|
protected NearCacheRecordStore<K,V> |
createNearCacheRecordStore(String name,
NearCacheConfig nearCacheConfig) |
void |
destroy()
Clears the record store and destroys it.
|
V |
get(K key)
Gets the value associated with the given
key . |
InMemoryFormat |
getInMemoryFormat()
Gets the
InMemoryFormat of the storage for internal records. |
String |
getName()
Gets the name of this
NearCache instance. |
NearCacheRecordStore<K,V> |
getNearCacheRecordStore() |
NearCacheStats |
getNearCacheStats()
Get the
NearCacheStats instance to monitor this store. |
NearCachePreloaderConfig |
getPreloaderConfig()
Gets the
NearCachePreloaderConfig of this Near Cache. |
void |
initialize() |
boolean |
isPreloadDone()
Checks if the pre-loading of the Near Cache is done.
|
boolean |
isSerializeKeys()
Checks if the Near Cache key is stored in serialized format or by-reference.
|
void |
preload(DataStructureAdapter<Object,?> adapter)
Executes the Near Cache pre-loader on the given
DataStructureAdapter . |
void |
put(K key,
Data keyData,
V value)
Puts (associates) a value with the given
key . |
boolean |
remove(K key)
Removes the value associated with the given
key . |
Object |
selectToSave(Object... candidates)
Selects the best candidate object to store from the given
candidates . |
int |
size()
Gets the count of stored records.
|
void |
storeKeys()
Stores the keys of the Near Cache.
|
V |
tryPublishReserved(K key,
V value,
long reservationId,
boolean deserialize)
Tries to update reserved key with supplied value.
|
long |
tryReserveForUpdate(K key,
Data keyData)
Tries to reserve supplied key for update.
|
<T> T |
unwrap(Class<T> clazz)
Used to access non-standard methods of an implementation.
|
protected final String name
protected final NearCacheConfig nearCacheConfig
protected final SerializationService serializationService
protected final TaskScheduler scheduler
protected final ClassLoader classLoader
protected NearCacheRecordStore<K,V> nearCacheRecordStore
protected ScheduledFuture expirationTaskFuture
public DefaultNearCache(String name, NearCacheConfig nearCacheConfig, SerializationService serializationService, TaskScheduler scheduler, ClassLoader classLoader)
public DefaultNearCache(String name, NearCacheConfig nearCacheConfig, NearCacheRecordStore<K,V> nearCacheRecordStore, SerializationService serializationService, TaskScheduler scheduler, ClassLoader classLoader)
public void initialize()
initialize
in interface InitializingObject
protected NearCacheRecordStore<K,V> createNearCacheRecordStore(String name, NearCacheConfig nearCacheConfig)
public String getName()
NearCache
NearCache
instance.public V get(K key)
NearCache
key
.public void put(K key, Data keyData, V value)
NearCache
key
.public boolean remove(K key)
NearCache
key
.public void clear()
NearCache
public void destroy()
NearCache
public InMemoryFormat getInMemoryFormat()
NearCache
InMemoryFormat
of the storage for internal records.getInMemoryFormat
in interface NearCache<K,V>
InMemoryFormat
of the storage for internal recordspublic NearCachePreloaderConfig getPreloaderConfig()
NearCache
NearCachePreloaderConfig
of this Near Cache.getPreloaderConfig
in interface NearCache<K,V>
NearCachePreloaderConfig
of this Near Cachepublic NearCacheStats getNearCacheStats()
NearCache
NearCacheStats
instance to monitor this store.getNearCacheStats
in interface NearCache<K,V>
NearCacheStats
instance to monitor this storepublic boolean isSerializeKeys()
NearCache
isSerializeKeys
in interface NearCache<K,V>
true
if the key is stored in serialized format, false
if stored by-reference.public Object selectToSave(Object... candidates)
NearCache
candidates
.selectToSave
in interface NearCache<K,V>
candidates
- the candidates from which the best candidate object will be selected.candidates
.public int size()
NearCache
public void preload(DataStructureAdapter<Object,?> adapter)
NearCache
DataStructureAdapter
.public void storeKeys()
NearCache
public boolean isPreloadDone()
NearCache
isPreloadDone
in interface NearCache<K,V>
true
if the pre-loading is done, false
otherwise.public <T> T unwrap(Class<T> clazz)
NearCache
If this method is called on a wrapper object, result is wrapped object.
public long tryReserveForUpdate(K key, Data keyData)
NearCache
If one thread takes reservation, only that thread can update the key.
tryReserveForUpdate
in interface NearCache<K,V>
key
- key to be reserved for updatekeyData
- key to be reserved for update as Data
NearCacheRecord.NOT_RESERVED
public V tryPublishReserved(K key, V value, long reservationId, boolean deserialize)
NearCache
tryPublishReserved
in interface NearCache<K,V>
key
- reserved key for updatevalue
- value to be associated with reserved keyreservationId
- ID for this reservationdeserialize
- eagerly deserialize returning valuetrue
and update succeeds, otherwise returns nullpublic NearCacheRecordStore<K,V> getNearCacheRecordStore()
Copyright © 2018 Hazelcast, Inc.. All Rights Reserved.