public class SimpleOverflowMap extends AbstractKeyBasedMap
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.
Modifier and Type | Class and 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 compares
Object.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.
|
AbstractKeyBasedMap.DeferredCacheEvent<K,V>, AbstractKeyBasedMap.EntrySet, AbstractKeyBasedMap.KeySet, AbstractKeyBasedMap.ValuesCollection
Base.LoggingWriter, Base.StackFrame
Modifier and Type | Field and 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 and 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
|
Modifier and Type | Method and 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.
|
clone, containsValue, entrySet, equals, getAll, hashCode, instantiateEntrySet, instantiateKeySet, instantiateValues, keySet, toString, values
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, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, 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
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public static final int ENTRY_INSERTED
public static final int ENTRY_UPDATED
public static final int ENTRY_DELETED
protected ObservableMap m_mapFront
protected Map m_mapBack
protected Map m_mapMiss
protected SimpleCacheStatistics m_stats
public SimpleOverflowMap(ObservableMap mapFront, Map mapBack)
mapBack
- back mapmapFront
- front mappublic SimpleOverflowMap(ObservableMap mapFront, Map mapBack, Map mapMiss)
mapFront
- front mapmapBack
- back mapmapMiss
- an optional miss cachepublic void clear()
clear
in interface Map
clear
in class AbstractKeyBasedMap
public boolean containsKey(Object oKey)
containsKey
in interface Map
containsKey
in class AbstractKeyBasedMap
public Object get(Object oKey)
get
in interface Map
get
in class AbstractKeyBasedMap
oKey
- the key objectpublic boolean isEmpty()
isEmpty
in interface Map
isEmpty
in class AbstractKeyBasedMap
public Object put(Object oKey, Object oValue)
put
in interface Map
put
in class AbstractKeyBasedMap
oKey
- key with which the specified value is to be associatedoValue
- value to be associated with the specified keypublic void putAll(Map map)
put(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.putAll
in interface Map
putAll
in class AbstractKeyBasedMap
map
- the Map containing the key/value pairings to put into this
Mappublic Object remove(Object oKey)
remove
in interface Map
remove
in class AbstractKeyBasedMap
oKey
- key whose mapping is to be removed from the mappublic int size()
size
in interface Map
size
in class AbstractKeyBasedMap
protected Iterator iterateKeys()
iterateKeys
in class AbstractKeyBasedMap
protected boolean removeBlind(Object oKey)
removeBlind
in class AbstractKeyBasedMap
oKey
- key whose mapping is to be removed from the mappublic ObservableMap getFrontMap()
Warning: Direct modifications of the returned map may cause unpredictable behavior of the Overflow Map.
public Map getBackMap()
Warning: Direct modifications of the returned map may cause unpredictable behavior of the Overflow Map.
public Map getMissCache()
Warning: Direct modifications of the returned map may cause unpredictable behavior of the Overflow Map.
public void setMissCache(Map mapMiss)
mapMiss
- miss cache.public CacheStatistics getCacheStatistics()
protected Gate getGate()
protected Map getStatusMap()
protected List getDeferredList()
public boolean isNullValuesAllowed()
public void setNullValuesAllowed(boolean fAllowNulls)
fAllowNulls
- pass true to allow null values; false to
disallowpublic boolean isFrontPutBlind()
public void setFrontPutBlind(boolean fUseFrontPutAll)
fUseFrontPutAll
- pass true to allow null values; false to
disallowprotected MapListener getFrontMapListener()
protected void setFrontMapListener(MapListener listener)
The caller is required to manage all of the thread concurrency issues associated with modifying the listener.
listener
- the MapListener for the front mapprotected MapListener instantiateFrontMapListener()
protected void onFrontEvent(MapEvent evt)
evt
- the eventprotected void processFrontEvent(SimpleOverflowMap.Status status, MapEvent evt)
status
- the statusevt
- the event to process; may be nullprotected SimpleOverflowMap.Status beginKeyProcess(Object oKey)
SimpleOverflowMap.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 call endKeyProcess(java.lang.Object, com.tangosol.net.cache.SimpleOverflowMap.Status)
passing the Status
object returned from this method.oKey
- the key to processprotected void endKeyProcess(Object oKey, SimpleOverflowMap.Status status)
oKey
- the keystatus
- the Status object returned from the call to
beginKeyProcess(java.lang.Object)
protected SimpleOverflowMap.Status[] beginBulkKeyProcess(Object[] aoKey)
aoKey
- an array of zero or more keys; note that this array may
be re-ordered by this methodbeginKeyProcess(Object)
protected void endBulkKeyProcess(Object[] aoKey, SimpleOverflowMap.Status[] aStatus)
aoKey
- the same array of keys as were passed to
beginBulkKeyProcess(java.lang.Object[])
aStatus
- the array of Status objects returned from the call to
beginBulkKeyProcess(java.lang.Object[])
protected void beginMapProcess()
protected void endMapProcess()
protected void processDeferredEvents()
protected static void verifyNoNulls(Collection collection, String sAssert)
collection
- a CollectionsAssert
- the human-readable description of the error if any
nulls are found in the passed Collectionprotected static void putOne(Map map, Object oKey, Object oValue, boolean fPutBlind)
map
- the Map to put intooKey
- the key to putoValue
- the value to putfPutBlind
- true to use the putBlind optimizationprotected static void warnEventSequence(MapEvent evtOld, MapEvent evtNew)
evtOld
- the previous (potentially amalgamated) eventevtNew
- the new eventprotected SimpleOverflowMap.Status instantiateStatus()