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); }
public virtual string AddEntryListener(IEntryListener <K, V> listener, K key, bool includeValue) { var keyData = ToData(key); var request = MultiMapAddEntryListenerToKeyCodec.EncodeRequest(GetName(), keyData, includeValue); DistributedEventHandler handler = eventData => MultiMapAddEntryListenerToKeyCodec.AbstractEventHandler.Handle(eventData, (thekey, value, oldValue, mergingValue, type, uuid, entries) => OnEntryEvent(thekey, value, oldValue, mergingValue, (EntryEventType)type, uuid, entries, includeValue, listener) ); return(Listen(request, message => MultiMapAddEntryListenerToKeyCodec.DecodeResponse(message).response, handler)); }
public virtual string AddEntryListener(IEntryListener <TKey, TValue> listener, TKey key, bool includeValue) { var listenerAdapter = EntryListenerAdapter <TKey, TValue> .CreateAdapter(listener, GetContext().GetSerializationService()); var keyData = ToData(key); var request = MultiMapAddEntryListenerToKeyCodec.EncodeRequest(GetName(), keyData, includeValue, IsSmart()); DistributedEventHandler handler = eventData => MultiMapAddEntryListenerToKeyCodec.EventHandler.HandleEvent(eventData, (k, value, oldValue, mergingValue, type, uuid, entries) => { OnEntryEvent(k, value, oldValue, mergingValue, type, uuid, entries, listenerAdapter); }); return(RegisterListener(request, message => MultiMapAddEntryListenerToKeyCodec.DecodeResponse(message).response, id => MultiMapRemoveEntryListenerCodec.EncodeRequest(GetName(), id), handler)); }
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); }