/// <summary> /// Subscribes to invalidation events. /// </summary> private async ValueTask <Guid> SubscribeToInvalidationEventsAsync() { var subscription = new ClusterSubscription( MapAddNearCacheInvalidationListenerCodec.EncodeRequest(Name, (int)MapEventTypes.Invalidated, false), (message, state) => MapAddNearCacheInvalidationListenerCodec.DecodeResponse(message).Response, (id, state) => MapRemoveEntryListenerCodec.EncodeRequest(((EventState)state).Name, id), (message, state) => MapRemoveEntryListenerCodec.DecodeResponse(message).Response, (message, state) => MapAddNearCacheInvalidationListenerCodec.HandleEventAsync(message, HandleCodecSingleEvent, HandleCodecBatchEvent, null, LoggerFactory), new EventState { Name = Name }); await Cluster.Events.InstallSubscriptionAsync(subscription, CancellationToken.None).CfAwait(); return(subscription.Id); }
private void RegisterInvalidateListener() { try { var request = MapAddNearCacheInvalidationListenerCodec.EncodeRequest(Name, (int)EntryEventType.Invalidation, false); DistributedEventHandler handler = message => MapAddNearCacheInvalidationListenerCodec.EventHandler.HandleEvent(message, HandleIMapInvalidationEvent, HandleIMapBatchInvalidationEvent); RegistrationId = Client.ListenerService.RegisterListener(request, message => MapAddNearCacheInvalidationListenerCodec.DecodeResponse(message).Response, id => MapRemoveEntryListenerCodec.EncodeRequest(Name, id), handler); } catch (Exception e) { Logger.Severe("-----------------\n Near Cache is not initialized!!! \n-----------------", e); } }