Class SimpleOverflowMap
- java.lang.Object
-
- com.tangosol.util.Base
-
- com.tangosol.util.AbstractKeyBasedMap
-
- com.tangosol.net.cache.SimpleOverflowMap
-
- All Implemented Interfaces:
Map
public class SimpleOverflowMap extends AbstractKeyBasedMap
A non-observable Map implementation that wraps two maps - a front map (assumed to be fast but limited in its maximum size) and a back map (assumed to be slower but much less limited in its maximum size).The SimpleOverflowMap is not observable, and as such it is assumed to be a passive data structure. In other words, it does not support item expiration or other types of "self-generating" events. As such, it may be more efficient for many common use cases that would benefit from the complete avoidance of event handling. As a second effect of being a passive data structure, the implementation is able to avoid tracking all of its entries; instead it tracks only entries that are in the front map and those that currently have a pending event or an in-flight operation occurring. This means that huge key sets are possible, since only keys in the front map will be managed in memory by the overflow map, but it means that some operations that would benefit from knowing the entire set of keys will be more expensive. Examples of operations that would be less efficient as a result include
containsKey()
,size()
,keySet().iterator()
, etc.- Since:
- Coherence 3.1
- Author:
- cp 2005.07.11
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
SimpleOverflowMap.FrontFilterConverter
A combination Filter and Converter used to iterate through the status map in order to iterate through the front keys.protected class
SimpleOverflowMap.FrontMapListener
A listener for the front map that moves evictions to the back map.protected static class
SimpleOverflowMap.HashcodeComparator
A stateless Comparator that comparesObject.hashCode()
values.protected class
SimpleOverflowMap.KeyIterator
An Iterator implementation that attempts to provide the most resilient and most up-to-date view of the keys in the OverflowMap.protected static class
SimpleOverflowMap.Status
The Status object is used to manage concurrency at the key level for the key-level operations against the Map, to track all the items in the front Map, to manage the state transition for operations occurring against the Map, and to coordinate events across multiple threads.-
Nested classes/interfaces inherited from class com.tangosol.util.AbstractKeyBasedMap
AbstractKeyBasedMap.DeferredCacheEvent<K,V>, AbstractKeyBasedMap.EntrySet, AbstractKeyBasedMap.KeySet, AbstractKeyBasedMap.ValuesCollection
-
Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
-
Field Summary
Fields Modifier and Type Field Description static int
ENTRY_DELETED
This event indicates that an entry has been removed from the map.static int
ENTRY_INSERTED
This event indicates that an entry has been added to the map.static int
ENTRY_UPDATED
This event indicates that an entry has been updated in the map.protected Map
m_mapBack
The "back" map, which the front overflows to.protected ObservableMap
m_mapFront
The "front" map, which is size-limited.protected Map
m_mapMiss
The miss cache; may be null.protected SimpleCacheStatistics
m_stats
The CacheStatistics object maintained by this cache.
-
Constructor Summary
Constructors Constructor Description SimpleOverflowMap(ObservableMap mapFront, Map mapBack)
Construct a SimpleOverflowMap using two specified maps: FrontMap (aka "cache" or "shallow") and BackMap (aka "file" or "deep")SimpleOverflowMap(ObservableMap mapFront, Map mapBack, Map mapMiss)
Construct a SimpleOverflowMap using three specified maps: Front Map (aka "cache" or "shallow") and Back Map (aka "file" or "deep") Miss Cache
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected SimpleOverflowMap.Status[]
beginBulkKeyProcess(Object[] aoKey)
Begin key-level procecessing for any number of keys.protected SimpleOverflowMap.Status
beginKeyProcess(Object oKey)
Block until a key is available for processing, and return the Status object for that key.protected void
beginMapProcess()
Block until this thread has exclusive access to perform operations against the OverflowMap.void
clear()
Clear all key/value mappings.boolean
containsKey(Object oKey)
Returns true if this map contains a mapping for the specified key.protected void
endBulkKeyProcess(Object[] aoKey, SimpleOverflowMap.Status[] aStatus)
Finish the processing of any number of keys.protected void
endKeyProcess(Object oKey, SimpleOverflowMap.Status status)
Finish the processing of a single key.protected void
endMapProcess()
Release exclusive access for the OverflowMap.Object
get(Object oKey)
Returns the value to which this map maps the specified key.Map
getBackMap()
Returns the back Map.CacheStatistics
getCacheStatistics()
Returns the CacheStatistics for this cache.protected List
getDeferredList()
Obtain the List of keys that may have deferred events.ObservableMap
getFrontMap()
Returns the front Map.protected MapListener
getFrontMapListener()
Get the MapListener for the front map.protected Gate
getGate()
Obtain the Gate for managing key-level and Collection-level operations against the Map, versus Map-level operations themselves.Map
getMissCache()
Returns the optional miss cache.protected Map
getStatusMap()
Obtain the Map of Status objects for entries managed by this Overflow Map.protected MapListener
instantiateFrontMapListener()
Factory pattern: Front Map Listener.protected SimpleOverflowMap.Status
instantiateStatus()
Factory method: Instantiate a Status object.boolean
isEmpty()
Returns true if this map contains no key-value mappings.boolean
isFrontPutBlind()
Determine if the front Map is more efficiently updated using putAll.boolean
isNullValuesAllowed()
Determine if null values are permitted.protected Iterator
iterateKeys()
Create an iterator over the keys in this Map.protected void
onFrontEvent(MapEvent evt)
Either handle an event by turning it over to another thread that is processing the key specified by the event, or take responsibility on this thread for deferring the event and registering its immediate side-effects.protected void
processDeferredEvents()
Process deferred events, if there are any.protected void
processFrontEvent(SimpleOverflowMap.Status status, MapEvent evt)
Process an event.Object
put(Object oKey, Object oValue)
Associates the specified value with the specified key in this map.void
putAll(Map map)
Copies all of the mappings from the specified map to this map.protected static void
putOne(Map map, Object oKey, Object oValue, boolean fPutBlind)
Helper to put a value into a map using either the put or putAll method.Object
remove(Object oKey)
Removes the mapping for this key from this map if present.protected boolean
removeBlind(Object oKey)
Removes the mapping for this key from this map if present.protected void
setFrontMapListener(MapListener listener)
Specify the MapListener for the front map.void
setFrontPutBlind(boolean fUseFrontPutAll)
Specify whether the front Map is more efficiently updated using putAll.void
setMissCache(Map mapMiss)
Set Miss Cache.void
setNullValuesAllowed(boolean fAllowNulls)
Specify whether null values are permitted.int
size()
Returns the number of key-value mappings in this map.protected static void
verifyNoNulls(Collection collection, String sAssert)
Check the passed collection for nulls, and fail if it contains any.protected static void
warnEventSequence(MapEvent evtOld, MapEvent evtNew)
Issue a one-time warning that events are being received in an order than cannot be explained by normal operation according to the contracts expected by this OverflowMap.-
Methods inherited from class com.tangosol.util.AbstractKeyBasedMap
clone, containsValue, entrySet, equals, getAll, hashCode, instantiateEntrySet, instantiateKeySet, instantiateValues, keySet, toString, 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 java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Field Detail
-
ENTRY_INSERTED
public static final int ENTRY_INSERTED
This event indicates that an entry has been added to the map.- See Also:
- Constant Field Values
-
ENTRY_UPDATED
public static final int ENTRY_UPDATED
This event indicates that an entry has been updated in the map.- See Also:
- Constant Field Values
-
ENTRY_DELETED
public static final int ENTRY_DELETED
This event indicates that an entry has been removed from the map.- See Also:
- Constant Field Values
-
m_mapFront
protected ObservableMap m_mapFront
The "front" map, which is size-limited.
-
m_mapBack
protected Map m_mapBack
The "back" map, which the front overflows to.
-
m_mapMiss
protected Map m_mapMiss
The miss cache; may be null.
-
m_stats
protected SimpleCacheStatistics m_stats
The CacheStatistics object maintained by this cache.
-
-
Constructor Detail
-
SimpleOverflowMap
public SimpleOverflowMap(ObservableMap mapFront, Map mapBack)
Construct a SimpleOverflowMap using two specified maps:- FrontMap (aka "cache" or "shallow") and
- BackMap (aka "file" or "deep")
- Parameters:
mapBack
- back mapmapFront
- front map
-
SimpleOverflowMap
public SimpleOverflowMap(ObservableMap mapFront, Map mapBack, Map mapMiss)
Construct a SimpleOverflowMap using three specified maps:- Front Map (aka "cache" or "shallow") and
- Back Map (aka "file" or "deep")
- Miss Cache
- Parameters:
mapFront
- front mapmapBack
- back mapmapMiss
- an optional miss cache
-
-
Method Detail
-
clear
public void clear()
Clear all key/value mappings.- Specified by:
clear
in interfaceMap
- Overrides:
clear
in classAbstractKeyBasedMap
-
containsKey
public boolean containsKey(Object oKey)
Returns true if this map contains a mapping for the specified key.- Specified by:
containsKey
in interfaceMap
- Overrides:
containsKey
in classAbstractKeyBasedMap
- Returns:
- true if this map contains a mapping for the specified key, false otherwise.
-
get
public Object get(Object oKey)
Returns the value to which this map maps the specified key.- Specified by:
get
in interfaceMap
- Specified by:
get
in classAbstractKeyBasedMap
- 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
-
isEmpty
public boolean isEmpty()
Returns true if this map contains no key-value mappings.- Specified by:
isEmpty
in interfaceMap
- Overrides:
isEmpty
in classAbstractKeyBasedMap
- Returns:
- true if this map contains no key-value mappings
-
put
public Object put(Object oKey, Object oValue)
Associates the specified value with the specified key in this map.- Specified by:
put
in interfaceMap
- Overrides:
put
in classAbstractKeyBasedMap
- 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
-
putAll
public void putAll(Map map)
Copies all of the mappings from the specified map to this map. The effect of this call is equivalent to that of callingput(java.lang.Object, java.lang.Object)
on this map once for each mapping in the passed map. The behavior of this operation is unspecified if the passed map is modified while the operation is in progress.- Specified by:
putAll
in interfaceMap
- Overrides:
putAll
in classAbstractKeyBasedMap
- Parameters:
map
- the Map containing the key/value pairings to put into this Map
-
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 interfaceMap
- Overrides:
remove
in classAbstractKeyBasedMap
- 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.
-
size
public int size()
Returns the number of key-value mappings in this map.- Specified by:
size
in interfaceMap
- Overrides:
size
in classAbstractKeyBasedMap
- Returns:
- the number of key-value mappings in this map
-
iterateKeys
protected Iterator iterateKeys()
Create an iterator over the keys in this Map.- Specified by:
iterateKeys
in classAbstractKeyBasedMap
- Returns:
- a new instance of an Iterator over the keys in this Map
-
removeBlind
protected boolean removeBlind(Object oKey)
Removes the mapping for this key from this map if present. This method exists to allow sub-classes to optmiize remove functionalitly for situations in which the original value is not required.- Overrides:
removeBlind
in classAbstractKeyBasedMap
- Parameters:
oKey
- key whose mapping is to be removed from the map- Returns:
- true iff the Map changed as the result of this operation
-
getFrontMap
public ObservableMap getFrontMap()
Returns the front Map.Warning: Direct modifications of the returned map may cause unpredictable behavior of the Overflow Map.
- Returns:
- the front Map
-
getBackMap
public Map getBackMap()
Returns the back Map.Warning: Direct modifications of the returned map may cause unpredictable behavior of the Overflow Map.
- Returns:
- the back Map
-
getMissCache
public Map getMissCache()
Returns the optional miss cache.Warning: Direct modifications of the returned map may cause unpredictable behavior of the Overflow Map.
- Returns:
- the miss cache, or null if there is no miss cache
-
setMissCache
public void setMissCache(Map mapMiss)
Set Miss Cache. Note: do not use other than in OverflowScheme#realizeMap(...)- Parameters:
mapMiss
- miss cache.
-
getCacheStatistics
public CacheStatistics getCacheStatistics()
Returns the CacheStatistics for this cache.- Returns:
- a CacheStatistics object
-
getGate
protected Gate getGate()
Obtain the Gate for managing key-level and Collection-level operations against the Map, versus Map-level operations themselves.- Returns:
- the Gate for the OverflowMap
-
getStatusMap
protected Map getStatusMap()
Obtain the Map of Status objects for entries managed by this Overflow Map. There will be a Status object for each entry in the front map, and a Status object for each key that has a current operation underway.- Returns:
- the Map of Status objects
-
getDeferredList
protected List getDeferredList()
Obtain the List of keys that may have deferred events.- Returns:
- the List of keys of deferred-event Status objects
-
isNullValuesAllowed
public boolean isNullValuesAllowed()
Determine if null values are permitted. By default, they are not.- Returns:
- true iff null values are permitted
-
setNullValuesAllowed
public void setNullValuesAllowed(boolean fAllowNulls)
Specify whether null values are permitted.- Parameters:
fAllowNulls
- pass true to allow null values; false to disallow
-
isFrontPutBlind
public boolean isFrontPutBlind()
Determine if the front Map is more efficiently updated using putAll. (The use of putAll instead of put is called put-blind because it does not return a value.)- Returns:
- true iff the use of the put method should be avoided when updating the front Map, and putAll should be used instead
-
setFrontPutBlind
public void setFrontPutBlind(boolean fUseFrontPutAll)
Specify whether the front Map is more efficiently updated using putAll.- Parameters:
fUseFrontPutAll
- pass true to allow null values; false to disallow
-
getFrontMapListener
protected MapListener getFrontMapListener()
Get the MapListener for the front map.- Returns:
- the MapListener for the front map
-
setFrontMapListener
protected void setFrontMapListener(MapListener listener)
Specify the MapListener for the front map.The caller is required to manage all of the thread concurrency issues associated with modifying the listener.
- Parameters:
listener
- the MapListener for the front map
-
instantiateFrontMapListener
protected MapListener instantiateFrontMapListener()
Factory pattern: Front Map Listener.- Returns:
- a new instance of the listener for the front map
-
onFrontEvent
protected void onFrontEvent(MapEvent evt)
Either handle an event by turning it over to another thread that is processing the key specified by the event, or take responsibility on this thread for deferring the event and registering its immediate side-effects.- Parameters:
evt
- the event
-
processFrontEvent
protected void processFrontEvent(SimpleOverflowMap.Status status, MapEvent evt)
Process an event. The Status must already be owned by this thread and in the processing or committing state.- Parameters:
status
- the statusevt
- the event to process; may be null
-
beginKeyProcess
protected SimpleOverflowMap.Status beginKeyProcess(Object oKey)
Block until a key is available for processing, and return the Status object for that key. The caller is then expected to perform its processing, during which time events against the Map Entry may occur. Note that those events can occur on threads other than the current thread; when this current thread can no longer handle events from other threads, it must callSimpleOverflowMap.Status.closeProcessing()
and then perform its final adjustments to the Status data structure, handling any events that were queued in the meantime on the Status. After completing the processing during this "quiet period" in which all other threads are prevented from accessing this entry or handling events for this entry, then the caller must callendKeyProcess(java.lang.Object, com.tangosol.net.cache.SimpleOverflowMap.Status)
passing the Status object returned from this method.- Parameters:
oKey
- the key to process- Returns:
- the Status object for the specified key
-
endKeyProcess
protected void endKeyProcess(Object oKey, SimpleOverflowMap.Status status)
Finish the processing of a single key.- Parameters:
oKey
- the keystatus
- the Status object returned from the call tobeginKeyProcess(java.lang.Object)
-
beginBulkKeyProcess
protected SimpleOverflowMap.Status[] beginBulkKeyProcess(Object[] aoKey)
Begin key-level procecessing for any number of keys.- Parameters:
aoKey
- an array of zero or more keys; note that this array may be re-ordered by this method- Returns:
- an array of Status objects corresponding to the passed keys
- See Also:
beginKeyProcess(Object)
-
endBulkKeyProcess
protected void endBulkKeyProcess(Object[] aoKey, SimpleOverflowMap.Status[] aStatus)
Finish the processing of any number of keys.- Parameters:
aoKey
- the same array of keys as were passed tobeginBulkKeyProcess(java.lang.Object[])
aStatus
- the array of Status objects returned from the call tobeginBulkKeyProcess(java.lang.Object[])
-
beginMapProcess
protected void beginMapProcess()
Block until this thread has exclusive access to perform operations against the OverflowMap.
-
endMapProcess
protected void endMapProcess()
Release exclusive access for the OverflowMap.
-
processDeferredEvents
protected void processDeferredEvents()
Process deferred events, if there are any. This implementation processes only the first deferred event that it encounters.
-
verifyNoNulls
protected static void verifyNoNulls(Collection collection, String sAssert)
Check the passed collection for nulls, and fail if it contains any.- Parameters:
collection
- a CollectionsAssert
- the human-readable description of the error if any nulls are found in the passed Collection
-
putOne
protected static void putOne(Map map, Object oKey, Object oValue, boolean fPutBlind)
Helper to put a value into a map using either the put or putAll method.- Parameters:
map
- the Map to put intooKey
- the key to putoValue
- the value to putfPutBlind
- true to use the putBlind optimization
-
warnEventSequence
protected static void warnEventSequence(MapEvent evtOld, MapEvent evtNew)
Issue a one-time warning that events are being received in an order than cannot be explained by normal operation according to the contracts expected by this OverflowMap.- Parameters:
evtOld
- the previous (potentially amalgamated) eventevtNew
- the new event
-
instantiateStatus
protected SimpleOverflowMap.Status instantiateStatus()
Factory method: Instantiate a Status object.- Returns:
- a new Status object
-
-