Package com.tangosol.util
Class MapListenerSupport
java.lang.Object
com.tangosol.util.Base
com.tangosol.util.MapListenerSupport
This class provides support for advanced MapListener functionality.
- Since:
- Coherence 2.3
- Author:
- gg 2003.09.16
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
An extension of the CacheEvent which may carry no values (old or new), but instead holds on an array of Filter objects being the "cause" of the event.static interface
A tag interface indicating that this listener is registered as a synchronous listener for lite events (carrying only a key) and generates a "priming" event when registered.static interface
A tag interface indicating that tagged MapListener implementation has to receive the MapEvent notifications in a synchronous manner.static class
A base class for various wrapper listener classes.static class
A wrapper class that turns the specified MapListener into a priming listener.static class
A wrapper class that turns the specified MapListener into a synchronous listener.Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
Field Summary
Modifier and TypeFieldDescriptionprotected Listeners
A cached set of Listeners.protected Map
The collections of MapListener objects that have signed up for key based notifications from an ObservableMap implementation keyed by the corresponding key objects.protected Map
The collections of MapListener objects that have signed up for notifications from an ObservableMap implementation keyed by the corresponding Filter objects.protected Map
The subset of standard (not lite) key listeners.protected Map
The subset of standard (not lite) global listeners.protected int
The optimization plan which indicates the fastest way to put together a set of listeners.protected final Listeners
An empty set of Listeners.protected static final int
There is one all-keys non-filtered listener.protected static final int
There is one key listener (even if for multiple keys).protected static final int
There are no listeners.protected static final int
There is no optimized plan, so just use the default approach.protected static final int
A plan has not yet been formed. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(MapListener listener, Filter filter, boolean fLite) Add a map listener that receives events based on a filter evaluation.void
addListener
(MapListener listener, Object oKey, boolean fLite) Add a map listener for a specific key.void
addListener
(MapListener listener, Set setKey, boolean fLite) Add a map listener for a set of keys.protected static void
addListenerState
(Map mapStandardListeners, Object anyKey, MapListener listener, boolean fLite) Add a state information (lite or standard) associated with specified key and listener.boolean
addListenerWithCheck
(MapListener listener, Filter filter, boolean fLite) Add a map listener that receives events based on a filter evaluation.boolean
addListenerWithCheck
(MapListener listener, Object oKey, boolean fLite) Add a map listener for a specific key.void
addListenerWithCheck
(MapListener listener, Set setKey, boolean fLite) Add a map listener for a set of keys.protected static void
addSafeListener
(Map mapListeners, Filter anyFilter, MapListener listener) Ensure that the specified map has a Listeners object associated with the specified Filter and add the specified listener to it.protected static void
addSafeListener
(Map mapListeners, Object anyKey, MapListener listener) Ensure that the specified map has a Listeners object associated with the specified key and add the specified listener to it.void
clear()
Remove all signed up listeners.collectListeners
(MapEvent event) Collect all Listeners that should be notified for a given event.boolean
containsStandardListeners
(Filter filter) Checks whether or not this MapListenerSupport object contains any standard (not lite) listeners for a given filter.boolean
Checks whether or not this MapListenerSupport object contains any standard (not lite) listeners for a given key.static MapEvent
convertEvent
(MapEvent event, ObservableMap mapConv, Converter convKey, Converter convVal) Convert the specified map event into another MapEvent that ensures the lazy event data conversion using the specified converters.static MapEvent
enrichEvent
(MapEvent event, Listeners listeners) Transform the given MapEvent into a FilterEvent if it is not already a FilterEvent and there are matching filters associated with the specified Listeners object.protected boolean
evaluateEvent
(Filter filter, MapEvent event) Evaluate whether or not the specified event should be delivered to the listener associated with the specified filter.void
Fire the specified map event.Obtain a set of all filters that have associated global listeners.Obtain a set of all keys that have associated key listeners.int
Return the number of listeners registered.getListeners
(Filter filter) Obtain the Listeners object for a given filter.getListeners
(Object oKey) Obtain the Listeners object for a given key.protected static long
getMinVersion
(EventListener[] aListeners) Return a minimum version for the provided listeners.getMinVersions
(Filter filter) getMinVersions
(Object oKey) Return the minimumversions
for the provided key.protected static VersionedPartitions
getMinVersions
(EventListener[] aListeners) Return the minimum versions received for all partitions for the provided listeners.boolean
isEmpty()
Checks whether or not this MapListenerSupport object contains any listeners.boolean
Checks whether or not this MapListenerSupport object contains any listeners for a given filter.boolean
Checks whether or not this MapListenerSupport object contains any listeners for a given key.static boolean
isPrimingListener
(MapListener listener) Check if the given listener is a PrimingListener or if it wraps one.protected boolean
isTransformedEvent
(MapEvent event) Return true iff the specified event represents a transformed CacheEvent.protected boolean
isVersionAware
(MapListener listener) Return true if the provided listener is version aware.protected boolean
isVersionUpdate
(MapEvent event) Return true if the provided MapEvent is due to a synthetic version update.protected static VersionedPartitions
min
(VersionedPartitions versionsLHS, VersionedPartitions versionsRHS) Return the minimum versions for the provided two partition versioned data structures.void
removeListener
(MapListener listener, Filter filter) Remove a map listener that previously signed up for events based on a filter evaluation.void
removeListener
(MapListener listener, Object oKey) Remove a map listener that previously signed up for events about a specific key.void
removeListener
(MapListener listener, Set setKey) Remove a map listener that previously signed up for events about specific keys.protected static void
removeListenerState
(Map mapStandardListeners, Object anyKey, MapListener listener) Remove a state information (lite or standard) associated with specified key and listener.boolean
removeListenerWithCheck
(MapListener listener, Filter filter) Remove a map listener that previously signed up for events based on a filter evaluation.boolean
removeListenerWithCheck
(MapListener listener, Object oKey) Remove a map listener that previously signed up for events about a specific key.void
removeListenerWithCheck
(MapListener listener, Set setKey) Remove a map listener that previously signed up for events about specific keys.protected static void
removeSafeListener
(Map mapListeners, Object anyKey, MapListener listener) Remove the specified listener from the Listeners object associated with the specified key.toString()
Provide a string representation of the MapListenerSupport object.static <K,
V> MapListener <K, V> unwrap
(MapListener<K, V> listener) Return the inner MapListener skipping any wrapper listeners.static MapEvent
unwrapEvent
(MapEvent evt) Unwrap the specified map event and return the underlying source event.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
-
Field Details
-
PLAN_NONE
protected static final int PLAN_NONEA plan has not yet been formed.- See Also:
-
PLAN_NO_LISTENERS
protected static final int PLAN_NO_LISTENERSThere are no listeners.- See Also:
-
PLAN_ALL_LISTENER
protected static final int PLAN_ALL_LISTENERThere is one all-keys non-filtered listener.- See Also:
-
PLAN_KEY_LISTENER
protected static final int PLAN_KEY_LISTENERThere is one key listener (even if for multiple keys).- See Also:
-
PLAN_NO_OPTIMIZE
protected static final int PLAN_NO_OPTIMIZEThere is no optimized plan, so just use the default approach.- See Also:
-
NO_LISTENERS
An empty set of Listeners. Because this is a theoretically mutable object that is used as a return value, it is purposefully not static. -
m_mapListeners
The collections of MapListener objects that have signed up for notifications from an ObservableMap implementation keyed by the corresponding Filter objects. -
m_mapKeyListeners
The collections of MapListener objects that have signed up for key based notifications from an ObservableMap implementation keyed by the corresponding key objects. -
m_mapStandardListeners
The subset of standard (not lite) global listeners. The keys are the Filter objects, the values are sets of corresponding standard listeners. -
m_mapStandardKeyListeners
The subset of standard (not lite) key listeners. The keys are the key objects, the values are sets of corresponding standard listeners. -
m_nOptimizationPlan
protected int m_nOptimizationPlanThe optimization plan which indicates the fastest way to put together a set of listeners. -
m_listenersCached
A cached set of Listeners.
-
-
Constructor Details
-
MapListenerSupport
public MapListenerSupport()Constructs a new MapListenerSupport object.
-
-
Method Details
-
addListener
Add a map listener that receives events based on a filter evaluation.- Parameters:
listener
- the 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; null is equivalent to a filter that always returns truefLite
- true to indicate that the MapEvent objects do not have to include the OldValue and NewValue property values in order to allow optimizations
-
addListenerWithCheck
Add a map listener that receives events based on a filter evaluation.- Parameters:
listener
- the 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; null is equivalent to a filter that always returns truefLite
- true to indicate that the MapEvent objects do not have to include the OldValue and NewValue property values in order to allow optimizations- Returns:
- false iff there already existed a "covering" listener for that filter (either standard or lite for a lite call and standard otherwise)
-
addListener
Add a map listener for a specific key.- Parameters:
listener
- the listener to addoKey
- the key that identifies the entry for which to register the event listenerfLite
- true to indicate that the MapEvent objects do not have to include the OldValue and NewValue property values in order to allow optimizations
-
addListenerWithCheck
Add a map listener for a specific key.- Parameters:
listener
- the listener to addoKey
- the key that identifies the entry for which to register the event listenerfLite
- true to indicate that the MapEvent objects do not have to include the OldValue and NewValue property values in order to allow optimizations- Returns:
- false iff there already existed a "covering" listener for that key (either standard or lite for a lite call and standard otherwise)
-
addListener
Add a map listener for a set of keys.- Parameters:
listener
- the listener to addsetKey
- the key set for which to register the event listenerfLite
- true to indicate that the MapEvent objects do not have to include the OldValue and NewValue property values in order to allow optimizations
-
addListenerWithCheck
Add a map listener for a set of keys. This method will modify the passed set by removing the keys that already had existing "covering" listeners for them.- Parameters:
listener
- the listener to addsetKey
- the key set for which to register the event listenerfLite
- true to indicate that the MapEvent objects do not have to include the OldValue and NewValue property values in order to allow optimizations
-
removeListener
Remove a map listener that previously signed up for events based on a filter evaluation.- Parameters:
listener
- the listener to removefilter
- a filter used to evaluate events
-
removeListenerWithCheck
Remove a map listener that previously signed up for events based on a filter evaluation.- Parameters:
listener
- the listener to removefilter
- a filter used to evaluate events- Returns:
- true iff there are no longer any listeners for that filter
-
removeListener
Remove a map listener that previously signed up for events about a specific key.- Parameters:
listener
- the listener to removeoKey
- the key that identifies the entry for which to unregister the event listener
-
removeListenerWithCheck
Remove a map listener that previously signed up for events about a specific key.- Parameters:
listener
- the listener to removeoKey
- the key that identifies the entry for which to unregister the event listener- Returns:
- true iff there are no longer any listeners for that key
-
removeListener
Remove a map listener that previously signed up for events about specific keys.- Parameters:
listener
- the listener to removesetKey
- the set of keys for which to unregister the event listener
-
removeListenerWithCheck
Remove a map listener that previously signed up for events about specific keys. This method will modify the passed set by removing the keys that still have existing "covering" listeners for them, so the keys that are retained in the set no longer have any listeners for them.- Parameters:
listener
- the listener to removesetKey
- the set of keys for which to unregister the event listener
-
clear
public void clear()Remove all signed up listeners. -
isEmpty
public boolean isEmpty()Checks whether or not this MapListenerSupport object contains any listeners.- Returns:
- true iff there are no listeners encapsulated by this MapListenerSupport object
-
getListenerCount
public int getListenerCount()Return the number of listeners registered.- Returns:
- the number of listeners registered
-
isEmpty
Checks whether or not this MapListenerSupport object contains any listeners for a given filter.- Parameters:
filter
- the filter- Returns:
- true iff there are no listeners for the specified filter encapsulated by this MapListenerSupport object
-
isEmpty
Checks whether or not this MapListenerSupport object contains any listeners for a given key.- Parameters:
oKey
- the key- Returns:
- true iff there are no listeners for the specified filter encapsulated by this MapListenerSupport object
-
containsStandardListeners
Checks whether or not this MapListenerSupport object contains any standard (not lite) listeners for a given filter.- Parameters:
filter
- the filter- Returns:
- true iff there are no standard listeners for the specified filter encapsulated by this MapListenerSupport object
-
containsStandardListeners
Checks whether or not this MapListenerSupport object contains any standard (not lite) listeners for a given key.- Parameters:
oKey
- the key- Returns:
- true iff there are no standard listeners for the specified filter encapsulated by this MapListenerSupport object
-
getFilterSet
Obtain a set of all filters that have associated global listeners.Note: The returned value must be treated as an immutable.
- Returns:
- a set of all filters that have associated global listeners
-
getKeySet
Obtain a set of all keys that have associated key listeners.Note: The returned value must be treated as an immutable.
- Returns:
- a set of all keys that have associated key listeners
-
getListeners
Obtain the Listeners object for a given filter.Note: The returned value must be treated as an immutable.
- Parameters:
filter
- the filter- Returns:
- the Listeners object for the filter; null if none exists
-
getListeners
Obtain the Listeners object for a given key.Note: The returned value must be treated as an immutable.
- Parameters:
oKey
- the key- Returns:
- the Listeners object for the key; null if none exists
-
collectListeners
Collect all Listeners that should be notified for a given event.Note: The returned value must be treated as an immutable.
- Parameters:
event
- the MapEvent object- Returns:
- the Listeners object containing the relevant listeners
-
fireEvent
Fire the specified map event.- Parameters:
event
- the map eventfStrict
- if true then any RuntimeException thrown by event handlers stops all further event processing and the exception is re-thrown; if false then all exceptions are logged and the process continues
-
getMinVersions
-
getMinVersions
Return the minimumversions
for the provided key.- Parameters:
oKey
- the key the listeners were registered with- Returns:
- the minimum
versions
for the provided key
-
convertEvent
public static MapEvent convertEvent(MapEvent event, ObservableMap mapConv, Converter convKey, Converter convVal) Convert the specified map event into another MapEvent that ensures the lazy event data conversion using the specified converters.- Parameters:
event
- the map eventmapConv
- the source for the converted eventconvKey
- (optional) the key ConverterconvVal
- (optional) the value converter- Returns:
- the converted MapEvent object
-
enrichEvent
Transform the given MapEvent into a FilterEvent if it is not already a FilterEvent and there are matching filters associated with the specified Listeners object.- Parameters:
event
- the MapEvent to transform, if necessarylisteners
- the Listeners object- Returns:
- a FilterEvent if the given MapEvent is not a FilterEvent and the specified Listeners object has associated filters; otherwise, the given MapEvent
-
unwrapEvent
Unwrap the specified map event and return the underlying source event.- Parameters:
evt
- the event to unwrap- Returns:
- the unwrapped event
-
unwrap
Return the inner MapListener skipping any wrapper listeners.- Type Parameters:
K
- key type for the mapV
- value type for the map- Parameters:
listener
- the listener to check against- Returns:
- the inner MapListener skipping any wrapper listeners
-
isPrimingListener
Check if the given listener is a PrimingListener or if it wraps one.- Parameters:
listener
- Map listener to check- Returns:
- true iff the listener is a PrimingListener or wraps one
-
isVersionAware
Return true if the provided listener is version aware.- Parameters:
listener
- the listener to check- Returns:
- true if the provided listener is version aware
-
isVersionUpdate
Return true if the provided MapEvent is due to a synthetic version update.- Parameters:
event
- the event to test- Returns:
- true if the provided MapEvent is due to a synthetic version update
-
evaluateEvent
Evaluate whether or not the specified event should be delivered to the listener associated with the specified filter.- Parameters:
filter
- the filterevent
- the event- Returns:
- true iff the event should be delivered to the corresponding listener
-
isTransformedEvent
Return true iff the specified event represents a transformed CacheEvent.- Parameters:
event
- the event to test- Returns:
- true iff the event has been transformed
-
addSafeListener
Ensure that the specified map has a Listeners object associated with the specified key and add the specified listener to it. -
addSafeListener
Ensure that the specified map has a Listeners object associated with the specified Filter and add the specified listener to it. -
removeSafeListener
Remove the specified listener from the Listeners object associated with the specified key. -
addListenerState
protected static void addListenerState(Map mapStandardListeners, Object anyKey, MapListener listener, boolean fLite) Add a state information (lite or standard) associated with specified key and listener. -
removeListenerState
protected static void removeListenerState(Map mapStandardListeners, Object anyKey, MapListener listener) Remove a state information (lite or standard) associated with specified key and listener. -
getMinVersions
Return the minimum versions received for all partitions for the provided listeners.- Parameters:
aListeners
- the listeners to interrogate- Returns:
- the minimum versions received for all partitions for the provided listeners
-
min
protected static VersionedPartitions min(VersionedPartitions versionsLHS, VersionedPartitions versionsRHS) Return the minimum versions for the provided two partition versioned data structures.- Parameters:
versionsLHS
- the first partition versioned objectversionsRHS
- the second partition versioned object- Returns:
- the minimum versions for the provided two partition versioned data structures
-
getMinVersion
Return a minimum version for the provided listeners.- Parameters:
aListeners
- the listeners to interrogate- Returns:
- a minimum version for the provided listeners
-
toString
Provide a string representation of the MapListenerSupport object.
-