Beispiel #1
0
 public Cache GetCache(string property)
 {
     return(DataPollers.FirstOrDefault(p => p.ParentMemberName == property));
 }
Beispiel #2
0
        /// <summary>
        /// Called on a background thread for when this node is ACTUALLY polling
        /// This is not called if we're not due for a poll when the pass runs
        /// </summary>
        private void InnerPollImpl(bool force = false, bool sync = false)
        {
            CurrentPollDuration = Stopwatch.StartNew();
            try
            {
                PollStatus = "InnerPoll Started";
                if (Polling != null)
                {
                    var ps = new PollStartArgs();
                    Polling(this, ps);
                    if (ps.AbortPoll)
                    {
                        return;
                    }
                }

                int toPoll = 0;
                if (sync || FirstPollRun != null)
                {
                    PollStatus = "DataPollers Queueing (Sync)";
                    var tasks = DataPollers
                                .Where(p => force || p.ShouldPoll)
                                .Select(p => p.PollAsync(force))
                                .ToArray <Task>();
                    Task.WaitAll(tasks);
                    PollStatus = "DataPollers Complete (Sync)";
                }
                else
                {
                    PollStatus = "DataPollers Queueing";
                    foreach (var p in DataPollers)
                    {
                        // Cheap checks to eliminate many uncessary task creations
                        if (!force && !p.ShouldPoll)
                        {
                            continue;
                        }
                        // Kick off the poll and don't wait for it to continue;
#pragma warning disable 4014
                        p.PollStatus = "Kicked off by Node";
                        Interlocked.Add(ref _totalCacheQueues, 1);
                        p.PollAsync(force).ContinueWith(t =>
                        {
                            if (t.IsFaulted)
                            {
                                Current.LogException(t.Exception);
                                PollStatus = "Faulted";
                            }
                            else
                            {
                                PollStatus = "Completed";
                            }
                            Interlocked.Add(ref _totalCachePolls, t.Result);
                        }, TaskContinuationOptions.ExecuteSynchronously).ConfigureAwait(false);
                        toPoll++;
#pragma warning restore 4014
                    }
                    PollStatus = toPoll.ToComma() + " DataPollers Started";
                }

                LastPoll = DateTime.UtcNow;
                Polled?.Invoke(this, new PollResultArgs {
                    Queued = toPoll
                });
                if (FirstPollRun != null)
                {
                    FirstPollRun.Set();
                    FirstPollRun = null;
                }

                Interlocked.Increment(ref _totalPolls);
            }
            finally
            {
                CurrentPollDuration.Stop();
                LastPollDuration    = CurrentPollDuration.Elapsed;
                _isPolling          = false;
                CurrentPollDuration = null;
                PollStatus          = "InnerPoll Complete";
            }
        }