Class LoomQueryCache<K,V>
- Type Parameters:
K- the key type (must round-trip throughClientSerializer)V- the value type (must round-trip throughClientSerializer)
- All Implemented Interfaces:
AutoCloseable
LoomMap.
Relationship to the server-side ContinuousQueryCache
The server-side ContinuousQueryCache is an in-process view maintained on a
single node. There is no wire message to subscribe a remote client to it, and the
existing MapChangeListener wire protocol delivers serialized String
key/value pairs only. Consequently, this client proxy implements its own filtered
view backed by the existing listener push channel plus an initial seed scan. The
predicate is evaluated client-side against deserialized values; no
predicate is shipped to the server. This keeps the v2.0 surface additive — no new
MessageType entries are required — while giving client callers the same
CQC-style API as the server-side class.
Lifecycle
create(LoomClient, String, BiPredicate, Class, Class)registers aLoomClient.MapChangeListener(via the existingregisterMapListener), then seeds the view by scanning the source map. Events delivered between registration and seed completion are recorded inbootstrapDirtyKeysso the scan does not overwrite newer values.- Live mutations are evaluated against
predicate: matching entries are inserted or updated in the local view; non-matching entries are removed. close()deregisters the listener and freezes the view.
Thread safety
The backing view is aConcurrentHashMap; listener dispatch uses
CopyOnWriteArrayList. All public methods are safe for concurrent use.- Since:
- 2.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceListener for changes applied to the locally cached view.static final recordSnapshot of this query cache's observability counters. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(LoomQueryCache.CQCListener<K, V> listener) Register a listener for view-level change notifications.voidclose()Deregister from the server and freeze the view.booleancontainsKey(K key) True if the locally cached view contains the given key.static <K,V> LoomQueryCache <K, V> create(LoomClient client, String sourceMapName, BiPredicate<K, V> predicate, Class<K> keyType, Class<V> valueType) Create a client-side continuous query cache over the named map.static <K,V> LoomQueryCache <K, V> createServerFiltered(LoomClient client, String sourceMapName, SerializablePredicate serverPredicate, Class<K> keyType, Class<V> valueType) Create a client-side continuous query cache with server-side predicate evaluation.@Nullable VLook up a key in the locally cached view.booleanisActive()True while this proxy is actively receiving events from the server.booleanisEmpty()True if the locally cached view has no entries.keySet()Unmodifiable view of current keys.booleanremoveListener(LoomQueryCache.CQCListener<K, V> listener) Remove a previously registered listener.intsize()Number of entries in the locally cached view.snapshot()Immutable snapshot of the current view.values()Unmodifiable view of current values.
-
Method Details
-
create
public static <K,V> LoomQueryCache<K,V> create(LoomClient client, String sourceMapName, BiPredicate<K, V> predicate, Class<K> keyType, Class<V> valueType) Create a client-side continuous query cache over the named map.The predicate is evaluated client-side after deserializing every incoming event payload via
ClientSerializer. Entries whose deserialized type does not matchkeyType/valueTypeare ignored (and counted againstpredicateEvaluations).- Type Parameters:
K- key typeV- value type- Parameters:
client- connected LoomClient (must be connected before calling)sourceMapName- name of the distributed map to observepredicate- client-side filter predicate (non-null)keyType- runtimeClassforKvalueType- runtimeClassforV- Returns:
- an active LoomQueryCache; call
close()to tear it down - Throws:
LoomException- if listener registration fails
-
createServerFiltered
public static <K,V> LoomQueryCache<K,V> createServerFiltered(LoomClient client, String sourceMapName, SerializablePredicate serverPredicate, Class<K> keyType, Class<V> valueType) Create a client-side continuous query cache with server-side predicate evaluation.Unlike
create(LoomClient, String, BiPredicate, Class, Class), the suppliedSerializablePredicateis shipped over the wire viaMessageType.CQC_SUBSCRIBEand evaluated server-side. Only entries matching the predicate are pushed back to this client asCQC_EVENTmessages — non-matching mutations never traverse the wire, saving bandwidth on large maps.Client-side events are delivered through the same
LoomClient.MapChangeListeneradapter used by the legacy client-filter path, so event handling and the local view semantics are identical. Because the predicate has already been evaluated server-side, the client-sideBiPredicatedegrades to(k, v) -> true.- Type Parameters:
K- key typeV- value type- Parameters:
client- connected LoomClientsourceMapName- source map name (non-blank)serverPredicate- the wire-serializable predicate to evaluate server-sidekeyType- runtimeClassforKvalueType- runtimeClassforV- Returns:
- an active LoomQueryCache; call
close()to tear it down - Throws:
LoomException- if CQC registration fails on every connected node- Since:
- 2.0
-
get
-
containsKey
True if the locally cached view contains the given key. -
size
public int size()Number of entries in the locally cached view. -
isEmpty
public boolean isEmpty()True if the locally cached view has no entries. -
snapshot
-
keySet
-
values
Unmodifiable view of current values. -
isActive
public boolean isActive()True while this proxy is actively receiving events from the server. -
addListener
Register a listener for view-level change notifications.- Parameters:
listener- listener to add (non-null)
-
removeListener
Remove a previously registered listener.- Returns:
trueif the listener was present and removed
-
getStatistics
- Returns:
- snapshot of this query cache's observability counters
-
close
public void close()Deregister from the server and freeze the view. Idempotent.- Specified by:
closein interfaceAutoCloseable
-