コード例 #1
0
        /// <summary>
        /// Sends event forever until stopped.
        /// </summary>
        private void loop()
        {
            for (;;)
            {
                var run = false;
                lock (_startStopLock)
                {
                    run = _keepRunning;
                }

                if (run)
                {
                    // If device is offline wait and loop
                    if (_deviceOnlineMethod != null && !_deviceOnlineMethod.Invoke())
                    {
                        EmitterLoopBackoff();
                    }
                    else
                    {
                        var eventList = _queue.Peek(_sendLimit, _stopPollIntervalMs);
                        _logger.Info(String.Format("Emitter found {0} events", eventList.Count));

                        var sendResult = _endpoint.Send(eventList);
                        _queue.Remove(sendResult.SuccessIds);
                        var successCount = sendResult.SuccessIds.Count;
                        var failureCount = sendResult.FailureIds.Count;

                        _logger.Info(String.Format("Emitter sent and deleted {0} events", successCount));
                        _logger.Info(String.Format("Emitter failed to send {0}", failureCount));

                        // Send callback method
                        _sendSuccessMethod?.Invoke(successCount, failureCount);

                        // If all events failed to send slow down - back off 30 secs
                        // NB this can be interrupted by Flush
                        if (successCount == 0 && failureCount > 0)
                        {
                            EmitterLoopBackoff();
                        }
                    }
                }
                else
                {
                    _logger.Info("Emitter thread finished processing");
                    break;
                }
            }
        }
            public void Consume()
            {
                Consumed = new List <Payload>();

                for (int i = 0; i < _count; i++)
                {
                    var items = _q.Peek(1, _timeout);
                    foreach (var item in items)
                    {
                        Consumed.Add(item.Item2);
                    }
                }
            }