Class ObservableSplittingBackingCache
- All Implemented Interfaces:
Disposable
,CacheMap
,ConfigurableCacheMap
,PartitionAwareBackingMap
,ObservableMap
,AutoCloseable
,Map
LocalCache
, but it internally
partitions its data across any number of caches that implement the
ConfigurableCacheMap interface. Note that the underlying backing maps must
implement the ConfigurableCacheMap interface or a runtime exception will
occur.- Author:
- cp 2009.01.16
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
A subclass of PartitionSplittingBackingMap which allows an injected instance ofObservableSplittingBackingMap
to be called immediately before inserting a value(s) in a partition map.class
A set of ConfigurableCacheMap entries backed by this map.Nested classes/interfaces inherited from class com.tangosol.util.WrapperObservableMap
WrapperObservableMap.InternalListener
Nested classes/interfaces inherited from class com.tangosol.util.AbstractKeySetBasedMap
AbstractKeySetBasedMap.KeyIterator, AbstractKeySetBasedMap.KeySet, AbstractKeySetBasedMap.ValuesCollection
Nested classes/interfaces inherited from class com.tangosol.util.AbstractKeyBasedMap
AbstractKeyBasedMap.DeferredCacheEvent<K,
V> Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
Nested classes/interfaces inherited from interface com.tangosol.net.cache.ConfigurableCacheMap
ConfigurableCacheMap.Entry, ConfigurableCacheMap.EvictionApprover, ConfigurableCacheMap.EvictionPolicy, ConfigurableCacheMap.UnitCalculator
-
Field Summary
Modifier and TypeFieldDescriptionprotected ConfigurableCacheMap[]
A cached array of the backing ConfigurableCacheMap instances.protected ConfigurableCacheMap.EvictionApprover
An optional EvictionApprover registered with this cache.protected ConfigurableCacheMap.UnitCalculator
The unit calculator.protected int
The expiry delay.protected int
The fair share of high units for each partition map.protected int
High units is the number of units that triggers eviction.protected int
The high units adjusted based on thepartition unit factor
.protected int
The fair share of low units for each partition map.protected int
Low units is the number of units to evict down to.protected int
The low units adjusted based on thepartition unit factor
.protected Class
protected int
The unit factor.protected ConfigurableCacheMap.EvictionPolicy
The eviction policy.protected static final int
The maximum unit factor for partition maps.Fields inherited from class com.tangosol.util.WrapperObservableMap
m_fDeferredEvent, m_fTranslateEvents, m_listenerInternal, m_listenerSupport, m_map, m_stats
Fields inherited from class com.tangosol.util.Base
LOG_ALWAYS, LOG_CONFIG, LOG_DEBUG, LOG_ERR, LOG_INFO, LOG_MAX, LOG_MIN, LOG_QUIET, LOG_WARN, POWER_0, POWER_G, POWER_K, POWER_M, POWER_T, UNIT_D, UNIT_H, UNIT_M, UNIT_MS, UNIT_NS, UNIT_S, UNIT_US
Fields inherited from interface com.tangosol.net.cache.CacheMap
EXPIRY_DEFAULT, EXPIRY_NEVER
-
Constructor Summary
ConstructorDescriptionObservableSplittingBackingCache
(BackingMapManager bmm, String sName) Create a ObservableSplittingBackingCache that adds ConfigurableCacheMap functionality to an ObservableSplittingBackingMap. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
adjustUnits
(int cUnits) Adjust the number of units for each map with the pool of units provided.protected int
calcUnitFairShare
(int cUnits) Return the fair share of units for each child maps.protected void
claimAll
(ConfigurableCacheMap mapRequestor) Claim the full entitlement of units for mapRequestor.protected void
claimUnused
(ConfigurableCacheMap mapRequestor) Claim as many units as possible from existing maps without causing over-allocated maps to evict.void
createPartition
(int nPid) Add a partition to the PartitionAwareBackingMap.void
destroyPartition
(int nPid) Remove a partition from the PartitionAwareBackingMap.void
evict()
Evict all entries from the cache that are no longer valid, and potentially prune the cache size if the cache is size-limited and its size is above the caching low water mark.void
Evict a specified key from the cache, as if it had expired from the cache.void
evictAll
(Collection colKeys) Evict the specified keys from the cache, as if they had each expired from the cache.getCacheEntry
(Object oKey) Locate a cache Entry in the cache based on its key.protected int
Determine the high units adjusted based on thepartition unit factor
.protected int
Determine the low units adjusted based on thepartition unit factor
.Obtain the registered EvictionApprover.Obtain the current EvictionPolicy used by the cache.int
Determine the default "time to live" for each individual cache entry.protected int
Return the fair share of high-units per partition map.int
Determine the limit of the cache size in units.protected int
Return the fair share of low-units per partition map.int
Determine the point to which the cache will shrink when it prunes.long
Determine the next expiry time for the cache entries.protected ConfigurableCacheMap
getPartitionCache
(Object oKey) Obtain the backing cache for a particular key.protected ConfigurableCacheMap[]
Obtain the array of backing caches.Return the uniform type used by each partition map.protected int
Determine the unit factor for individual partition maps.Obtain the current UnitCalculator used by the cache.int
Determine the factor by which the Units, LowUnits and HighUnits properties are adjusted.int
getUnits()
Determine the number of units that the cache currently stores.protected void
Initialize the configurable properties of this cache-map.protected Set
Factory pattern: Create a Set that represents the entries in the Map.protected void
prepareUpdate
(Map mapPartition, Map mapUpdate) Prepare mapPart, a map representing a partition, for the impending changes in which all of the mappings from mapUpdate will be copied to mapPart.void
Set the EvictionApprover for this ConfigurableCacheMap.void
Set the EvictionPolicy for the cache to use.void
setExpiryDelay
(int cMillis) Specify the default "time to live" for cache entries.void
setHighUnits
(int cMax) Update the maximum size of the cache in units.void
setLowUnits
(int cUnits) Specify the point to which the cache will shrink when it prunes.void
setUnitCalculator
(ConfigurableCacheMap.UnitCalculator calculator) Set the UnitCalculator for the cache to use.void
setUnitFactor
(int nFactor) Determine the factor by which the Units, LowUnits and HighUnits properties are adjusted.Methods inherited from class com.tangosol.net.partition.ObservableSplittingBackingMap
addMapListener, addMapListener, dispose, getBackingMapManager, getCacheStatistics, getName, getPartitionMap, getPartitionMap, getPartitionSplittingBackingMap, instantiateKeySet, isCollectStats, isEventFabricator, put, removeMapListener, removeMapListener, setTranslateEvents, toString
Methods inherited from class com.tangosol.util.WrapperObservableMap
addMapListener, clear, containsValue, dispatchEvent, dispatchPendingEvent, ensureInternalListener, ensureMapListenerSupport, equals, get, getDescription, getInternalKeySet, getMap, getMapListenerSupport, hashCode, hasListeners, instantiateInternalListener, isInternalKeySetIteratorMutable, isSynthetic, isTranslateEvents, put, putAll, remove, removeBlind, removeMapListener, setCollectStats
Methods inherited from class com.tangosol.util.AbstractKeySetBasedMap
containsKey, instantiateKeyIterator, instantiateValues, isEmpty, iterateKeys, size
Methods inherited from class com.tangosol.util.AbstractKeyBasedMap
clone, entrySet, getAll, keySet, values
Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.oracle.coherence.common.base.Disposable
close
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from interface com.tangosol.util.ObservableMap
addMapListener, addMapListener, addMapListener, removeMapListener, removeMapListener, removeMapListener
-
Field Details
-
MAX_PARTITION_MAP_UNIT_FACTOR
protected static final int MAX_PARTITION_MAP_UNIT_FACTORThe maximum unit factor for partition maps.- See Also:
-
m_cHighUnits
protected int m_cHighUnitsHigh units is the number of units that triggers eviction. The value -1 indicates that this cache has not been instructed to override the high units of the underlying caches. -
m_cLowUnits
protected int m_cLowUnitsLow units is the number of units to evict down to. The value -1 indicates that this cache has not been instructed to override the low units of the underlying caches. -
m_cHighUnitsCalibrated
protected int m_cHighUnitsCalibratedThe high units adjusted based on thepartition unit factor
. -
m_cLowUnitsCalibrated
protected int m_cLowUnitsCalibratedThe low units adjusted based on thepartition unit factor
. -
m_nUnitFactor
protected int m_nUnitFactorThe unit factor. The value -1 indicates that this cache has not been instructed to override the unit factor of the underlying caches. -
m_cExpiryDelayMillis
protected int m_cExpiryDelayMillisThe expiry delay. The value -1 indicates that this cache has not been instructed to override the expiry delay of the underlying caches. -
m_policy
The eviction policy. The value of null indicates that this cache has not been instructed to override the eviction policy of the underlying caches. -
m_calculator
The unit calculator. The value of null indicates that this cache has not been instructed to override the unit calculator of the underlying caches. -
m_acache
A cached array of the backing ConfigurableCacheMap instances. -
m_apprvrEvict
An optional EvictionApprover registered with this cache. -
m_clzPartitionMap
-
-
Constructor Details
-
ObservableSplittingBackingCache
Create a ObservableSplittingBackingCache that adds ConfigurableCacheMap functionality to an ObservableSplittingBackingMap.- Parameters:
bmm
- a callback that knows how to create and release the backing maps that this ObservableSplittingBackingCache is responsible forsName
- the cache name for which this backing map exists
-
-
Method Details
-
createPartition
public void createPartition(int nPid) Add a partition to the PartitionAwareBackingMap.- Specified by:
createPartition
in interfacePartitionAwareBackingMap
- Overrides:
createPartition
in classObservableSplittingBackingMap
- Parameters:
nPid
- the partition id that the PartitionAwareBackingMap will be responsible for, starting at this instant
-
destroyPartition
public void destroyPartition(int nPid) Remove a partition from the PartitionAwareBackingMap.- Specified by:
destroyPartition
in interfacePartitionAwareBackingMap
- Overrides:
destroyPartition
in classObservableSplittingBackingMap
- Parameters:
nPid
- the partition id that the PartitionAwareBackingMap will no longer be responsible for, starting at this instant
-
getUnits
public int getUnits()Determine the number of units that the cache currently stores.Note: It is expected that the return type will be widened to a long in Coherence 4.
- Specified by:
getUnits
in interfaceConfigurableCacheMap
- Returns:
- the current size of the cache in units
-
getHighUnits
public int getHighUnits()Determine the limit of the cache size in units. The cache will prune itself automatically once it reaches its maximum unit level. This is often referred to as the "high water mark" of the cache.Note: It is expected that the return type will be widened to a long in Coherence 4.
- Specified by:
getHighUnits
in interfaceConfigurableCacheMap
- Returns:
- the limit of the cache size in units
-
setHighUnits
public void setHighUnits(int cMax) Update the maximum size of the cache in units. This is often referred to as the "high water mark" of the cache.Note: It is expected that the parameter will be widened to a long in Coherence 4.
- Specified by:
setHighUnits
in interfaceConfigurableCacheMap
- Parameters:
cMax
- the new maximum size of the cache, in units
-
getLowUnits
public int getLowUnits()Determine the point to which the cache will shrink when it prunes. This is often referred to as a "low water mark" of the cache. If the cache incrementally prunes, then this setting will have no effect.Note: It is expected that the parameter will be widened to a long in Coherence 4.
- Specified by:
getLowUnits
in interfaceConfigurableCacheMap
- Returns:
- the number of units that the cache prunes to
-
setLowUnits
public void setLowUnits(int cUnits) Specify the point to which the cache will shrink when it prunes. This is often referred to as a "low water mark" of the cache.Note: It is expected that the parameter will be widened to a long in Coherence 4.
- Specified by:
setLowUnits
in interfaceConfigurableCacheMap
- Parameters:
cUnits
- the number of units that the cache prunes to
-
getUnitFactor
public int getUnitFactor()Determine the factor by which the Units, LowUnits and HighUnits properties are adjusted. Using a binary unit calculator, for example, the factor 1048576 could be used to count megabytes instead of bytes.Note: This property exists only to avoid changing the type of the units, low units and high units properties from 32-bit values to 64-bit values. It is expected that the parameter will be dropped in Coherence 4.
- Specified by:
getUnitFactor
in interfaceConfigurableCacheMap
- Returns:
- the units factor; the default is 1
-
setUnitFactor
public void setUnitFactor(int nFactor) Determine the factor by which the Units, LowUnits and HighUnits properties are adjusted. Using a binary unit calculator, for example, the factor 1048576 could be used to count megabytes instead of bytes.Note: This property exists only to avoid changing the type of the units, low units and high units properties from 32-bit values to 64-bit values. It is expected that the parameter will be dropped in Coherence 4.
- Specified by:
setUnitFactor
in interfaceConfigurableCacheMap
- Parameters:
nFactor
- the units factor; the default is 1
-
getEvictionPolicy
Obtain the current EvictionPolicy used by the cache.- Specified by:
getEvictionPolicy
in interfaceConfigurableCacheMap
- Returns:
- the EvictionPolicy used by the cache
-
setEvictionPolicy
Set the EvictionPolicy for the cache to use.- Specified by:
setEvictionPolicy
in interfaceConfigurableCacheMap
- Parameters:
policy
- an EvictionPolicy
-
evict
Evict a specified key from the cache, as if it had expired from the cache. If the key is not in the cache, then the method has no effect.- Specified by:
evict
in interfaceConfigurableCacheMap
- Parameters:
oKey
- the key to evict from the cache
-
evictAll
Evict the specified keys from the cache, as if they had each expired from the cache.The result of this method is defined to be semantically the same as the following implementation:
for (Iterator iter = colKeys.iterator(); iter.hasNext(); ) { Object oKey = iter.next(); evict(oKey); }
- Specified by:
evictAll
in interfaceConfigurableCacheMap
- Parameters:
colKeys
- a collection of keys to evict from the cache
-
evict
public void evict()Evict all entries from the cache that are no longer valid, and potentially prune the cache size if the cache is size-limited and its size is above the caching low water mark.- Specified by:
evict
in interfaceConfigurableCacheMap
-
getEvictionApprover
Obtain the registered EvictionApprover.- Specified by:
getEvictionApprover
in interfaceConfigurableCacheMap
- Returns:
- the EvictionApprover (could be null)
-
setEvictionApprover
Set the EvictionApprover for this ConfigurableCacheMap.- Specified by:
setEvictionApprover
in interfaceConfigurableCacheMap
- Parameters:
approver
- the EvictionApprover
-
getExpiryDelay
public int getExpiryDelay()Determine the default "time to live" for each individual cache entry.- Specified by:
getExpiryDelay
in interfaceConfigurableCacheMap
- Returns:
- the number of milliseconds that a cache entry value will live, or zero if cache entries are never automatically expired
-
setExpiryDelay
public void setExpiryDelay(int cMillis) Specify the default "time to live" for cache entries. This does not affect the already-scheduled expiry of existing entries.- Specified by:
setExpiryDelay
in interfaceConfigurableCacheMap
- Parameters:
cMillis
- the number of milliseconds that cache entries will live, or zero to disable automatic expiry
-
getNextExpiryTime
public long getNextExpiryTime()Determine the next expiry time for the cache entries. This value is supposed to be used only by the "active" expiry algorithms, so for implementations that choose to return the value of zero the entries will be evicted as with pre-existing "passive" expiry approach.- Specified by:
getNextExpiryTime
in interfaceConfigurableCacheMap
- Returns:
- the earliest time (using the
SafeClock
) that one or more cache entries will expire or zero if the cache is empty, its entries never expire or the implementation chooses to avoid the pro-active eviction
-
getCacheEntry
Locate a cache Entry in the cache based on its key.- Specified by:
getCacheEntry
in interfaceConfigurableCacheMap
- Parameters:
oKey
- the key object to search for- Returns:
- the Entry or null
-
getUnitCalculator
Obtain the current UnitCalculator used by the cache.- Specified by:
getUnitCalculator
in interfaceConfigurableCacheMap
- Returns:
- the UnitCalculator used by the cache
-
setUnitCalculator
Set the UnitCalculator for the cache to use.- Specified by:
setUnitCalculator
in interfaceConfigurableCacheMap
- Parameters:
calculator
- a UnitCalculator
-
getPartitionMapType
Return the uniform type used by each partition map.- Returns:
- the type of partition map
-
prepareUpdate
Prepare mapPart, a map representing a partition, for the impending changes in which all of the mappings from mapUpdate will be copied to mapPart.This implementation will check if mapPart is under-allocated for high units. If this is the case, demand the entitled unit amount from other maps.
- Overrides:
prepareUpdate
in classObservableSplittingBackingMap
- Parameters:
mapPartition
- the map to be mutated with the contents of mapUpdatemapUpdate
- the map of changes to be applied
-
claimUnused
Claim as many units as possible from existing maps without causing over-allocated maps to evict.- Parameters:
mapRequestor
- the map requesting its fair share of units
-
claimAll
Claim the full entitlement of units for mapRequestor. This method should only be invoked if the map has insufficient units, based on a pending put request, however does not occupy its fair share.- Parameters:
mapRequestor
- the map demanding its entitled fair share
-
adjustUnits
protected void adjustUnits(int cUnits) Adjust the number of units for each map with the pool of units provided. The units provided is a total across all maps with the adjustment per map being made as prescribed below.The provided units may be positive or negative, with the latter suggesting that this number of units should be retrieved, thus decremented, from child maps. If the provided units is positive, maps that are over-allocated may consumer the provided amount. If the provided units is negative maintain a positive delta between the fair share and their current high units may consume the minimum between what is available from the provided units and the determined delta. If the provided units is negative, those maps whose current high unit allocation is more than the fair share will have this delta decremented until the debt (cUnits) is reclaimed.
- Parameters:
cUnits
- the number of units to either disseminate (positive unit value) or retract across the maps
-
initializeConfiguredProperties
protected void initializeConfiguredProperties()Initialize the configurable properties of this cache-map. -
getPartitionCache
Obtain the backing cache for a particular key. If the key is not owned by a partition represented by this ObservableSplittingBackingCache, then a runtime exception is thrown.- Parameters:
oKey
- the key of the desired entry- Returns:
- the backing cache
-
getPartitionCacheArray
Obtain the array of backing caches.- Returns:
- an array of all the per-partition backing caches
-
getCalibratedHighUnits
protected int getCalibratedHighUnits()Determine the high units adjusted based on thepartition unit factor
.- Returns:
- the limit of the cache size in units adjusted by partition unitFactor
-
getCalibratedLowUnits
protected int getCalibratedLowUnits()Determine the low units adjusted based on thepartition unit factor
.- Returns:
- the number of units adjusted by partition unitFactor that the cache prunes to
-
getPartitionUnitFactor
protected int getPartitionUnitFactor()Determine the unit factor for individual partition maps.- Returns:
- the unit factor for partition maps
-
instantiateEntrySet
Factory pattern: Create a Set that represents the entries in the Map.- Overrides:
instantiateEntrySet
in classAbstractKeySetBasedMap
- Returns:
- a new instance of Set that represents the entries in the Map
-