Ejemplo n.º 1
0
        private async Task <Guid> SubscribeAsync(Action <MultiMapEventHandlers <TKey, TValue> > events, Maybe <TKey> key, bool includeValues, object state)
        {
            if (events == null)
            {
                throw new ArgumentNullException(nameof(events));
            }

            var handlers = new MultiMapEventHandlers <TKey, TValue>();

            events(handlers);

            // 0: no entryKey
            // 1: entryKey
            var mode = key.Match(1, 0);
            var keyv = key.ValueOrDefault();

            var subscribeRequest = mode switch
            {
                0 => MultiMapAddEntryListenerCodec.EncodeRequest(Name, includeValues, Cluster.IsSmartRouting),
                1 => MultiMapAddEntryListenerToKeyCodec.EncodeRequest(Name, ToData(keyv), includeValues, Cluster.IsSmartRouting),
                _ => throw new NotSupportedException()
            };

            var subscription = new ClusterSubscription(
                subscribeRequest,
                ReadSubscribeResponse,
                CreateUnsubscribeRequest,
                ReadUnsubscribeResponse,
                HandleEventAsync,
                new MapSubscriptionState(mode, Name, handlers, state));

            await Cluster.Events.InstallSubscriptionAsync(subscription).CfAwait();

            return(subscription.Id);
        }
Ejemplo n.º 2
0
 public MapSubscriptionState(int mode, string name, MultiMapEventHandlers <TKey, TValue> handlers, object state)
     : base(name, handlers, state)
 {
     Mode = mode;
 }