public class WrapperObservableMap<K,V> extends AbstractKeySetBasedMap<K,V> implements ObservableMap<K,V>
Note: as of Coherence 3.0 the CacheStatistics implementation has to be
turned on explicitly by calling the setCollectStats(boolean)
method.
Note: if the underlying (wrapped) Map is an ObservableMap by itself,
as of Coherence 3.2 the WrapperObservableMap implementation does not
translate events generated the wrapped map by default. The translation can
be turned on explicitly by calling the setTranslateEvents(boolean)
method.
Modifier and Type | Class and Description |
---|---|
protected class |
WrapperObservableMap.InternalListener
An internal MapListener that listens to the wrapped map.
|
AbstractKeySetBasedMap.EntrySet, AbstractKeySetBasedMap.KeyIterator, AbstractKeySetBasedMap.KeySet, AbstractKeySetBasedMap.ValuesCollection
AbstractKeyBasedMap.DeferredCacheEvent<K,V>
Base.LoggingWriter, Base.StackFrame
Modifier and Type | Field and Description |
---|---|
protected boolean |
m_fDeferredEvent
Specifies whether or not fabricated events could be deferred.
|
protected boolean |
m_fTranslateEvents
Specifies whether or not events are translated by this wrapper.
|
protected MapListener<K,V> |
m_listenerInternal
The MapListener used to listen to the wrapped ObservableMap.
|
protected MapListenerSupport |
m_listenerSupport
The event listeners.
|
protected Map<K,V> |
m_map
The (wrapped) map containing all the resources.
|
protected SimpleCacheStatistics |
m_stats
The CacheStatistics object maintained by this wrapper.
|
Constructor and Description |
---|
WrapperObservableMap(Map<K,V> map)
Construct an ObservableMap wrapper based on the specified map.
|
WrapperObservableMap(Map<K,V> map,
boolean fDeferredEvent)
Construct an ObservableMap wrapper based on the specified map.
|
Modifier and Type | Method and Description |
---|---|
void |
addMapListener(MapListener<? super K,? super V> 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.
|
void |
addMapListener(MapListener<? super K,? super V> listener,
Filter filter,
boolean fLite)
Add a map listener that receives events based on a filter evaluation.
|
void |
addMapListener(MapListener<? super K,? super V> listener,
K oKey,
boolean fLite)
Add a map listener for a specific key.
|
void |
clear()
Clear all key/value mappings.
|
boolean |
containsValue(Object oValue)
Returns true if this Map maps one or more keys to the
specified value.
|
protected void |
dispatchEvent(MapEvent<? extends K,? extends V> evt)
Dispatch the passed event.
|
protected void |
dispatchPendingEvent(K oKey,
int nId,
V oNewValue,
boolean fSynthetic)
Dispatch an event that has not yet occurred, allowing the cache to
potentially avoid reading of the "original value" information.
|
protected MapListener<K,V> |
ensureInternalListener()
Obtain the internal MapListener, creating one if necessary.
|
protected MapListenerSupport |
ensureMapListenerSupport()
Obtain the MapListenerSupport, creating it if necessary.
|
boolean |
equals(Object o)
Compares the specified object with this map for equality.
|
V |
get(Object oKey)
Returns the value to which this map maps the specified key.
|
CacheStatistics |
getCacheStatistics()
Return the CacheStatistics for this cache.
|
protected String |
getDescription()
Assemble a human-readable description.
|
protected Set<K> |
getInternalKeySet()
Obtain a set of keys that are represented by this Map.
|
Map<K,V> |
getMap()
Get the Map that is wrapped by this wrapper.
|
protected MapListenerSupport |
getMapListenerSupport()
Accessor for the MapListenerSupport for sub-classes.
|
int |
hashCode()
Returns the hash code value for this Map.
|
protected boolean |
hasListeners()
Determine if the OverflowMap has any listeners at all.
|
protected MapListener<K,V> |
instantiateInternalListener()
Instantiate a MapListener to listen to the wrapped map.
|
boolean |
isCollectStats()
Check whether or not statistics are collected by the wrapper.
|
protected boolean |
isEventFabricator()
Determine if this ObservableMap has to fabricate events itself.
|
protected boolean |
isInternalKeySetIteratorMutable()
Determine if this Iterator should remove an iterated item by calling
remove on the internal key Set Iterator, or by calling removeBlind on
the map itself.
|
protected static <K,V> boolean |
isSynthetic(MapEvent<K,V> evt)
Helper method to determine if an event is synthetic.
|
boolean |
isTranslateEvents()
Check whether or not an event source has to be translated by the wrapper.
|
V |
put(K oKey,
V oValue)
Associates the specified value with the specified key in this map.
|
void |
putAll(Map<? extends K,? extends V> map)
Copies all of the mappings from the specified map to this map.
|
V |
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.
|
void |
removeMapListener(MapListener<? super K,? super V> listener)
Remove a standard map listener that previously signed up for all
events.
|
void |
removeMapListener(MapListener<? super K,? super V> listener,
Filter filter)
Remove a map listener that previously signed up for events based on a
filter evaluation.
|
void |
removeMapListener(MapListener<? super K,? super V> listener,
K oKey)
Remove a map listener that previously signed up for events about a
specific key.
|
void |
setCollectStats(boolean fCollectStats)
Specify whether or not statistics are to be collected by the wrapper.
|
void |
setTranslateEvents(boolean fTranslate)
Specify whether or not an event source has to be translated by the
wrapper.
|
String |
toString()
Returns a string representation of this Map.
|
containsKey, instantiateEntrySet, instantiateKeyIterator, instantiateKeySet, instantiateValues, isEmpty, iterateKeys, size
clone, entrySet, getAll, keySet, 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, containsKey, entrySet, forEach, getOrDefault, isEmpty, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll, size, values
protected MapListenerSupport m_listenerSupport
protected MapListener<K,V> m_listenerInternal
protected SimpleCacheStatistics m_stats
protected boolean m_fTranslateEvents
protected boolean m_fDeferredEvent
public WrapperObservableMap(Map<K,V> map)
Note: it is assumed that while the WrapperObservableMap exists, the contents of the underlying wrapped map are not directly manipulated.
map
- the Map that will be wrapped by this WrapperObservableMappublic WrapperObservableMap(Map<K,V> map, boolean fDeferredEvent)
Note: it is assumed that while the WrapperObservableMap exists, the contents of the underlying wrapped map are not directly manipulated.
map
- the Map that will be wrapped by this WrapperObservableMapfDeferredEvent
- true iff if the value contained in the fabricated
cache events could be lazily populated. Deferred
events should only be raised to listeners that will
process events synchronouslypublic void clear()
public boolean containsValue(Object oValue)
containsValue
in interface Map<K,V>
containsValue
in class AbstractKeyBasedMap<K,V>
public V put(K oKey, V oValue)
put
in interface Map<K,V>
put
in class AbstractKeyBasedMap<K,V>
oKey
- key with which the specified value is to be associatedoValue
- value to be associated with the specified keypublic void putAll(Map<? extends K,? extends V> map)
AbstractKeyBasedMap.put(K, V)
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.public V remove(Object oKey)
remove
in interface Map<K,V>
remove
in class AbstractKeyBasedMap<K,V>
oKey
- key whose mapping is to be removed from the mapprotected Set<K> getInternalKeySet()
The AbstractKeySetBasedMap only utilizes the internal key set as a read-only resource.
getInternalKeySet
in class AbstractKeySetBasedMap<K,V>
protected boolean isInternalKeySetIteratorMutable()
isInternalKeySetIteratorMutable
in class AbstractKeySetBasedMap<K,V>
AbstractKeyBasedMap.removeBlind(Object)
methodprotected boolean removeBlind(Object oKey)
removeBlind
in class AbstractKeyBasedMap<K,V>
oKey
- key whose mapping is to be removed from the mappublic void addMapListener(MapListener<? super K,? super V> listener)
addMapListener(listener, (Filter) null, false);
addMapListener
in interface ObservableMap<K,V>
listener
- the MapEvent
listener to addpublic void removeMapListener(MapListener<? super K,? super V> listener)
removeMapListener(listener, (Filter) null);
removeMapListener
in interface ObservableMap<K,V>
listener
- the listener to removepublic void addMapListener(MapListener<? super K,? super V> listener, K oKey, boolean fLite)
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.
addMapListener
in interface ObservableMap<K,V>
listener
- the MapEvent
listener to addoKey
- the key that identifies the entry for which to raise
eventsfLite
- true to indicate that the MapEvent
objects do
not have to include the OldValue and NewValue
property values in order to allow optimizationspublic void removeMapListener(MapListener<? super K,? super V> listener, K oKey)
removeMapListener
in interface ObservableMap<K,V>
listener
- the listener to removeoKey
- the key that identifies the entry for which to raise
eventspublic void addMapListener(MapListener<? super K,? super V> listener, Filter filter, boolean fLite)
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.
addMapListener
in interface ObservableMap<K,V>
listener
- the MapEvent
listener to addfilter
- 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 truefLite
- true to indicate that the MapEvent
objects do
not have to include the OldValue and NewValue
property values in order to allow optimizationspublic void removeMapListener(MapListener<? super K,? super V> listener, Filter filter)
removeMapListener
in interface ObservableMap<K,V>
listener
- the listener to removefilter
- the filter that was passed into the corresponding
addMapListener() callpublic Map<K,V> getMap()
Note: direct modifications of the returned map may cause an unpredictable behavior of the wrapper map.
public CacheStatistics getCacheStatistics()
public boolean isCollectStats()
public void setCollectStats(boolean fCollectStats)
fCollectStats
- true if this wrapper should collect cache
statistics; false otherwisepublic boolean isTranslateEvents()
Note: this setting is only meaningful if the underlying map is an ObservableMap itself.
public void setTranslateEvents(boolean fTranslate)
Note: this setting is only meaningful if the underlying map is an ObservableMap itself.
fTranslate
- true if this wrapper should translate an event
source; false otherwiseprotected String getDescription()
public String toString()
toString
in class AbstractKeyBasedMap<K,V>
protected MapListenerSupport getMapListenerSupport()
protected MapListenerSupport ensureMapListenerSupport()
protected boolean hasListeners()
protected boolean isEventFabricator()
protected static <K,V> boolean isSynthetic(MapEvent<K,V> evt)
K
- the key typeV
- the value typeevt
- a Map Eventprotected void dispatchPendingEvent(K oKey, int nId, V oNewValue, boolean fSynthetic)
oKey
- the key which the event is related tonId
- the event IDoNewValue
- the new valuefSynthetic
- true if the event is syntheticprotected void dispatchEvent(MapEvent<? extends K,? extends V> evt)
evt
- a CacheEvent objectpublic int hashCode()
AbstractKeyBasedMap
public boolean equals(Object o)
AbstractKeyBasedMap
protected MapListener<K,V> ensureInternalListener()
protected MapListener<K,V> instantiateInternalListener()