Class CqcSubscriptionHandler
java.lang.Object
com.loomcache.server.handler.CqcSubscriptionHandler
Server-side handler for the CQC (Continuous Query Cache) wire protocol.
Clients send MessageType.CQC_SUBSCRIBE with a SerializablePredicate
encoded in the message value; this handler registers a
DistributedMap.MapChangeListener on the target map that evaluates the predicate
server-side. Matched events are pushed back to the client as
MessageType.CQC_EVENT messages; non-matching events are silently dropped,
saving bandwidth compared to the legacy
MessageType.LISTENER_EVENT fan-out-then-client-filter path.
Lifecycle
- CQC_SUBSCRIBE: register/replace the listener for (peerId, mapName) and respond OK.
- CQC_UNSUBSCRIBE: deregister the listener and respond OK.
- Client disconnect:
onPeerDisconnect(String)tears down all subscriptions for the peer.
Event wire format
CQC_EVENT is laid out like LISTENER_EVENT (for parity) with the map name inmapName, the key in key, and the value being:
[2-byte eventType len][eventType UTF-8][4-byte oldValue len][oldValue UTF-8][4-byte newValue len][newValue UTF-8]Null values are encoded with length
-1 and no payload bytes.
Thread safety
Subscription state uses concurrent collections; listener dispatch happens on whatever thread mutated the map (same contract asDistributedEventListenerManager).- Since:
- 2.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordActive CQC subscription.static final recordComposite key identifying a single subscription. -
Constructor Summary
ConstructorsConstructorDescriptionCqcSubscriptionHandler(DataStructureRegistry registry, TcpServer tcpServer, int instanceNumber) -
Method Summary
Modifier and TypeMethodDescriptionintNumber of active subscriptions (observability only).Snapshot of active subscriptions, keyed by (peerId, mapName).Dispatch a CQC_SUBSCRIBE or CQC_UNSUBSCRIBE message from the given peer.static booleanisCqcOperation(@Nullable MessageType type) Returnstruefor message types this handler owns.voidonPeerDisconnect(String peerId) Remove all subscriptions for a disconnected peer.
-
Constructor Details
-
CqcSubscriptionHandler
public CqcSubscriptionHandler(DataStructureRegistry registry, TcpServer tcpServer, int instanceNumber)
-
-
Method Details
-
isCqcOperation
Returnstruefor message types this handler owns. -
handle
-
onPeerDisconnect
Remove all subscriptions for a disconnected peer. -
getActiveSubscriptionCount
public int getActiveSubscriptionCount()Number of active subscriptions (observability only). -
getSubscriptions
public Map<CqcSubscriptionHandler.SubscriptionId, CqcSubscriptionHandler.CqcSubscription> getSubscriptions()Snapshot of active subscriptions, keyed by (peerId, mapName). Exposed for tests.
-