Class NearCacheInvalidationManager
Clients with near-caching enabled subscribe to map-level invalidation
events. When a key is modified (PUT, DELETE, CLEAR) on the server, this
manager broadcasts a MessageType.NEAR_CACHE_INVALIDATE message
to all subscribed clients so they can evict stale entries immediately
rather than waiting for TTL expiry.
Thread-safe: uses ConcurrentHashMap for tracking structures and
a shared lock to keep forward and reverse subscription indices consistent.
- Since:
- 1.3
-
Constructor Summary
ConstructorsConstructorDescriptionNearCacheInvalidationManager(TcpServer tcpServer) Initialize near-cache invalidation manager. -
Method Summary
Modifier and TypeMethodDescriptionvoidbroadcastInvalidation(String mapName, @Nullable String key) Broadcast an invalidation event to all clients subscribed to the given map.voidderegisterMap(String mapName) Remove all invalidation state for a map when the map is destroyed.longgetMapSequence(String mapName) Get the current sequence number for a map.intintGet a snapshot of all subscriptions for diagnostics.longlongvoidSubscribe a client to invalidation events for a specific map.voidunsubscribe(String peerId, String mapName) Unsubscribe a client from invalidation events for a specific map.voidunsubscribeAll(String peerId) Unsubscribe a client from all maps.
-
Constructor Details
-
NearCacheInvalidationManager
Initialize near-cache invalidation manager.- Parameters:
tcpServer- the TCP server for broadcasting messages (must not be null)
-
-
Method Details
-
subscribe
-
unsubscribe
-
unsubscribeAll
Unsubscribe a client from all maps. Called on connection close.- Parameters:
peerId- the disconnecting client's peer ID (must not be null)
-
deregisterMap
Remove all invalidation state for a map when the map is destroyed.- Parameters:
mapName- the destroyed map name (must not be null)
-
broadcastInvalidation
Broadcast an invalidation event to all clients subscribed to the given map. Called after MAP_PUT, MAP_DELETE, MAP_CLEAR, etc.Each invalidation carries a per-map monotonic sequence number in the message value (8-byte big-endian long). Clients use this to detect duplicates, out-of-order delivery, and sequence gaps.
Sends asynchronously on virtual threads without blocking the caller, while preserving enqueue order relative to sequence assignment.
- Parameters:
mapName- the map that was modifiedkey- the key that was modified (null for CLEAR operations)
-
getMapSequence
Get the current sequence number for a map. Useful for diagnostics and testing.- Parameters:
mapName- the map name- Returns:
- the current sequence, or 0 if no invalidations have been broadcast
-
getTotalInvalidationsSent
public long getTotalInvalidationsSent() -
getTotalInvalidationsFailed
public long getTotalInvalidationsFailed() -
getSubscriptionCount
public int getSubscriptionCount() -
getSubscribedPeerCount
public int getSubscribedPeerCount() -
getSubscriptions
-