/// <inheritdoc /> public void Build(HazelcastClientEventHandlers events) { if (_build != null) { _build(events); } else { var subscriber = _subscriber ?? (_type == null ? ServiceFactory.CreateInstance <IHazelcastClientEventSubscriber>(_typename, null) : ServiceFactory.CreateInstance <IHazelcastClientEventSubscriber>(_type, null)); subscriber.Build(events); } }
/// <inheritdoc /> public async Task <Guid> SubscribeAsync(Action <HazelcastClientEventHandlers> events) { if (events == null) { throw new ArgumentNullException(nameof(events)); } var handlers = new HazelcastClientEventHandlers(); events(handlers); foreach (var handler in handlers) { switch (handler) { case DistributedObjectCreatedEventHandler _: case DistributedObjectDestroyedEventHandler _: await Cluster.Events.AddObjectLifecycleSubscription().CfAwait(); break; case PartitionLostEventHandler _: await Cluster.Events.AddPartitionLostSubscription().CfAwait(); break; case MembersUpdatedEventHandler _: case PartitionsUpdatedEventHandler _: case ConnectionOpenedEventHandler _: case ConnectionClosedEventHandler _: case StateChangedEventHandler _: // nothing to do (but don't throw) break; default: throw new NotSupportedException($"Handler of type {handler.GetType()} is not supported here."); } } var id = Guid.NewGuid(); _handlers[id] = handlers; return(id); }