Class ReadWriteBackingMap
- All Implemented Interfaces:
CacheMap
,ObservableMap
,Map
- Direct Known Subclasses:
ReadWriteSplittingBackingMap
,VersionedBackingMap
- Author:
- cp 2002.11.25, jh 2005.02.08
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
A wrapper around the original BinaryEntryStore to allow operations to be overridden and extended.static class
A CacheStore wrapped around a CacheLoader.class
A wrapper around the original CacheStore to allow operations to be overridden and extended.class
A queue entry that is scheduled to come out of the front of the queue no earlier than some specific point in time.protected class
A set of entries corresponding to this backing map.static class
A Map implementation used for a backup map that evicts all data that has been successfully written.protected class
A MapListener implementation that listens to the internal cache and routes those events to anyone listening to this ReadWriteBackingMap.protected class
A set of entries backed by this backing map.class
A wrapper around the original NonBlockingEntryStore to allow operations to be overridden and extended.protected static class
A synchronization construct used to coordinate asynchronous loads by the refresh-ahead thread with cache accesses by other threads.class
A queue of keys that should be read from the underlying CacheStore.class
A thread that removes keys from aReadWriteBackingMap.ReadQueue
, reads the value for the key from the underlying CacheStore, and caches the value in the internal ReadWriteBackingMap cache.class
Abstract wrapper around a cache store to allow operations to be overridden and extended.protected class
A collection of values backed by this map.class
A queue that only releases entries after a configurable period of time.class
This is the write-behind thread that pulls things from the write-behind queue and writes them to the CacheStore that the backing map uses.Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,
V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
Modifier and TypeFieldDescriptionprotected static final Binary
The binary form of the decoration indicating that the CacheStore on the primary member has not yet written the value.protected static final float
The recovery threshold to use for guarded execution of write-behind/refresh-ahead threads.protected MapListenerSupport
MapListenerSupport object.static final long
The minimum "retry after requeue" time interval.protected static final Binary
Marker object used byReadWriteBackingMap.Entry
to indicateremove
was called on the Entry.Fields inherited from interface com.tangosol.net.cache.CacheMap
EXPIRY_DEFAULT, EXPIRY_NEVER
-
Constructor Summary
ConstructorDescriptionReadWriteBackingMap
(BackingMapManagerContext ctxService, ObservableMap mapInternal, Map mapMisses, BinaryEntryStore storeBinary, boolean fReadOnly, int cWriteBehindSeconds, double dflRefreshAheadFactor) Construct a ReadWriteBackingMap based on a BinaryEntryStore.ReadWriteBackingMap
(BackingMapManagerContext ctxService, ObservableMap mapInternal, Map mapMisses, CacheLoader loader) Construct a ReadWriteBackingMap based on a CacheLoader (CacheStore).ReadWriteBackingMap
(BackingMapManagerContext ctxService, ObservableMap mapInternal, Map mapMisses, CacheLoader loader, boolean fReadOnly, int cWriteBehindSeconds, double dflRefreshAheadFactor) Construct a ReadWriteBackingMap based on a CacheLoader (CacheStore).ReadWriteBackingMap
(BackingMapManagerContext ctxService, ObservableMap mapInternal, Map mapMisses, NonBlockingEntryStore storeBinary, boolean fReadOnly, int cWriteBehindSeconds, double dflRefreshAheadFactor) Construct a ReadWriteBackingMap based on a NonBlockingEntryStore. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addMapListener
(MapListener listener) Add a standard map listener that will receive all events (inserts, updates, deletes) that occur against the map, with the key, old-value and new-value included.void
addMapListener
(MapListener listener, Filter filter, boolean fLite) Add a map listener that receives events based on a filter evaluation.void
addMapListener
(MapListener listener, Object oKey, boolean fLite) Add a map listener for a specific key.protected void
cancelOutstandingReads
(Object oKey) Cancel any outstanding asynchronous reads for a key.void
clear()
Remove everything from the Map.protected void
configureCacheStore
(ReadWriteBackingMap.StoreWrapper store, boolean fReadOnly) Set up the StoreWrapper that this backing map will use.protected void
configureInternalCache
(ObservableMap mapInternal) Configure the internal cache that this backing map uses to store its "in-memory" data.protected void
configureReadThread
(double dflRefreshAheadFactor) Set up the optional refresh-ahead thread and queue that this backing map will use.protected void
configureWriteThread
(int cWriteBehindSeconds) Set up the optional write-behind thread and queue that this backing map will use.boolean
containsKey
(Object oKey) Returns true if this map contains a mapping for the specified key.boolean
containsValue
(Object oValue) Returns true if this CachingMap maps one or more keys to the specified value.entrySet()
Returns an set view of the mappings contained in this map.boolean
Compares the specified object with this map for equality.protected long
Return the expiration value for the given entry.void
flush()
Flush the write-behind queue, writing everything immediately.protected void
Flush the write-behind queue, writing everything immediately.Returns the value to which this map maps the specified key.getAll
(Collection colKeys) Retrieve values for all the specified keys.protected Object
getCachedOrPending
(Object oKey) Get a value from the internal cache in a way that respects a potentially pending write-behind operation.Return the CacheService.Get the representative of the "persistent" storage for this backing map.long
Return the timeout used for CacheStore operations, or 0 if no timeout is specified.Get the context information provided by the CacheService.Get the concurrency control map for this backing map.protected Object
getFromInternalCache
(Object oKey) Get the the value for a given key.Get the representative of the "in-memory" storage for this backing map.protected ConfigurableCacheMap
Get the map that provides internal storage for this backing map.protected MapListener
Obtain the MapListener that listens to the internal cache and routes those events to anyone listening to this ReadWriteBackingMap, creating such a listener if one does not already exist.Get the optional map used to cache CacheLoader (or CacheStore) misses.int
Return the size of the write-behind queue if configured, or the number of pending writes of the non-blocking store, if configured.Get the queue of keys that are yet to be read.protected ReadWriteBackingMap.ReadThread
Get the refresh-ahead thread.double
Return the refresh-ahead factor.protected Map
Get the map of keys for which the events should be marked as synthetic (internal).double
Return the write-batch factor.long
Return the number of milliseconds between write-behind writes to the CacheStore or 0 if write-behind is not enabled.int
Return the number of seconds between write-behind writes to the CacheStore or 0 if write-behind is not enabled.int
Get the maximum size of the write-behind batch.Get the queue of entries that are yet to be written.int
Return the maximum size of the write-behind queue for which failed CacheStore write operations are requeued or 0 if write-behind requeueing is disabled.protected ReadWriteBackingMap.WriteThread
Get the write-behind thread.int
hashCode()
Returns the hash code value for this map.protected void
Issue a service guardian "heartbeat" for the current thread.protected CacheStore
Factory pattern: Instantiate a CacheLoaderCacheStore wrapper around a passed CacheLoader.protected ReadWriteBackingMap.StoreWrapper
Factory pattern: Instantiate a StoreWrapper wrapper around the passed BinaryEntryStore.protected ReadWriteBackingMap.StoreWrapper
Factory pattern: Instantiate a StoreWrapper wrapper around the passed CacheStore.protected ReadWriteBackingMap.StoreWrapper
Factory pattern: Instantiate a StoreWrapper wrapper around the passed NonBlockingEntryStore.protected ConcurrentMap
Factory pattern: Create the concurrency control map for this backing map.protected ReadWriteBackingMap.Entry
instantiateEntry
(Object oKey, Object oValue, Object oValueOrig) Factory pattern: instantiate a queue entry.protected ReadWriteBackingMap.Entry
instantiateEntry
(Object oKey, Object oValue, Object oValueOrig, long cExpiry) Factory pattern: instantiate a queue entry.protected ReadWriteBackingMap.EntrySet
Factory pattern: instantiate an entry set for this backing map.protected MapListener
Factory pattern: Create a MapListener that listens to the internal cache and routes those events to anyone listening to this ReadWriteBackingMap.protected ReadWriteBackingMap.KeySet
Factory pattern: instantiate a key set for this backing map.protected ReadWriteBackingMap.ReadLatch
instantiateReadLatch
(Object oKey) Factory pattern: Instantiate a new read latch the given key.protected ReadWriteBackingMap.ReadQueue
Factory pattern: Instantiate a new ReadQueue object.protected ReadWriteBackingMap.ReadThread
Factory pattern: Instantiate the refresh-ahead thread.protected ReadWriteBackingMap.ValuesCollection
Factory pattern.protected ReadWriteBackingMap.WriteQueue
Factory pattern: Instantiate a new WriteQueue object.protected ReadWriteBackingMap.WriteThread
Factory pattern: Instantiate the write-behind thread.boolean
isActive()
Determine if the backing map is still active.boolean
Determine if the backing map should send data changes through the CacheStore, or should just keep them in memory.boolean
Determine if the backing map preemptively reads soon-to-be expired entries on a refresh-ahead thread.boolean
Determine if exceptions caught during synchronous CacheStore operations are rethrown to the calling thread; if false, exceptions are logged.boolean
Determine if the backing map writes changes on a write-behind thread through the CacheStore.boolean
Determine if the backing map writes changes immediately through the CacheStore.keySet()
Returns an set view of the keys contained in this map.Associates the specified value with the specified key in this map.Associates the specified value with the specified key in this map.void
Associates the specified values with the respective keys in this map.protected Object
putInternal
(Object oKey, Object oValue, long cMillis) An actual implementation for the extended put() method.protected void
Add the key and value pair to the internal cache in such a way that the resulting map event would be marked as "synthetic".protected void
putToInternalCache
(Object oKey, Object oVal) Add the key and value pair to the internal cache in such a way that the resulting map event would be marked as "synthetic".protected void
putToInternalCache
(Object oKey, Object oVal, long cMillis) Add the key and value pair to the internal cache in such a way that the resulting map event would be marked as "synthetic".protected Object
putToInternalMap
(Object binKey, Object binValue, long cExpiry) Put the specified key in internal format and value in internal format into the internal backing map.void
release()
Release the backing map when it is no longer being used.Removes the mapping for this key from this map if present.protected boolean
removeAll
(Collection colKeys) Remove the collection of keys from this ReadWriteBackingMap.protected ReadWriteBackingMap.Entry
removeFromWriteQueue
(Object binKey) Remove the specified entry from the WriteQueue.protected Object
removeInternal
(Object oKey, boolean fBlind) Implementation of the remove() API.void
removeMapListener
(MapListener listener) Remove a standard map listener that previously signed up for all events.void
removeMapListener
(MapListener listener, Filter filter) Remove a map listener that previously signed up for events based on a filter evaluation.void
removeMapListener
(MapListener listener, Object oKey) Remove a map listener that previously signed up for events about a specific key.void
setCacheName
(String sCacheName) Set the cache name for ReadThread and WriteThread if not already set.void
setCacheStoreTimeoutMillis
(long cStoreTimeoutMillis) Set the timeout used for CacheStore operations.void
setRefreshAheadFactor
(double dflRefreshAheadFactor) Set the refresh-ahead factor, expressed as a percentage of the internal cache expiration interval.void
setRethrowExceptions
(boolean fRethrow) Set the value of the flag that determines if exceptions caught during synchronous CacheStore operations are rethrown to the calling thread; if false, exceptions are logged.void
setWriteBatchFactor
(double dflWriteBatchFactor) Set the write-batch factor, expressed as a percentage of the write-behind interval.void
setWriteBehindMillis
(long cMillis) Set the number of milliseconds between write-behind writes to the CacheStore.void
setWriteBehindSeconds
(int cSecs) Set the number of seconds between write-behind writes to the CacheStore.void
setWriteMaxBatchSize
(int cWriteMaxBatchSize) Set the maximum size of a batch.void
setWriteRequeueThreshold
(int cThreshold) Set the maximum size of the write-behind queue for which failed CacheStore write operations are requeued.int
size()
Returns the number of key-value mappings in this map.protected void
Terminate the refresh-ahead thread.protected void
Terminate the write-behind thread.toString()
For debugging purposes, format the contents of the Map in a human- readable format.protected void
updateThreadName
(Daemon daemon, String sName) Append the provided name to the Daemon's thread name if not already appended.values()
Returns a collection view of the values contained in this map.protected boolean
Wait for notification on the specified object for no longer than the specified wait time.Methods inherited from class java.util.AbstractMap
clone, isEmpty
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
REMOVED
Marker object used byReadWriteBackingMap.Entry
to indicateremove
was called on the Entry. -
BIN_STORE_PENDING
The binary form of the decoration indicating that the CacheStore on the primary member has not yet written the value. -
GUARD_RECOVERY
protected static final float GUARD_RECOVERYThe recovery threshold to use for guarded execution of write-behind/refresh-ahead threads.- See Also:
-
MIN_REQUEUE_DELAY
public static final long MIN_REQUEUE_DELAYThe minimum "retry after requeue" time interval. Default value is 60 sec and can be overridden by the system property:coherence.rwbm.requeue.delay
-
m_listenerSupport
MapListenerSupport object.
-
-
Constructor Details
-
ReadWriteBackingMap
public ReadWriteBackingMap(BackingMapManagerContext ctxService, ObservableMap mapInternal, Map mapMisses, CacheLoader loader) Construct a ReadWriteBackingMap based on a CacheLoader (CacheStore).- Parameters:
ctxService
- the context provided by the CacheService which is using this backing mapmapInternal
- the ObservableMap used to store the data internally in this backing mapmapMisses
- the Map used to cache CacheLoader misses (optional)loader
- the CacheLoader responsible for the persistence of the cached data (optional)
-
ReadWriteBackingMap
public ReadWriteBackingMap(BackingMapManagerContext ctxService, ObservableMap mapInternal, Map mapMisses, CacheLoader loader, boolean fReadOnly, int cWriteBehindSeconds, double dflRefreshAheadFactor) Construct a ReadWriteBackingMap based on a CacheLoader (CacheStore).- Parameters:
ctxService
- the context provided by the CacheService which is using this backing mapmapInternal
- the ObservableMap used to store the data internally in this backing mapmapMisses
- the Map used to cache CacheStore misses (optional)loader
- the CacheLoader responsible for the persistence of the cached data (optional)fReadOnly
- pass true is the specified loader is in fact a CacheStore that needs to be used only for read operations; changes to the cache will not be persistedcWriteBehindSeconds
- number of seconds to write if there is a CacheStore; zero disables write-behind caching, which (combined with !fReadOnly) implies write-throughdflRefreshAheadFactor
- the interval before an entry expiration time (expressed as a percentage of the internal cache expiration interval) during which an asynchronous load request for the entry will be scheduled; zero disables refresh-ahead; only applicable when the mapInternal parameter is an instance ofConfigurableCacheMap
-
ReadWriteBackingMap
public ReadWriteBackingMap(BackingMapManagerContext ctxService, ObservableMap mapInternal, Map mapMisses, BinaryEntryStore storeBinary, boolean fReadOnly, int cWriteBehindSeconds, double dflRefreshAheadFactor) Construct a ReadWriteBackingMap based on a BinaryEntryStore.- Parameters:
ctxService
- the context provided by the CacheService which is using this backing mapmapInternal
- the ObservableMap used to store the data internally in this backing mapmapMisses
- the Map used to cache CacheStore misses (optional)storeBinary
- the BinaryEntryStore responsible for the persistence of the cached data (optional)fReadOnly
- pass true is the specified loader is in fact a CacheStore that needs to be used only for read operations; changes to the cache will not be persistedcWriteBehindSeconds
- number of seconds to write if there is a CacheStore; zero disables write-behind caching, which (combined with !fReadOnly) implies write-throughdflRefreshAheadFactor
- the interval before an entry expiration time (expressed as a percentage of the internal cache expiration interval) during which an asynchronous load request for the entry will be scheduled; zero disables refresh-ahead; only applicable when the mapInternal parameter is an instance ofConfigurableCacheMap
- Since:
- Coherence 3.6
-
ReadWriteBackingMap
public ReadWriteBackingMap(BackingMapManagerContext ctxService, ObservableMap mapInternal, Map mapMisses, NonBlockingEntryStore storeBinary, boolean fReadOnly, int cWriteBehindSeconds, double dflRefreshAheadFactor) Construct a ReadWriteBackingMap based on a NonBlockingEntryStore.- Parameters:
ctxService
- the context provided by the CacheService which is using this backing mapmapInternal
- the ObservableMap used to store the data internally in this backing mapmapMisses
- the Map used to cache CacheStore misses (optional)storeBinary
- the NonBlockingEntryStore responsible for the persistence of the cached data (optional)fReadOnly
- pass true is the specified loader is in fact a CacheStore that needs to be used only for read operations; changes to the cache will not be persistedcWriteBehindSeconds
- number of seconds to write if there is a CacheStore; zero disables write-behind caching, which (combined with !fReadOnly) implies write-throughdflRefreshAheadFactor
- the interval before an entry expiration time (expressed as a percentage of the internal cache expiration interval) during which an asynchronous load request for the entry will be scheduled; zero disables refresh-ahead; only applicable when the mapInternal parameter is an instance ofConfigurableCacheMap
- Since:
- Coherence 21.06
-
-
Method Details
-
getContext
Get the context information provided by the CacheService.- Returns:
- the CacheService's BackingMapManagerContext object that it provided to the BackingMapManager that created this backing map
-
getCacheService
Return the CacheService.- Returns:
- the CacheService
-
isRethrowExceptions
public boolean isRethrowExceptions()Determine if exceptions caught during synchronous CacheStore operations are rethrown to the calling thread; if false, exceptions are logged.- Returns:
- true if CacheStore exceptions are rethrown to the calling thread
-
setRethrowExceptions
public void setRethrowExceptions(boolean fRethrow) Set the value of the flag that determines if exceptions caught during synchronous CacheStore operations are rethrown to the calling thread; if false, exceptions are logged.- Parameters:
fRethrow
- true to indicate that exceptions should be rethrown
-
getRefreshAheadFactor
public double getRefreshAheadFactor()Return the refresh-ahead factor.The refresh-ahead factor is used to calculate the "soft-expiration" time for cache entries. Soft-expiration is the point in time prior to the actual expiration after which any access request for an entry will schedule an asynchronous load request for the entry.
The value of this property is expressed as a percentage of the internal cache expiration interval. If zero, refresh-ahead scheduling is disabled.
- Returns:
- the refresh-ahead factor
-
setRefreshAheadFactor
public void setRefreshAheadFactor(double dflRefreshAheadFactor) Set the refresh-ahead factor, expressed as a percentage of the internal cache expiration interval. Valid values are doubles in the interval [0.0, 1.0].This method has no effect if refresh-ahead is disabled.
- Parameters:
dflRefreshAheadFactor
- the new refresh-ahead factor- See Also:
-
isReadOnly
public boolean isReadOnly()Determine if the backing map should send data changes through the CacheStore, or should just keep them in memory.- Returns:
- false to send changes to CacheStore (a read-write cache), or true to just keep them in memory (a read-only cache)
-
isRefreshAhead
public boolean isRefreshAhead()Determine if the backing map preemptively reads soon-to-be expired entries on a refresh-ahead thread.- Returns:
- true if refresh-ahead is enabled
-
getWriteMaxBatchSize
public int getWriteMaxBatchSize()Get the maximum size of the write-behind batch.- Returns:
- the maximum number of entries in the write-behind batch
-
setWriteMaxBatchSize
public void setWriteMaxBatchSize(int cWriteMaxBatchSize) Set the maximum size of a batch. The size is used to reduce the size of the write-behind batches and the amount of [scratch] memory used to keep de-serialized entries passed to the storeAll operations.This method has no effect if write-behind is disabled.
- Parameters:
cWriteMaxBatchSize
- the maximum batch size
-
getWriteBatchFactor
public double getWriteBatchFactor()Return the write-batch factor.The write-batch factor is used to calculate the "soft-ripe" time for write-behind queue entries. A queue entry is considered to be "ripe" for a write operation if it has been in the write-behind queue for no less than the write-behind interval. The "soft-ripe" time is the point in time prior to the actual ripe time after which an entry will be included in a batched asynchronous write operation to the CacheStore (along with all other ripe and soft-ripe entries). In other words, a soft-ripe entry is an entry that has been in the write-behind queue for at least the following duration:
D' = (1.0 - F)*D
where:D = write-behind delay F = write-batch factor
Conceptually, the write-behind thread uses the following logic when performing a batched update:- The thread waits for a queued entry to become ripe.
- When an entry becomes ripe, the thread dequeues all ripe and soft-ripe entries in the queue.
- The thread then writes all ripe and soft-ripe entries either via
store()
(if there is only the single ripe entry) orstoreAll()
(if there are multiple ripe/soft-ripe entries). - The thread then repeats (1).
This property is only applicable if asynchronous writes are enabled and the CacheStore implements the
storeAll()
method.The value of this property is expressed as a percentage of the
write-behind
interval. Valid values are doubles in the interval [0.0, 1.0].- Returns:
- the write-batch factor
-
setWriteBatchFactor
public void setWriteBatchFactor(double dflWriteBatchFactor) Set the write-batch factor, expressed as a percentage of the write-behind interval. Valid values are doubles in the interval [0.0, 1.0].This method has no effect if write-behind is disabled.
- Parameters:
dflWriteBatchFactor
- the new write-batch factor- See Also:
-
isWriteBehind
public boolean isWriteBehind()Determine if the backing map writes changes on a write-behind thread through the CacheStore.- Returns:
- true implies changes are queued to be written asynchronously
-
getWriteBehindSeconds
public int getWriteBehindSeconds()Return the number of seconds between write-behind writes to the CacheStore or 0 if write-behind is not enabled.- Returns:
- the number of seconds between write-behind writes
-
setWriteBehindSeconds
public void setWriteBehindSeconds(int cSecs) Set the number of seconds between write-behind writes to the CacheStore.This method has not effect if write-behind is not enabled.
- Parameters:
cSecs
- the new write-behind delay in seconds
-
getWriteBehindMillis
public long getWriteBehindMillis()Return the number of milliseconds between write-behind writes to the CacheStore or 0 if write-behind is not enabled.- Returns:
- the number of milliseconds between write-behind writes
- Since:
- Coherence 3.4
-
setWriteBehindMillis
public void setWriteBehindMillis(long cMillis) Set the number of milliseconds between write-behind writes to the CacheStore.This method has not effect if write-behind is not enabled.
- Parameters:
cMillis
- the new write-behind delay in milliseconds- Since:
- Coherence 3.4
-
getWriteRequeueThreshold
public int getWriteRequeueThreshold()Return the maximum size of the write-behind queue for which failed CacheStore write operations are requeued or 0 if write-behind requeueing is disabled.- Returns:
- the write-behind requeue threshold
-
setWriteRequeueThreshold
public void setWriteRequeueThreshold(int cThreshold) Set the maximum size of the write-behind queue for which failed CacheStore write operations are requeued.This method has not effect if write-behind is not enabled.
- Parameters:
cThreshold
- the new write-behind requeue threshold
-
isWriteThrough
public boolean isWriteThrough()Determine if the backing map writes changes immediately through the CacheStore.- Returns:
- true implies that changes to the backing map are written synchronously to the CacheStore
-
getCacheStoreTimeoutMillis
public long getCacheStoreTimeoutMillis()Return the timeout used for CacheStore operations, or 0 if no timeout is specified.- Returns:
- the CacheStore timeout
-
setCacheStoreTimeoutMillis
public void setCacheStoreTimeoutMillis(long cStoreTimeoutMillis) Set the timeout used for CacheStore operations. A value of 0 indicates to use the default guardian timeout of the associated service.- Parameters:
cStoreTimeoutMillis
- the CacheStore timeout, or 0 for the default guardian timeout
-
setCacheName
Set the cache name for ReadThread and WriteThread if not already set.- Parameters:
sCacheName
- the name of the cache
-
getPendingWrites
public int getPendingWrites()Return the size of the write-behind queue if configured, or the number of pending writes of the non-blocking store, if configured. Return -1 if neither.- Returns:
- number of pending writes
-
clear
public void clear()Remove everything from the Map.- Specified by:
clear
in interfaceMap
- Overrides:
clear
in classAbstractMap
-
containsKey
Returns true if this map contains a mapping for the specified key.- Specified by:
containsKey
in interfaceMap
- Overrides:
containsKey
in classAbstractMap
- Parameters:
oKey
- the key to test for- Returns:
- true if this map contains a mapping for the specified key, false otherwise.
-
containsValue
Returns true if this CachingMap maps one or more keys to the specified value.- Specified by:
containsValue
in interfaceMap
- Overrides:
containsValue
in classAbstractMap
- Parameters:
oValue
- the value to test for- Returns:
- true if this CachingMap maps one or more keys to the specified value, false otherwise
-
get
Returns the value to which this map maps the specified key.- Specified by:
get
in interfaceMap
- Overrides:
get
in classAbstractMap
- Parameters:
oKey
- the key object- Returns:
- the value to which this map maps the specified key, or null if the map contains no mapping for this key
-
put
Associates the specified value with the specified key in this map.- Specified by:
put
in interfaceCacheMap
- Specified by:
put
in interfaceMap
- Overrides:
put
in classAbstractMap
- Parameters:
oKey
- key with which the specified value is to be associatedoValue
- value to be associated with the specified key- Returns:
- previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
-
remove
Removes the mapping for this key from this map if present. Expensive: updates both the underlying cache and the local cache.- Specified by:
remove
in interfaceMap
- Overrides:
remove
in classAbstractMap
- Parameters:
oKey
- key whose mapping is to be removed from the map- Returns:
- previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
-
putAll
Associates the specified values with the respective keys in this map. Be aware that the keys will be locked in the order they are returned from iterating over the map passed in and unlocked at the end of the method. This method is called internally within Coherence and the keys will have been locked at the Service level already, so concurrent calls to this method with the same keys will not be an issue. If this method is somehow called directly by application code, which is not recommended, then it is advisable to pass in a sorted map that sorts the keys by their natural ordering.- Specified by:
putAll
in interfaceMap
- Overrides:
putAll
in classAbstractMap
- Parameters:
map
- keys and values which are to be associated in this map
-
putToInternalMap
Put the specified key in internal format and value in internal format into the internal backing map. If the cExpiry parameter is greater than the default expiry value CacheMap.EXPIRY_DEFAULT and the internal map is not an instance ofCacheMap
then an exception will be thrown.- Parameters:
binKey
- the key in internal formatbinValue
- the value in internal format; null if the value should be cached as "missing"cExpiry
- the cache entry expiry value- Returns:
- any previous value tht was mapped to the key.
- Throws:
UnsupportedOperationException
- if the value of cExpiry is greater than CacheMap.EXPIRY_DEFAULT and the internal map is not an instance ofCacheMap
.
-
removeInternal
Implementation of the remove() API.- Parameters:
oKey
- key whose mapping is to be removed from the mapfBlind
- if true, the return value will be ignored- Returns:
- previous value associated with specified key, or null
-
size
public int size()Returns the number of key-value mappings in this map. If the map contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.- Specified by:
size
in interfaceMap
- Overrides:
size
in classAbstractMap
- Returns:
- the number of key-value mappings in this map
-
entrySet
Returns an set view of the mappings contained in this map.- Specified by:
entrySet
in interfaceMap
- Specified by:
entrySet
in classAbstractMap
- Returns:
- a set view of the mappings contained in this map
-
keySet
Returns an set view of the keys contained in this map.- Specified by:
keySet
in interfaceMap
- Overrides:
keySet
in classAbstractMap
- Returns:
- a set view of the keys contained in this map
-
values
Returns a collection view of the values contained in this map.- Specified by:
values
in interfaceMap
- Overrides:
values
in classAbstractMap
- Returns:
- a collection view of the values contained in this map
-
put
Associates the specified value with the specified key in this map.- Specified by:
put
in interfaceCacheMap
- Parameters:
oKey
- key with which the specified value is to be associatedoValue
- value to be associated with the specified keycMillis
- the number of milliseconds until the entry will expire; pass zero to use the cache's default ExpiryDelay settings; pass -1 to indicate that the entry should never expire- Returns:
- previous value associated with specified key, or null if there was no mapping for key
-
getAll
Retrieve values for all the specified keys. -
removeAll
Remove the collection of keys from this ReadWriteBackingMap.This method will ensure the configured CacheStore.eraseAll method is called with all owned keys in addition to removing the relevant entries from the internal Map.
- Parameters:
colKeys
- a collection of keys to remove, that may be in the map- Returns:
- true if any of the provided keys were successfully removed from this map
-
putToInternalCache
Add the key and value pair to the internal cache in such a way that the resulting map event would be marked as "synthetic".- Parameters:
oKey
- the key in internal formatoVal
- the value in internal format; null if the value should be cached as "missing"
-
putToInternalCache
Add the key and value pair to the internal cache in such a way that the resulting map event would be marked as "synthetic".- Parameters:
entry
- cache entry
-
putToInternalCache
Add the key and value pair to the internal cache in such a way that the resulting map event would be marked as "synthetic".- Parameters:
oKey
- the key in internal formatoVal
- the value in internal format; null if the value should be cached as "missing"cMillis
- the cache entry expiry value
-
cancelOutstandingReads
Cancel any outstanding asynchronous reads for a key.- Parameters:
oKey
- the key in internal format
-
getFromInternalCache
Get the the value for a given key. If the entry is present in the internal cache and refresh-ahead is configured, check if a reload operation needs to be scheduled. If the entry is missing, check for a potentially pending refresh-ahead operation and potentially pending write-behind.- Parameters:
oKey
- the key in internal format- Returns:
- the value or null if the value is not found
-
getCachedOrPending
Get a value from the internal cache in a way that respects a potentially pending write-behind operation.- Parameters:
oKey
- the key- Returns:
- the corresponding value
-
putInternal
An actual implementation for the extended put() method.- Parameters:
oKey
- key with which the specified value is to be associatedoValue
- value to be associated with the specified keycMillis
- the number of milliseconds until the entry will expire- Returns:
- previous value associated with specified key, or null if there was no mapping for key.
-
waitFor
Wait for notification on the specified object for no longer than the specified wait time.Note: the caller must hold synchronization on the object being waited on.
- Parameters:
o
- the object to wait for notification oncMillis
- the maximum time in milliseconds to wait; pass 0 for forever- Returns:
- true iff notification was received, the timeout has passed, or the thread was spuriously wakened; false if this thread was interrupted
-
heartbeat
protected void heartbeat()Issue a service guardian "heartbeat" for the current thread. -
extractExpiry
Return the expiration value for the given entry.- Parameters:
entry
- the entry- Returns:
- the expiration value
-
updateThreadName
Append the provided name to the Daemon's thread name if not already appended.- Parameters:
daemon
- the Daemon to be modifiedsName
- the name to append to the Daemon's thread name
-
instantiateEntrySet
Factory pattern: instantiate an entry set for this backing map.- Returns:
- a new EntrySet object
-
instantiateKeySet
Factory pattern: instantiate a key set for this backing map.- Returns:
- a new KeySet object
-
instantiateValuesCollection
Factory pattern.- Returns:
- a new instance of the ValuesCollection class (or subclass thereof)
-
addMapListener
Add a standard map listener that will receive all events (inserts, updates, deletes) that occur against the map, with the key, old-value and new-value included. This has the same result as the following call:addMapListener(listener, (Filter) null, false);
- Specified by:
addMapListener
in interfaceObservableMap
- Parameters:
listener
- theMapEvent
listener to add
-
removeMapListener
Remove a standard map listener that previously signed up for all events. This has the same result as the following call:removeMapListener(listener, (Filter) null);
- Specified by:
removeMapListener
in interfaceObservableMap
- Parameters:
listener
- the listener to remove
-
addMapListener
Add a map listener for a specific key.The listeners will receive MapEvent objects, but if fLite is passed as true, they might not contain the OldValue and NewValue properties.
To unregister the MapListener, use the
ObservableMap.removeMapListener(MapListener, Object)
method.- Specified by:
addMapListener
in interfaceObservableMap
- Parameters:
listener
- theMapEvent
listener to addoKey
- the key that identifies the entry for which to raise eventsfLite
- true to indicate that theMapEvent
objects do not have to include the OldValue and NewValue property values in order to allow optimizations
-
removeMapListener
Remove a map listener that previously signed up for events about a specific key.- Specified by:
removeMapListener
in interfaceObservableMap
- Parameters:
listener
- the listener to removeoKey
- the key that identifies the entry for which to raise events
-
addMapListener
Add a map listener that receives events based on a filter evaluation.The listeners will receive MapEvent objects, but if fLite is passed as true, they might not contain the OldValue and NewValue properties.
To unregister the MapListener, use the
ObservableMap.removeMapListener(MapListener, Filter)
method.- Specified by:
addMapListener
in interfaceObservableMap
- Parameters:
listener
- theMapEvent
listener to addfilter
- a filter that will be passed MapEvent objects to select from; a MapEvent will be delivered to the listener only if the filter evaluates to true for that MapEvent (seeMapEventFilter
); null is equivalent to a filter that alway returns truefLite
- true to indicate that theMapEvent
objects do not have to include the OldValue and NewValue property values in order to allow optimizations
-
removeMapListener
Remove a map listener that previously signed up for events based on a filter evaluation.- Specified by:
removeMapListener
in interfaceObservableMap
- Parameters:
listener
- the listener to removefilter
- the filter that was passed into the corresponding addMapListener() call
-
equals
Compares the specified object with this map for equality. Returns true if the given object is also a map and the two maps represent the same mappings.- Specified by:
equals
in interfaceMap
- Overrides:
equals
in classAbstractMap
- Parameters:
o
- object to be compared for equality with this map- Returns:
- true if the specified object is equal to this map
-
hashCode
public int hashCode()Returns the hash code value for this map.- Specified by:
hashCode
in interfaceMap
- Overrides:
hashCode
in classAbstractMap
- Returns:
- the hash code value for this map
-
toString
For debugging purposes, format the contents of the Map in a human- readable format.- Overrides:
toString
in classAbstractMap
- Returns:
- a String representation of this ReadWriteBackingMap
-
getInternalCache
Get the representative of the "in-memory" storage for this backing map.- Returns:
- the ObservableMap object (never null) that this backing map uses to store entries
-
getInternalConfigurableCache
Get the map that provides internal storage for this backing map. If the internal storage is a ConfigurableCacheMap, then this accessor returns the same reference asgetInternalCache()
; otherwise it returns null. The refresh-ahead implementation relies on the internal storage providing the ConfigurableCacheMap interface, so this method will always return a non-null value if refresh-ahead is enabled.- Returns:
- the cache for this backing map or null if the internal map is not an implementation of the ConfigurableCacheMap interface
-
configureInternalCache
Configure the internal cache that this backing map uses to store its "in-memory" data.- Parameters:
mapInternal
- the internal map
-
getMissesCache
Get the optional map used to cache CacheLoader (or CacheStore) misses.- Returns:
- the Map that this backing map uses to cache CacheLoader (or CacheStore) misses or null if misses are not cached
-
getControlMap
Get the concurrency control map for this backing map.- Returns:
- the ObservableMap object (never null) that this backing map uses to store entries
-
instantiateControlMap
Factory pattern: Create the concurrency control map for this backing map.- Returns:
- a new concurrency control map
-
getSyntheticEventsMap
Get the map of keys for which the events should be marked as synthetic (internal).- Returns:
- the map of keys to mark events as internal
-
getInternalListener
Obtain the MapListener that listens to the internal cache and routes those events to anyone listening to this ReadWriteBackingMap, creating such a listener if one does not already exist.- Returns:
- a routing MapListener
-
instantiateInternalListener
Factory pattern: Create a MapListener that listens to the internal cache and routes those events to anyone listening to this ReadWriteBackingMap.- Returns:
- a new routing MapListener
-
release
public void release()Release the backing map when it is no longer being used. -
isActive
public boolean isActive()Determine if the backing map is still active.- Returns:
- true if the backing map is still active
-
instantiateReadLatch
Factory pattern: Instantiate a new read latch the given key.- Parameters:
oKey
- the key- Returns:
- the read latch
-
getReadQueue
Get the queue of keys that are yet to be read.- Returns:
- the refresh-ahead queue object
-
instantiateReadQueue
Factory pattern: Instantiate a new ReadQueue object.- Returns:
- a new ReadQueue object
-
getWriteQueue
Get the queue of entries that are yet to be written.- Returns:
- the write-behind queue object
-
flush
public void flush()Flush the write-behind queue, writing everything immediately. -
flush
Flush the write-behind queue, writing everything immediately.- Parameters:
queue
- the write-behind queue to flushstore
- the CacheStore to flush to
-
removeFromWriteQueue
Remove the specified entry from the WriteQueue.- Parameters:
binKey
- the key- Returns:
- the currently queued entry (could be NO_VALUE marker or null)
-
instantiateEntry
Factory pattern: instantiate a queue entry.- Parameters:
oKey
- the key for the new entryoValue
- the entry's value; could be null representing a non-existing or removed entryoValueOrig
- the entry's original value; could be null representing a non-existing entry- Returns:
- a new Entry
-
instantiateEntry
protected ReadWriteBackingMap.Entry instantiateEntry(Object oKey, Object oValue, Object oValueOrig, long cExpiry) Factory pattern: instantiate a queue entry.- Parameters:
oKey
- the key for the new entryoValue
- the entry's value; could be null representing a non-existing or removed entryoValueOrig
- the entry's original value; could be null representing a non-existing entrycExpiry
- the expiry delay, orCacheMap.EXPIRY_NEVER
orCacheMap.EXPIRY_DEFAULT
- Returns:
- a new Entry
-
instantiateWriteQueue
Factory pattern: Instantiate a new WriteQueue object.- Returns:
- a new WriteQueue object
-
getReadThread
Get the refresh-ahead thread.- Returns:
- the refresh-ahead thread or null if refresh-ahead is not enabled
-
configureReadThread
protected void configureReadThread(double dflRefreshAheadFactor) Set up the optional refresh-ahead thread and queue that this backing map will use.This method has no effect if the given refresh-ahead factor is zero or the cache returned by
getInternalConfigurableCache()
is null or non-expiring.- Parameters:
dflRefreshAheadFactor
- the refresh-ahead factor expressed as a percentage of the internal cache expiry
-
instantiateReadThread
Factory pattern: Instantiate the refresh-ahead thread.- Returns:
- a new refresh-ahead thread
-
terminateReadThread
protected void terminateReadThread()Terminate the refresh-ahead thread. -
getWriteThread
Get the write-behind thread.- Returns:
- the write-behind thread or null if there is no CacheStore to write to
-
configureWriteThread
protected void configureWriteThread(int cWriteBehindSeconds) Set up the optional write-behind thread and queue that this backing map will use.This method has no effect if the given write-behind delay is zero or
isReadOnly()
returns true.- Parameters:
cWriteBehindSeconds
- write-behind delay
-
instantiateWriteThread
Factory pattern: Instantiate the write-behind thread.- Returns:
- a new write-behind thread
-
terminateWriteThread
protected void terminateWriteThread()Terminate the write-behind thread. -
getCacheStore
Get the representative of the "persistent" storage for this backing map.- Returns:
- the cache store wrapper object that this backing map uses for persistence or null if there is no persistent store behind this backing map
-
configureCacheStore
Set up the StoreWrapper that this backing map will use.- Parameters:
store
- the StoreWrapper that this backing map will delegate persistence responsibilities tofReadOnly
- pass true to prevent the usage of the cache store write operations
-
instantiateCacheStoreWrapper
Factory pattern: Instantiate a StoreWrapper wrapper around the passed CacheStore. (Supports CacheStore extension by delegation pattern.)- Parameters:
store
- the CacheStore to wrap- Returns:
- the StoreWrapper wrapper that can supplement and override the operations of the supplied CacheStore
-
instantiateCacheStoreWrapper
Factory pattern: Instantiate a StoreWrapper wrapper around the passed BinaryEntryStore. (Supports BinaryEntryStore extension by delegation pattern.)- Parameters:
store
- the BinaryEntryStore to wrap- Returns:
- the StoreWrapper wrapper that can supplement and override the operations of the supplied BinaryEntryStore
-
instantiateCacheStoreWrapper
protected ReadWriteBackingMap.StoreWrapper instantiateCacheStoreWrapper(NonBlockingEntryStore store) Factory pattern: Instantiate a StoreWrapper wrapper around the passed NonBlockingEntryStore. (Supports NonBlockingEntryStore extension by delegation pattern.)- Parameters:
store
- the NonBlockingEntryStore to wrap- Returns:
- the StoreWrapper wrapper that can supplement and override the operations of the supplied BinaryEntryStore
-
instantiateCacheLoaderCacheStore
Factory pattern: Instantiate a CacheLoaderCacheStore wrapper around a passed CacheLoader.- Parameters:
loader
- the CacheLoader to wrap; never null- Returns:
- a CacheStore instance
-