Class ContinuousQueryCache<K,V>
java.lang.Object
com.loomcache.server.datastructures.ContinuousQueryCache<K,V>
- Type Parameters:
K- the key typeV- the value type
- All Implemented Interfaces:
DistributedMap.MapChangeListener<K,V>
public class ContinuousQueryCache<K,V>
extends Object
implements DistributedMap.MapChangeListener<K,V>
Continuous Query Cache — a server-side filtered view of a
DistributedMap
that auto-updates via map change events.
On creation, the CQC scans the source map and populates an in-memory view
with all entries matching the predicate. It then registers as a
DistributedMap.MapChangeListener to receive live updates:
- New entries matching the predicate are added to the view
- Updated entries are re-evaluated: added, updated, or removed from the view
- Removed/evicted/expired entries are removed from the view
- Map clear empties the view
The view is read-only — all writes go through the source map.
Call destroy() to deregister the listener and release resources.
Thread safety: The view uses ConcurrentHashMap; listener dispatch uses CopyOnWriteArrayList. All operations are safe for concurrent access.
- Since:
- 1.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceListener for changes to the CQC filtered view.static final recordSnapshot of CQC statistics. -
Constructor Summary
ConstructorsConstructorDescriptionContinuousQueryCache(String name, int instanceNumber, DistributedMap<K, V> sourceMap, MapPredicate<K, V> predicate) Create a CQC on the given map with the specified filter predicate. -
Method Summary
Modifier and TypeMethodDescriptionaddEntryListener(ContinuousQueryCache.CqcListener<K, V> listener) Add a listener for changes to the CQC view.booleancontainsKey(K key) Check if a key exists in the filtered view.booleancontainsValue(V value) Check if a value exists in the filtered view.voiddestroy()Deregister from the source map and release resources.@Nullable VGet a value from the filtered view.getAll()Get an unmodifiable snapshot of all entries in the filtered view.longlongThe name of the source map this CQC is derived from.Get a snapshot of CQC statistics.longbooleanisEmpty()Check if the filtered view is empty.keySet()Get an unmodifiable set of keys in the filtered view.voidonEntryAdded(String mapName, K key, V value) voidonEntryEvicted(String mapName, K key, V value) Called when an entry is evicted by memory pressure or eviction policy (LRU/LFU/FIFO/RANDOM).voidonEntryExpired(String mapName, K key, V value) Called when an entry expires due to TTL (time-to-live).voidonEntryRemoved(String mapName, K key, V oldValue) voidonEntryUpdated(String mapName, K key, @Nullable V oldValue, V newValue) voidonMapCleared(String mapName) Called when the entire map is cleared viaDistributedMap.clear().booleanremoveEntryListener(ContinuousQueryCache.CqcListener<K, V> listener) Remove a CQC listener.intsize()Get the number of entries in the filtered view.values()Get an unmodifiable collection of values in the filtered view.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DistributedMap.MapChangeListener
onEntryLoaded, onEntryMerged
-
Constructor Details
-
ContinuousQueryCache
public ContinuousQueryCache(String name, int instanceNumber, DistributedMap<K, V> sourceMap, MapPredicate<K, V> predicate) Create a CQC on the given map with the specified filter predicate.Registers as a listener first, then scans existing entries, ensuring no entries are missed due to concurrent mutations.
- Parameters:
name- the CQC name for identificationinstanceNumber- the node instance number for loggingsourceMap- the map to create a filtered view ofpredicate- the filter predicate (entries matching this are included)
-
-
Method Details
-
get
-
containsKey
Check if a key exists in the filtered view. -
containsValue
Check if a value exists in the filtered view. -
size
public int size()Get the number of entries in the filtered view. -
isEmpty
public boolean isEmpty()Check if the filtered view is empty. -
keySet
-
values
Get an unmodifiable collection of values in the filtered view. -
getAll
-
getSourceMapName
The name of the source map this CQC is derived from. -
addEntryListener
Add a listener for changes to the CQC view.- Parameters:
listener- the listener to register- Returns:
- a subscription ID for removal
-
removeEntryListener
Remove a CQC listener. -
destroy
public void destroy()Deregister from the source map and release resources. After this call, the view is frozen and no longer receives updates. -
getEventsProcessed
public long getEventsProcessed() -
getPredicateEvaluations
public long getPredicateEvaluations() -
getViewUpdates
public long getViewUpdates() -
getStatistics
Get a snapshot of CQC statistics. -
onEntryAdded
- Specified by:
onEntryAddedin interfaceDistributedMap.MapChangeListener<K,V>
-
onEntryUpdated
- Specified by:
onEntryUpdatedin interfaceDistributedMap.MapChangeListener<K,V>
-
onEntryRemoved
- Specified by:
onEntryRemovedin interfaceDistributedMap.MapChangeListener<K,V>
-
onEntryEvicted
Description copied from interface:DistributedMap.MapChangeListenerCalled when an entry is evicted by memory pressure or eviction policy (LRU/LFU/FIFO/RANDOM). Eviction is involuntary removal triggered by capacity limits, distinct from explicit removal.- Specified by:
onEntryEvictedin interfaceDistributedMap.MapChangeListener<K,V> - Parameters:
mapName- the map namekey- the evicted keyvalue- the evicted value
-
onEntryExpired
Description copied from interface:DistributedMap.MapChangeListenerCalled when an entry expires due to TTL (time-to-live). Expiration is involuntary removal triggered by time, distinct from explicit removal.- Specified by:
onEntryExpiredin interfaceDistributedMap.MapChangeListener<K,V> - Parameters:
mapName- the map namekey- the expired keyvalue- the expired value
-
onMapCleared
Description copied from interface:DistributedMap.MapChangeListenerCalled when the entire map is cleared viaDistributedMap.clear(). Fired once per clear operation, not per entry.- Specified by:
onMapClearedin interfaceDistributedMap.MapChangeListener<K,V> - Parameters:
mapName- the map name
-