Package com.tangosol.util
Class ObservableHashMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- com.tangosol.util.SafeHashMap<K,V>
-
- com.tangosol.util.ObservableHashMap<K,V>
-
- All Implemented Interfaces:
ObservableMap<K,V>
,Serializable
,Cloneable
,Map<K,V>
public class ObservableHashMap<K,V> extends SafeHashMap<K,V> implements ObservableMap<K,V>
An ObservableMap implementation that extends the SafeHashMap.This Map implements the ObservableMap interface, meaning it provides event notifications to any interested listener for each insert, update and delete.
- Author:
- cp 2002.02.12
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ObservableHashMap.Entry<K,V>
A holder for a cached value.-
Nested classes/interfaces inherited from class com.tangosol.util.SafeHashMap
SafeHashMap.EntrySet, SafeHashMap.KeySet, SafeHashMap.ValuesCollection
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description protected MapListenerSupport
m_listenerSupport
The MapListenerSupport object.-
Fields inherited from class com.tangosol.util.SafeHashMap
BIGGEST_MODULO, DEFAULT_GROWTHRATE, DEFAULT_INITIALSIZE, DEFAULT_LOADFACTOR, m_aeBucket, m_cCapacity, m_cEntries, m_colValues, m_flGrowthRate, m_flLoadFactor, m_oIterActive, m_setEntries, m_setKeys, RESIZING
-
-
Constructor Summary
Constructors Constructor Description ObservableHashMap()
Construct the ObservableHashMap.ObservableHashMap(int cInitialBuckets, float flLoadFactor, float flGrowthRate)
Construct an ObservableHashMap using the specified settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMapListener(MapListener 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 key, boolean fLite)
Add a map listener for a specific key.void
clear()
Remove everything from the cache, notifying any registered listeners.protected void
clear(boolean fTruncate)
protected void
dispatchEvent(MapEvent evt)
Dispatch the passed event.protected MapListenerSupport
getMapListenerSupport()
Accessor for the MapListenerSupport for sub-classes.protected boolean
hasListeners()
Determine if the OverflowMap has any listeners at all.protected SafeHashMap.Entry<K,V>
instantiateEntry()
Factory method.V
put(K key, V value)
Store a value in the cache.V
remove(Object oKey)
Remove an entry from the cache.void
removeMapListener(MapListener 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 key)
Remove a map listener that previously signed up for events about a specific key.void
truncate()
Removes all mappings from this map.-
Methods inherited from class com.tangosol.util.SafeHashMap
clone, cloneEntryList, containsKey, entrySet, get, getBucketIndex, getEntry, getEntryInternal, getStableBucketArray, grow, instantiateEntry, instantiateEntrySet, instantiateKeySet, instantiateValuesCollection, isActiveIterator, isEmpty, iteratorActivated, iteratorDeactivated, keySet, removeEntryInternal, size, values
-
Methods inherited from class java.util.AbstractMap
containsValue, equals, hashCode, putAll, toString
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, size, values
-
-
-
-
Field Detail
-
m_listenerSupport
protected transient MapListenerSupport m_listenerSupport
The MapListenerSupport object.
-
-
Constructor Detail
-
ObservableHashMap
public ObservableHashMap()
Construct the ObservableHashMap.
-
ObservableHashMap
public ObservableHashMap(int cInitialBuckets, float flLoadFactor, float flGrowthRate)
Construct an ObservableHashMap using the specified settings.- Parameters:
cInitialBuckets
- the initial number of hash buckets, 0 < nflLoadFactor
- the acceptable load factor before resizing occurs, 0 < n, such that a load factor of 1.0 causes resizing when the number of entries exceeds the number of bucketsflGrowthRate
- the rate of bucket growth when a resize occurs, 0 < n, such that a growth rate of 1.0 will double the number of buckets: bucketCount = bucketCount * (1 + growthRate)
-
-
Method Detail
-
clear
public void clear()
Remove everything from the cache, notifying any registered listeners.
-
addMapListener
public void addMapListener(MapListener listener)
Description copied from interface:ObservableMap
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. This has the same result as the following call:addMapListener(listener, (Filter) null, false);
- Specified by:
addMapListener
in interfaceObservableMap<K,V>
- Parameters:
listener
- theMapEvent
listener to add
-
removeMapListener
public void removeMapListener(MapListener listener)
Description copied from interface:ObservableMap
Remove a standard map listener that previously signed up for all events. This has the same result as the following call:removeMapListener(listener, (Filter) null);
- Specified by:
removeMapListener
in interfaceObservableMap<K,V>
- Parameters:
listener
- the listener to remove
-
addMapListener
public void addMapListener(MapListener<? super K,? super V> listener, K key, boolean fLite)
Description copied from interface:ObservableMap
Add a map listener for a specific key.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.- Specified by:
addMapListener
in interfaceObservableMap<K,V>
- Parameters:
listener
- theMapEvent
listener to addkey
- the key that identifies the entry for which to raise eventsfLite
- true to indicate that theMapEvent
objects do not have to include the OldValue and NewValue property values in order to allow optimizations
-
removeMapListener
public void removeMapListener(MapListener<? super K,? super V> listener, K key)
Description copied from interface:ObservableMap
Remove a map listener that previously signed up for events about a specific key.- Specified by:
removeMapListener
in interfaceObservableMap<K,V>
- Parameters:
listener
- the listener to removekey
- the key that identifies the entry for which to raise events
-
addMapListener
public void addMapListener(MapListener<? super K,? super V> listener, Filter filter, boolean fLite)
Description copied from interface:ObservableMap
Add a map listener that receives events based on a filter evaluation.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.- Specified by:
addMapListener
in interfaceObservableMap<K,V>
- Parameters:
listener
- theMapEvent
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 (seeMapEventFilter
); null is equivalent to a filter that alway returns truefLite
- true to indicate that theMapEvent
objects do not have to include the OldValue and NewValue property values in order to allow optimizations
-
removeMapListener
public void removeMapListener(MapListener<? super K,? super V> listener, Filter filter)
Description copied from interface:ObservableMap
Remove a map listener that previously signed up for events based on a filter evaluation.- Specified by:
removeMapListener
in interfaceObservableMap<K,V>
- Parameters:
listener
- the listener to removefilter
- the filter that was passed into the corresponding addMapListener() call
-
truncate
public void truncate()
Removes all mappings from this map. Note: the removal of entries caused by this truncate operation will not be observable.- Since:
- 12.2.1.4
-
getMapListenerSupport
protected MapListenerSupport getMapListenerSupport()
Accessor for the MapListenerSupport for sub-classes.- Returns:
- the MapListenerSupport, or null if there are no listeners
-
hasListeners
protected boolean hasListeners()
Determine if the OverflowMap has any listeners at all.- Returns:
- true iff this OverflowMap has at least one MapListener
-
dispatchEvent
protected void dispatchEvent(MapEvent evt)
Dispatch the passed event.- Parameters:
evt
- a CacheEvent object
-
instantiateEntry
protected SafeHashMap.Entry<K,V> instantiateEntry()
Factory method. This method exists to allow the Cache class to be easily inherited from by allowing the Entry class to be easily sub-classed.- Overrides:
instantiateEntry
in classSafeHashMap<K,V>
- Returns:
- an instance of Entry that holds the passed cache value
-
clear
protected void clear(boolean fTruncate)
-
-