public class SimpleMapIndex extends Base implements MapIndex
Modifier and Type | Class and Description |
---|---|
static class |
SimpleMapIndex.IndexCalculator
A stateful
calculator
used to calculate the cost of a homogeneous index (holding all values of a
single type). |
Base.LoggingWriter, Base.StackFrame
Modifier and Type | Field and Description |
---|---|
protected ConfigurableCacheMap.UnitCalculator |
m_calculator
UnitCalculator used to estimate the cost of a value.
|
protected int |
m_cLogMissingIdx
The number of "missing inverse index" messages that have been logged.
|
protected Comparator |
m_comparator
Comparator used to sort the index.
|
protected BackingMapContext |
m_ctx
The
context associated with this index. |
protected long |
m_cUnits
The size footprint of the index, in units (as defined by the UnitCalculator).
|
protected ValueExtractor |
m_extractor
ValueExtractor object that this MapIndex uses to extract an indexable
property value from a [converted] value stored in the resource map.
|
protected boolean |
m_fForwardIndex
Specifies whether or not this MapIndex supports a forward index.
|
protected boolean |
m_fImmutableValues
Specifies whether or not the index is based on the immutable values (e.g. keys).
|
protected boolean |
m_fOrdered
Specifies whether or not this MapIndex orders the contents of the
indexed information.
|
protected boolean |
m_fSplitCollection
If a value extracted by the ValueExtractor is a Collection, this
property specifies whether or not it should be treated as a Collection
of contained attributes or indexed as a single composite attribute.
|
protected long |
m_ldtLogMissingIdx
The time at which the most recent logging of "missing inverse index"
messages started.
|
protected Map |
m_mapForward
Map that contains the index values (forward index).
|
protected Map |
m_mapInverse
Map that contains the index contents (inverse index).
|
protected Set |
m_setKeyExcluded
A set of keys for the entries, which could not be included in the index.
|
Modifier | Constructor and Description |
---|---|
|
SimpleMapIndex(ValueExtractor extractor,
boolean fOrdered,
Comparator comparator,
BackingMapContext ctx)
Construct an index for the given map.
|
protected |
SimpleMapIndex(ValueExtractor extractor,
boolean fOrdered,
Comparator comparator,
boolean fInit,
BackingMapContext ctx)
Construct an index for the given map.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addForwardEntry(Object oKey,
Object oIxValueNew)
Add a new mapping to the forward index map.
|
protected Object |
addInverseCollectionMapping(Map mapIndex,
Object oIxValue,
Object oKey)
Add new mappings from the elements of the given value to the given key
in the supplied index.
|
protected Object |
addInverseMapping(Map mapIndex,
Object oIxValue,
Object oKey)
Add a new mapping from the given indexed value to the given key in the
supplied index.
|
protected Object |
addInverseMapping(Object oIxValue,
Object oKey)
Add a new mapping from the given indexed value to the given key in the
inverse index.
|
protected Set |
collectRemoved(Object oIxValueOld,
Object oIxValueNew)
Given that the old value is known to be a Collection or an array,
collect all the enclosed elements that are not part of the new value.
|
void |
delete(Map.Entry entry)
Update this index in response to a remove operation on a cache.
|
protected void |
deleteInternal(Map.Entry entry)
Update this index in response to a remove operation on a cache.
|
protected Collection |
ensureCollection(Object oValue)
Return a Collection representation of the specified value, which could be
a Collection, Object[], scalar, or NO_VALUE.
|
boolean |
equals(Object o)
Compares the specified object with this index for equality.
|
protected Object |
extractNewValue(Map.Entry entry)
Extract the "new" value from the specified entry.
|
protected Object |
extractOldValue(MapTrigger.Entry entry)
Extract the "old" value from the specified entry.
|
Object |
get(Object oKey)
Using the index information if possible, get the value associated with
the specified key.
|
ConfigurableCacheMap.UnitCalculator |
getCalculator()
Return the UnitCalculator used to size this index's contents.
|
Comparator |
getComparator()
Get the Comparator used to sort the index.
|
protected Map.Entry |
getForwardEntry(Object oKey)
Get the forward index entry associated with the specified key.
|
Map |
getIndexContents()
Get the Map that contains the index contents.
|
long |
getUnits()
Retrieve the size of this index in units (as defined by the
UnitCalculator ). |
ValueExtractor |
getValueExtractor()
Obtain the ValueExtractor object that the MapIndex uses to extract
an indexable Object from a value stored in the indexed Map.
|
int |
hashCode()
Returns the hash code value for this MapIndex.
|
protected void |
initialize(boolean fForwardIndex)
Initialize the index's data structures.
|
void |
insert(Map.Entry entry)
Update this index in response to a insert operation on a cache.
|
protected void |
insertInternal(Map.Entry entry)
Update this index in response to a insert operation on a cache.
|
protected ConfigurableCacheMap.UnitCalculator |
instantiateCalculator()
Factory method used to create a new calculator.
|
protected Map |
instantiateForwardIndex()
Instantiate the forward index.
|
protected Map |
instantiateInverseIndex(boolean fOrdered,
Comparator comparator)
Instantiate the inverse index.
|
protected Set |
instantiateSet()
Factory method used to create a new set containing the keys associated
with a single value.
|
boolean |
isForwardIndexSupported()
Determine whether or not this SimpleMapIndex supports a forward index.
|
protected boolean |
isKeyExcluded(Object oKey)
Check if the entry with the given key is excluded from the index.
|
boolean |
isOptimizeMV()
Specifies whether an attempt will be made to search the forward map
for an existing reference that is "equal" to the specified mutli-value
and use it instead (if available) to reduce the index memory footprint.
|
boolean |
isOrdered()
Determine if the MapIndex orders the contents of the indexed
information.
|
boolean |
isPartial()
Determine if indexed information for any entry in the indexed Map has
been excluded from this index.
|
protected void |
logMissingIdx(Object oIxValue,
Object oKey)
Log messages for missing inverse index.
|
protected void |
onMappingAdded()
Increase the size of the index by the size of an index map entry.
|
protected void |
onMappingAdded(Object oValue,
int cSize)
Increase the size of the index by the estimated size of the specified
added value.
|
protected void |
onMappingRemoved()
Decrease the size of the index by the size of an index map entry.
|
protected void |
onMappingRemoved(Object oValue)
Decrease the size of the index by the estimated size of the specified
removed value.
|
protected void |
removeForwardEntry(Object oKey)
Remove the forward index entry for the specified key.
|
protected void |
removeInverseMapping(Map mapIndex,
Object oIxValue,
Object oKey)
Remove the mapping from the given indexed value to the given key from
the supplied index.
|
protected void |
removeInverseMapping(Object oIxValue,
Object oKey)
Remove the mapping from the given indexed value to the given key from
the inverse index.
|
protected void |
removeInverseMapping(Object oIxValue,
Object oKey,
Collection colIgnore)
Remove the mapping from the given indexed value to the given key from
the inverse index.
|
void |
setOptimizeMV(boolean fOptimizeMV)
For an indexed value that is a multi-value (Collection or array) this flag
specifies whether an attempt should be made to search the forward map
for an existing reference that is "equal" to the specified mutli-value
and use it instead (if available) to reduce the index memory footprint.
|
protected void |
setUnits(long cUnits)
Set the size of this index in units (as defined by the
UnitCalculator ). |
String |
toString()
Returns a string representation of this SimpleMapIndex.
|
String |
toString(boolean fVerbose)
Returns a string representation of this SimpleMapIndex.
|
void |
update(Map.Entry entry)
Update this index in response to an update operation on a cache.
|
protected void |
updateExcludedKeys(Map.Entry entry,
boolean fExclude)
Check the entry against the set of entries not included in the index and
update the set if necessary.
|
protected void |
updateInternal(Map.Entry entry)
Update this index in response to an update operation on a cache.
|
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
protected ValueExtractor m_extractor
protected Comparator m_comparator
protected boolean m_fOrdered
protected Map m_mapForward
protected Map m_mapInverse
protected boolean m_fSplitCollection
protected volatile long m_cUnits
protected ConfigurableCacheMap.UnitCalculator m_calculator
protected BackingMapContext m_ctx
context
associated with this index.protected long m_ldtLogMissingIdx
protected int m_cLogMissingIdx
protected Set m_setKeyExcluded
protected boolean m_fForwardIndex
protected boolean m_fImmutableValues
public SimpleMapIndex(ValueExtractor extractor, boolean fOrdered, Comparator comparator, BackingMapContext ctx)
extractor
- the ValueExtractor that is used to extract an indexed
value from a resource map entryfOrdered
- true iff the contents of the indexed information
should be ordered; false otherwisecomparator
- the Comparator object which imposes an ordering
on entries in the index map; or null
if the entries' values natural ordering should be usedctx
- the context
associated with
the indexed cacheprotected SimpleMapIndex(ValueExtractor extractor, boolean fOrdered, Comparator comparator, boolean fInit, BackingMapContext ctx)
extractor
- the ValueExtractor that is used to extract an indexed
value from a resource map entryfOrdered
- true iff the contents of the indexed information
should be ordered; false otherwisecomparator
- the Comparator object which imposes an ordering
on entries in the index map; or null
if the entries' values natural ordering should be usedfInit
- initialize the index if truectx
- the context
associated with
the indexed cachepublic ValueExtractor getValueExtractor()
getValueExtractor
in interface MapIndex
public boolean isOrdered()
public boolean isPartial()
IndexAwareFilter
implementations to
determine the most optimal way to apply the index.
Note: Queries that use a partial index are allowed not to return entries that are not indexed even though they would match the corresponding filter were they evaluated during the full scan (if there were no index). However, it's not allowable for a query to return entries that do not match the corresponding filter, regardless of their presence in the index.
public Comparator getComparator()
getComparator
in interface MapIndex
public Map getIndexContents()
The keys of the Map are the return values from the ValueExtractor operating against the indexed Map's values, and for each key, the corresponding value stored in the Map is a Set of keys to the indexed Map.
If the MapIndex is known to be ordered, then the returned Map object
will be an instance of SortedMap
. The SortedMap may or may
not have a Comparator
object associated with it; see
SortedMap.comparator()
.
A client should assume that the returned Map object is read-only and must not attempt to modify it.
getIndexContents
in interface MapIndex
public Object get(Object oKey)
get
in interface MapIndex
oKey
- the key that specifies the object to extract the value frompublic void insert(Map.Entry entry)
public void update(Map.Entry entry)
public void delete(Map.Entry entry)
public boolean isOptimizeMV()
public void setOptimizeMV(boolean fOptimizeMV)
Note, that even if this optimization is allowed, the full search could be quite expensive and our algorithm will always limit the number of cycles it spends on the search.
fOptimizeMV
- the boolean value to setpublic long getUnits()
UnitCalculator
).protected void setUnits(long cUnits)
UnitCalculator
).cUnits
- new index sizepublic ConfigurableCacheMap.UnitCalculator getCalculator()
public boolean isForwardIndexSupported()
protected void initialize(boolean fForwardIndex)
fForwardIndex
- specifies whether or not this index supports a
forward mapprotected Map.Entry getForwardEntry(Object oKey)
oKey
- the keyprotected void addForwardEntry(Object oKey, Object oIxValueNew)
oKey
- the key to add to the mappingoIxValueNew
- the new value to add to the mappingprotected void removeForwardEntry(Object oKey)
oKey
- the key to remove the forward index entry forprotected Object extractNewValue(Map.Entry entry)
entry
- the entry to extract the "new" value fromprotected Object extractOldValue(MapTrigger.Entry entry)
entry
- the entry to extract the "old" value fromprotected Collection ensureCollection(Object oValue)
oValue
- the valueprotected Map instantiateForwardIndex()
Note: To optimize the memory footprint of the forward index, any
subclasses of the SimpleMapIndex that override this method must also
implement the getForwardEntry(Object)
method accordingly.
protected Map instantiateInverseIndex(boolean fOrdered, Comparator comparator)
fOrdered
- true iff the contents of the indexed information
should be ordered; false otherwisecomparator
- the Comparator object which imposes an ordering
on entries in the index map; or null
if the entries' values natural ordering should be
usedprotected void insertInternal(Map.Entry entry)
entry
- the entry representing the object being insertedprotected void updateInternal(Map.Entry entry)
entry
- the entry representing the object being updatedprotected void deleteInternal(Map.Entry entry)
entry
- the entry representing the object being removedprotected Object addInverseMapping(Object oIxValue, Object oKey)
oIxValue
- the indexed value (serves as a key in the inverse index)oKey
- the key to insert into the inverse indexprotected Object addInverseMapping(Map mapIndex, Object oIxValue, Object oKey)
mapIndex
- the index to which to add the mappingoIxValue
- the indexed value (serves as a key in the inverse index)oKey
- the key to insert into the inverse indexprotected Object addInverseCollectionMapping(Map mapIndex, Object oIxValue, Object oKey)
mapIndex
- the index to which to add the mappingoIxValue
- the indexed Collection value (each element serves
as a key in the inverse index)oKey
- the key to insert into the inverse indexprotected void removeInverseMapping(Object oIxValue, Object oKey, Collection colIgnore)
oIxValue
- the indexed value, or NO_VALUE if unknownoKey
- the keycolIgnore
- the Collection of values to ignore (exclude from removal), or nullprotected void removeInverseMapping(Object oIxValue, Object oKey)
oIxValue
- the indexed value, or NO_VALUE if unknownoKey
- the keyprotected void removeInverseMapping(Map mapIndex, Object oIxValue, Object oKey)
mapIndex
- the index from which to remove the mappingoIxValue
- the indexed valueoKey
- the keyprotected void logMissingIdx(Object oIxValue, Object oKey)
oIxValue
- the indexed valueoKey
- the keyprotected Set collectRemoved(Object oIxValueOld, Object oIxValueNew)
oIxValueOld
- the old value (must be a collection or an array)oIxValueNew
- the new valueprotected Set instantiateSet()
protected ConfigurableCacheMap.UnitCalculator instantiateCalculator()
ConfigurableCacheMap.UnitCalculator
protected void onMappingRemoved()
protected void onMappingRemoved(Object oValue)
oValue
- the value being removed from the indexprotected void onMappingAdded()
protected void onMappingAdded(Object oValue, int cSize)
oValue
- the value being added to the indexcSize
- the current key set size indexed by the given valueprotected void updateExcludedKeys(Map.Entry entry, boolean fExclude)
entry
- the entry to be checkedfExclude
- true iff the insert or update of the entry into the index
caused an exceptionprotected boolean isKeyExcluded(Object oKey)
oKey
- the key to testpublic String toString()
public String toString(boolean fVerbose)
fVerbose
- if true then print the content of the index otherwise
print the number of entriespublic boolean equals(Object o)