public override void DoPeriodicAction()
        {
            var isGlobalCheck         = ShouldPerformGlobalCheck();
            var peers                 = _cqlStorage.GetAllKnownPeers().AsList();
            var updatedNonAckedCounts = _nonAckedCountCache.Update(peers.Select(x => new NonAckedCount(x.PeerId, x.NonAckedMessageCount)));
            var updatedPeerIds        = updatedNonAckedCounts.Select(x => x.PeerId).ToHashSet();
            var peersToCheck          = isGlobalCheck ? peers : peers.Where(x => updatedPeerIds.Contains(x.PeerId));

            if (isGlobalCheck)
            {
                _lastGlobalCheck = SystemDateTime.UtcNow;
            }

            Parallel.ForEach(peersToCheck, new ParallelOptions {
                MaxDegreeOfParallelism = 10
            }, UpdateOldestNonAckedMessage);
        }
Exemple #2
0
        public override void DoPeriodicAction()
        {
            var isGlobalCheck      = SystemDateTime.UtcNow >= _lastGlobalCheck.Add(_configuration.OldestMessagePerPeerGlobalCheckPeriod);
            var allPeersDictionary = _cqlStorage.GetAllKnownPeers().ToDictionary(state => state.PeerId);
            IEnumerable <PeerState> peersToCheck = allPeersDictionary.Values;
            var updatedPeers = _nonAckedCountCache.GetUpdatedValues(peersToCheck.Select(x => new NonAckedCount(x.PeerId, x.NonAckedMessageCount)));

            if (isGlobalCheck)
            {
                _lastGlobalCheck = SystemDateTime.UtcNow;
            }
            else
            {
                peersToCheck = updatedPeers.Select(x => allPeersDictionary[x.PeerId]);
            }

            Parallel.ForEach(peersToCheck, new ParallelOptions {
                MaxDegreeOfParallelism = 10
            }, UpdateOldestNonAckedMessage);
        }