Class ReadWriteBackingMap

java.lang.Object
java.util.AbstractMap
com.tangosol.net.cache.ReadWriteBackingMap
All Implemented Interfaces:
CacheMap, ObservableMap, Map
Direct Known Subclasses:
ReadWriteSplittingBackingMap, VersionedBackingMap

public class ReadWriteBackingMap extends AbstractMap implements CacheMap
Backing Map implementation that provides a size-limited cache of a persistent store and supports configurable write-behind and refresh- ahead caching. This implementation is not intended to support null keys or null values.
Author:
cp 2002.11.25, jh 2005.02.08
  • Field Details

    • REMOVED

      protected static final Binary REMOVED
      Marker object used by ReadWriteBackingMap.Entry to indicate remove was called on the Entry.
    • BIN_STORE_PENDING

      protected static final Binary 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_RECOVERY
      The recovery threshold to use for guarded execution of write-behind/refresh-ahead threads.
      See Also:
    • MIN_REQUEUE_DELAY

      public static final long MIN_REQUEUE_DELAY
      The 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

      protected MapListenerSupport 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 map
      mapInternal - the ObservableMap used to store the data internally in this backing map
      mapMisses - 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 map
      mapInternal - the ObservableMap used to store the data internally in this backing map
      mapMisses - 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 persisted
      cWriteBehindSeconds - number of seconds to write if there is a CacheStore; zero disables write-behind caching, which (combined with !fReadOnly) implies write-through
      dflRefreshAheadFactor - 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 of ConfigurableCacheMap
    • 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 map
      mapInternal - the ObservableMap used to store the data internally in this backing map
      mapMisses - 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 persisted
      cWriteBehindSeconds - number of seconds to write if there is a CacheStore; zero disables write-behind caching, which (combined with !fReadOnly) implies write-through
      dflRefreshAheadFactor - 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 of ConfigurableCacheMap
      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 map
      mapInternal - the ObservableMap used to store the data internally in this backing map
      mapMisses - 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 persisted
      cWriteBehindSeconds - number of seconds to write if there is a CacheStore; zero disables write-behind caching, which (combined with !fReadOnly) implies write-through
      dflRefreshAheadFactor - 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 of ConfigurableCacheMap
      Since:
      Coherence 21.06
  • Method Details

    • getContext

      public BackingMapManagerContext 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

      public CacheService 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:
      1. The thread waits for a queued entry to become ripe.
      2. When an entry becomes ripe, the thread dequeues all ripe and soft-ripe entries in the queue.
      3. The thread then writes all ripe and soft-ripe entries either via store() (if there is only the single ripe entry) or storeAll() (if there are multiple ripe/soft-ripe entries).
      4. 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

      public void setCacheName(String sCacheName)
      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 interface Map
      Overrides:
      clear in class AbstractMap
    • containsKey

      public boolean containsKey(Object oKey)
      Returns true if this map contains a mapping for the specified key.
      Specified by:
      containsKey in interface Map
      Overrides:
      containsKey in class AbstractMap
      Parameters:
      oKey - the key to test for
      Returns:
      true if this map contains a mapping for the specified key, false otherwise.
    • containsValue

      public boolean containsValue(Object oValue)
      Returns true if this CachingMap maps one or more keys to the specified value.
      Specified by:
      containsValue in interface Map
      Overrides:
      containsValue in class AbstractMap
      Parameters:
      oValue - the value to test for
      Returns:
      true if this CachingMap maps one or more keys to the specified value, false otherwise
    • get

      public Object get(Object oKey)
      Returns the value to which this map maps the specified key.
      Specified by:
      get in interface Map
      Overrides:
      get in class AbstractMap
      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

      public Object put(Object oKey, Object oValue)
      Associates the specified value with the specified key in this map.
      Specified by:
      put in interface CacheMap
      Specified by:
      put in interface Map
      Overrides:
      put in class AbstractMap
      Parameters:
      oKey - key with which the specified value is to be associated
      oValue - 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

      public Object remove(Object oKey)
      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 interface Map
      Overrides:
      remove in class AbstractMap
      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

      public void putAll(Map map)
      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 interface Map
      Overrides:
      putAll in class AbstractMap
      Parameters:
      map - keys and values which are to be associated in this map
    • putToInternalMap

      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. If the cExpiry parameter is greater than the default expiry value CacheMap.EXPIRY_DEFAULT and the internal map is not an instance of CacheMap then an exception will be thrown.
      Parameters:
      binKey - the key in internal format
      binValue - 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 of CacheMap.
    • removeInternal

      protected Object removeInternal(Object oKey, boolean fBlind)
      Implementation of the remove() API.
      Parameters:
      oKey - key whose mapping is to be removed from the map
      fBlind - 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 interface Map
      Overrides:
      size in class AbstractMap
      Returns:
      the number of key-value mappings in this map
    • entrySet

      public Set entrySet()
      Returns an set view of the mappings contained in this map.
      Specified by:
      entrySet in interface Map
      Specified by:
      entrySet in class AbstractMap
      Returns:
      a set view of the mappings contained in this map
    • keySet

      public Set keySet()
      Returns an set view of the keys contained in this map.
      Specified by:
      keySet in interface Map
      Overrides:
      keySet in class AbstractMap
      Returns:
      a set view of the keys contained in this map
    • values

      public Collection values()
      Returns a collection view of the values contained in this map.
      Specified by:
      values in interface Map
      Overrides:
      values in class AbstractMap
      Returns:
      a collection view of the values contained in this map
    • put

      public Object put(Object oKey, Object oValue, long cMillis)
      Associates the specified value with the specified key in this map.
      Specified by:
      put in interface CacheMap
      Parameters:
      oKey - key with which the specified value is to be associated
      oValue - value to be associated with the specified key
      cMillis - 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

      public Map getAll(Collection colKeys)
      Retrieve values for all the specified keys.
      Specified by:
      getAll in interface CacheMap
      Parameters:
      colKeys - a collection of keys that may be in the named cache
      Returns:
      a Map of keys to values for the specified keys passed in colKeys
    • removeAll

      protected boolean removeAll(Collection colKeys)
      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

      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".
      Parameters:
      oKey - the key in internal format
      oVal - the value in internal format; null if the value should be cached as "missing"
    • putToInternalCache

      protected void putToInternalCache(ReadWriteBackingMap.Entry entry)
      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

      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".
      Parameters:
      oKey - the key in internal format
      oVal - the value in internal format; null if the value should be cached as "missing"
      cMillis - the cache entry expiry value
    • cancelOutstandingReads

      protected void cancelOutstandingReads(Object oKey)
      Cancel any outstanding asynchronous reads for a key.
      Parameters:
      oKey - the key in internal format
    • getFromInternalCache

      protected Object getFromInternalCache(Object oKey)
      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

      protected Object getCachedOrPending(Object oKey)
      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

      protected Object putInternal(Object oKey, Object oValue, long cMillis)
      An actual implementation for the extended put() method.
      Parameters:
      oKey - key with which the specified value is to be associated
      oValue - value to be associated with the specified key
      cMillis - 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

      protected boolean waitFor(Object o, long cMillis)
      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 on
      cMillis - 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

      protected long extractExpiry(ReadWriteBackingMap.Entry entry)
      Return the expiration value for the given entry.
      Parameters:
      entry - the entry
      Returns:
      the expiration value
    • updateThreadName

      protected void updateThreadName(Daemon daemon, String sName)
      Append the provided name to the Daemon's thread name if not already appended.
      Parameters:
      daemon - the Daemon to be modified
      sName - the name to append to the Daemon's thread name
    • instantiateEntrySet

      protected ReadWriteBackingMap.EntrySet instantiateEntrySet()
      Factory pattern: instantiate an entry set for this backing map.
      Returns:
      a new EntrySet object
    • instantiateKeySet

      protected ReadWriteBackingMap.KeySet instantiateKeySet()
      Factory pattern: instantiate a key set for this backing map.
      Returns:
      a new KeySet object
    • instantiateValuesCollection

      protected ReadWriteBackingMap.ValuesCollection instantiateValuesCollection()
      Factory pattern.
      Returns:
      a new instance of the ValuesCollection class (or subclass thereof)
    • addMapListener

      public void 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. This has the same result as the following call:
         addMapListener(listener, (Filter) null, false);
       
      Specified by:
      addMapListener in interface ObservableMap
      Parameters:
      listener - the MapEvent listener to add
    • removeMapListener

      public void removeMapListener(MapListener listener)
      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 interface ObservableMap
      Parameters:
      listener - the listener to remove
    • addMapListener

      public void addMapListener(MapListener listener, Object oKey, boolean fLite)
      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 interface ObservableMap
      Parameters:
      listener - the MapEvent listener to add
      oKey - the key that identifies the entry for which to raise events
      fLite - true to indicate that the MapEvent objects do not have to include the OldValue and NewValue property values in order to allow optimizations
    • removeMapListener

      public void removeMapListener(MapListener listener, Object oKey)
      Remove a map listener that previously signed up for events about a specific key.
      Specified by:
      removeMapListener in interface ObservableMap
      Parameters:
      listener - the listener to remove
      oKey - the key that identifies the entry for which to raise events
    • addMapListener

      public void addMapListener(MapListener listener, Filter filter, boolean fLite)
      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 interface ObservableMap
      Parameters:
      listener - the MapEvent listener to add
      filter - 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 (see MapEventFilter); null is equivalent to a filter that alway returns true
      fLite - true to indicate that the MapEvent objects do not have to include the OldValue and NewValue property values in order to allow optimizations
    • removeMapListener

      public void removeMapListener(MapListener listener, Filter filter)
      Remove a map listener that previously signed up for events based on a filter evaluation.
      Specified by:
      removeMapListener in interface ObservableMap
      Parameters:
      listener - the listener to remove
      filter - the filter that was passed into the corresponding addMapListener() call
    • equals

      public boolean equals(Object o)
      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 interface Map
      Overrides:
      equals in class AbstractMap
      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 interface Map
      Overrides:
      hashCode in class AbstractMap
      Returns:
      the hash code value for this map
    • toString

      public String toString()
      For debugging purposes, format the contents of the Map in a human- readable format.
      Overrides:
      toString in class AbstractMap
      Returns:
      a String representation of this ReadWriteBackingMap
    • getInternalCache

      public ObservableMap 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

      protected ConfigurableCacheMap 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 as getInternalCache(); 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

      protected void configureInternalCache(ObservableMap mapInternal)
      Configure the internal cache that this backing map uses to store its "in-memory" data.
      Parameters:
      mapInternal - the internal map
    • getMissesCache

      public 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

      public ConcurrentMap 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

      protected ConcurrentMap instantiateControlMap()
      Factory pattern: Create the concurrency control map for this backing map.
      Returns:
      a new concurrency control map
    • getSyntheticEventsMap

      protected 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

      protected MapListener 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

      protected 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

      protected ReadWriteBackingMap.ReadLatch instantiateReadLatch(Object oKey)
      Factory pattern: Instantiate a new read latch the given key.
      Parameters:
      oKey - the key
      Returns:
      the read latch
    • getReadQueue

      public ReadWriteBackingMap.ReadQueue getReadQueue()
      Get the queue of keys that are yet to be read.
      Returns:
      the refresh-ahead queue object
    • instantiateReadQueue

      protected ReadWriteBackingMap.ReadQueue instantiateReadQueue()
      Factory pattern: Instantiate a new ReadQueue object.
      Returns:
      a new ReadQueue object
    • getWriteQueue

      public ReadWriteBackingMap.WriteQueue 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 flush
      store - the CacheStore to flush to
    • removeFromWriteQueue

      protected ReadWriteBackingMap.Entry removeFromWriteQueue(Object binKey)
      Remove the specified entry from the WriteQueue.
      Parameters:
      binKey - the key
      Returns:
      the currently queued entry (could be NO_VALUE marker or null)
    • instantiateEntry

      protected ReadWriteBackingMap.Entry instantiateEntry(Object oKey, Object oValue, Object oValueOrig)
      Factory pattern: instantiate a queue entry.
      Parameters:
      oKey - the key for the new entry
      oValue - the entry's value; could be null representing a non-existing or removed entry
      oValueOrig - 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 entry
      oValue - the entry's value; could be null representing a non-existing or removed entry
      oValueOrig - the entry's original value; could be null representing a non-existing entry
      cExpiry - the expiry delay, or CacheMap.EXPIRY_NEVER or CacheMap.EXPIRY_DEFAULT
      Returns:
      a new Entry
    • instantiateWriteQueue

      protected ReadWriteBackingMap.WriteQueue instantiateWriteQueue()
      Factory pattern: Instantiate a new WriteQueue object.
      Returns:
      a new WriteQueue object
    • getReadThread

      protected ReadWriteBackingMap.ReadThread 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

      protected ReadWriteBackingMap.ReadThread instantiateReadThread()
      Factory pattern: Instantiate the refresh-ahead thread.
      Returns:
      a new refresh-ahead thread
    • terminateReadThread

      protected void terminateReadThread()
      Terminate the refresh-ahead thread.
    • getWriteThread

      protected ReadWriteBackingMap.WriteThread 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

      protected ReadWriteBackingMap.WriteThread instantiateWriteThread()
      Factory pattern: Instantiate the write-behind thread.
      Returns:
      a new write-behind thread
    • terminateWriteThread

      protected void terminateWriteThread()
      Terminate the write-behind thread.
    • getCacheStore

      public ReadWriteBackingMap.StoreWrapper 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

      protected void configureCacheStore(ReadWriteBackingMap.StoreWrapper store, boolean fReadOnly)
      Set up the StoreWrapper that this backing map will use.
      Parameters:
      store - the StoreWrapper that this backing map will delegate persistence responsibilities to
      fReadOnly - pass true to prevent the usage of the cache store write operations
    • instantiateCacheStoreWrapper

      protected ReadWriteBackingMap.StoreWrapper instantiateCacheStoreWrapper(CacheStore store)
      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

      protected ReadWriteBackingMap.StoreWrapper instantiateCacheStoreWrapper(BinaryEntryStore store)
      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

      protected CacheStore instantiateCacheLoaderCacheStore(CacheLoader loader)
      Factory pattern: Instantiate a CacheLoaderCacheStore wrapper around a passed CacheLoader.
      Parameters:
      loader - the CacheLoader to wrap; never null
      Returns:
      a CacheStore instance