Пример #1
0
        /// <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);
        }
Пример #2
0
        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);
            }
        }