Exemple #1
0
        private bool TryFill()
        {
            var subscriptonsReadyForPolling = this.bufferPool
                                                  .Where(s => !s.IsPolling && !s.IsPoisoned && s.NewEventsQueue.Count < queueMaxCount)
                                                  .ToArray();

            if (!subscriptonsReadyForPolling.Any())
                // all subscriptions are being polled
                return false;

            foreach (var subscription in subscriptonsReadyForPolling)
            {
                subscription.IsPolling = true;
                ThreadPool.UnsafeQueueUserWorkItem(new WaitCallback(_ =>
                    poller.PollSubscription(subscription.StreamType, subscription.Url, subscription.Token, subscription.CurrentBufferVersion)), null);
            }

            // there are subscriptions that are being polled
            return true;
        }
Exemple #2
0
        private bool TryFill(SubscriptionBuffer buffer)
        {
            if (!buffer.IsPolling && !buffer.IsPoisoned && buffer.NewEventsQueue.Count < queueMaxCount)
            {
                buffer.IsPolling = true;
                try
                {
                    if (!ThreadPool.UnsafeQueueUserWorkItem(new WaitCallback(_ =>
                                poller.PollSubscription(buffer.StreamType, buffer.Url, buffer.Token, buffer.CurrentBufferVersion)), null))
                    {
                        this.bus.Publish(new FatalErrorOcurred(new FatalErrorException("A work item could not be queued in Poller.TryFill()")));
                    }
                }
                catch (Exception ex)
                {
                    this.bus.Publish(new FatalErrorOcurred(new FatalErrorException("A work item could not be queued in Poller.TryFill()", ex)));
                    throw;
                }
                return true;
            }

            return false;
        }