private async Task <Guid> SubscribeAsync(bool includeValues, TKey key, bool hasKey, Action <MultiDictionaryEventHandlers <TKey, TValue> > handle) { if (hasKey && key == null) { throw new ArgumentNullException(nameof(key)); } if (handle == null) { throw new ArgumentNullException(nameof(handle)); } var handlers = new MultiDictionaryEventHandlers <TKey, TValue>(); handle(handlers); // 0: no entryKey // 1: entryKey var mode = hasKey ? 1 : 0; var subscribeRequest = mode switch { 0 => MultiMapAddEntryListenerCodec.EncodeRequest(Name, includeValues, Cluster.IsSmartRouting), 1 => MultiMapAddEntryListenerToKeyCodec.EncodeRequest(Name, ToData(key), includeValues, Cluster.IsSmartRouting), _ => throw new NotSupportedException() }; var subscription = new ClusterSubscription( subscribeRequest, ReadSubscribeResponse, CreateUnsubscribeRequest, ReadUnsubscribeResponse, HandleEventAsync, new MapSubscriptionState(mode, Name, handlers)); await Cluster.Events.InstallSubscriptionAsync(subscription).CAF(); return(subscription.Id); }
public MapSubscriptionState(int mode, string name, MultiDictionaryEventHandlers <TKey, TValue> handlers) : base(name, handlers) { Mode = mode; }