Пример #1
0
        /// <summary>
        /// Opens the current instance
        /// </summary>
        /// <param name="interests">The interests for which to open trackers</param>
        public void Open(IEnumerable <MessageInterest> interests)
        {
            Guard.Argument(interests, nameof(interests)).NotNull().NotEmpty();

            var interestList = interests as List <MessageInterest> ?? interests.ToList();

            // the LINQ query below might produce a list with same entries (one producer found more than once)
            var producersToOpen = from producer in _producerManager.Producers
                                  where !producer.IsDisabled && producer.IsAvailable
                                  let producerScopes = ((Producer)producer).Scope.Select(MessageInterest.FromScope).ToList()
                                                       from interest in interestList
                                                       where !interest.IsScopeInterest || producerScopes.Contains(interest)
                                                       select producer;

            var producerRecoveryManagers = producersToOpen.Distinct(new ProducerEqualityComparer()).Select(p => _producerRecoveryManagerFactory.GetRecoveryTracker(p, interestList)).ToList();

            if (!producerRecoveryManagers.Any())
            {
                throw new InvalidOperationException($"Message interests [{string.Join(", ", interestList)}] cannot be used. There are no suitable active producers.");
            }

            Open(producerRecoveryManagers);

            _systemSession.AliveReceived += OnSystemSessionMessageReceived;
            _systemSession.Open();
        }
        /// <summary>
        /// Opens the current instance
        /// </summary>
        /// <param name="interests">The interests for which to open trackers</param>
        public void Open(IEnumerable <MessageInterest> interests)
        {
            Contract.Requires(interests != null);

            var interestList = interests as List <MessageInterest> ?? interests.ToList();

            // the LINQ query below might produce a list with same entries (one producer found more than once)
            var producersToOpen = from producer in _producerManager.Producers
                                  where !producer.IsDisabled && producer.IsAvailable
                                  let producerScopes = ((Producer)producer).Scope.Select(MessageInterest.FromScope).ToList()
                                                       from interest in interestList
                                                       where !interest.IsScopeInterest || producerScopes.Contains(interest)
                                                       select producer;

            var producerRecoveryManagers = producersToOpen.Distinct(new ProducerEqualityComparer()).Select(p => _producerRecoveryManagerFactory.GetRecoveryTracker(p, interestList)).ToList();

            Open(producerRecoveryManagers);

            _systemSession.AliveReceived += OnSystemSessionMessageReceived;
            _systemSession.Open();
        }