示例#1
0
        /// <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> >();
        }
示例#2
0
        /// <summary>
        /// Factory method for <see cref="ClusterClient"/> <see cref="Actor.Props"/>.
        /// </summary>
        /// <param name="settings">TBD</param>
        /// <exception cref="ArgumentNullException">
        /// This exception is thrown when the specified <paramref name="settings"/> is undefined.
        /// </exception>
        /// <returns>TBD</returns>
        public static Props Props(ClusterClientSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            return(Actor.Props.Create(() => new ClusterClient(settings)).WithDeploy(Deploy.Local));
        }
示例#3
0
        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);
        }
示例#4
0
        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>>();
        }
示例#5
0
        /// <summary>
        /// Factory method for <see cref="ClusterClient"/> <see cref="Actor.Props"/>.
        /// </summary>
        public static Props Props(ClusterClientSettings settings)
        {
            if (settings == null)
                throw new ArgumentNullException(nameof(settings));

            return Actor.Props.Create(() => new ClusterClient(settings)).WithDeploy(Deploy.Local);
        }
示例#6
0
        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);
        }