/// <summary> /// Initializes a new instance of the <see cref="ClusterClient" /> class. /// </summary> /// <param name="settings">The settings used to configure the client.</param> /// <exception cref="ArgumentException"> /// This exception is thrown when the settings contains no initial contacts. /// </exception> public ClusterClient(ClusterClientSettings settings) { if (settings.InitialContacts.Count == 0) { throw new ArgumentException("Initial contacts for cluster client cannot be empty"); } _settings = settings; _failureDetector = new DeadlineFailureDetector(_settings.AcceptableHeartbeatPause, _settings.HeartbeatInterval); _contactPaths = settings.InitialContacts.ToImmutableHashSet(); _initialContactsSelections = _contactPaths.Select(Context.ActorSelection).ToArray(); _contacts = _initialContactsSelections; SendGetContacts(); _contactPathsPublished = ImmutableHashSet <ActorPath> .Empty; _subscribers = ImmutableList <IActorRef> .Empty; _heartbeatTask = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable( settings.HeartbeatInterval, settings.HeartbeatInterval, Self, HeartbeatTick.Instance, Self); _refreshContactsCancelable = null; ScheduleRefreshContactsTick(settings.EstablishingGetContactsInterval); Self.Tell(RefreshContactsTick.Instance); _buffer = new Queue <Tuple <object, IActorRef> >(); }
private void UpdateClientInteractions(IActorRef client) { if (_clientInteractions.TryGetValue(client, out var failureDetector)) { failureDetector.HeartBeat(); } else { failureDetector = new DeadlineFailureDetector(_settings.AcceptableHeartbeatPause, _settings.HeartbeatInterval); failureDetector.HeartBeat(); _clientInteractions = _clientInteractions.Add(client, failureDetector); _log.Debug($"Received new contact from [{client.Path}]"); var clusterClientUp = new ClusterClientUp(client); _subscribers.ForEach(s => s.Tell(clusterClientUp)); _clientsPublished = _clientInteractions.Keys.ToImmutableHashSet(); } }
public ClusterClient(ClusterClientSettings settings) { if (!settings.InitialContacts.Any()) { throw new ArgumentException("Initial contacts for cluster client cannot be empty"); } Settings = settings; _failureDetector = new DeadlineFailureDetector(Settings.AcceptableHeartbeatPause, () => Settings.HeartbeatInterval.Ticks); _initialContactsSelections = settings.InitialContacts.Select(Context.ActorSelection).ToArray(); _contacts = _initialContactsSelections; _buffer = new Queue <Tuple <object, IActorRef> >(); SendGetContacts(); _heartbeatCancelable = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable( settings.HeartbeatInterval, settings.HeartbeatInterval, Self, InternalMessage.HeartbeatTick, Self); ScheduleRefreshContactsTick(settings.EstablishingGetContactsInterval); Self.Tell(InternalMessage.RefreshContactsTick); }