Exemplo n.º 1
0
        internal EventProcessorInternal(
            EventsConfiguration config,
            BlockingCollection <IEventMessage> messageQueue,
            IEventSender eventSender,
            IUserDeduplicator userDeduplicator,
            IDiagnosticStore diagnosticStore,
            Logger logger,
            Action testActionOnDiagnosticSend
            )
        {
            _config                     = config;
            _diagnosticStore            = diagnosticStore;
            _userDeduplicator           = userDeduplicator;
            _testActionOnDiagnosticSend = testActionOnDiagnosticSend;
            _flushWorkersCounter        = new CountdownEvent(1);
            _eventSender                = eventSender;
            _logger                     = logger;
            _random                     = new Random();

            EventBuffer buffer = new EventBuffer(config.EventCapacity > 0 ? config.EventCapacity : 1, _diagnosticStore, _logger);

            // Here we use TaskFactory.StartNew instead of Task.Run() because that allows us to specify the
            // LongRunning option. This option tells the task scheduler that the task is likely to hang on
            // to a thread for a long time, so it should consider growing the thread pool.
            Task.Factory.StartNew(
                () => RunMainLoop(messageQueue, buffer),
                TaskCreationOptions.LongRunning
                );
        }
        public EventProcessor(
            EventsConfiguration config,
            IEventSender eventSender,
            IUserDeduplicator userDeduplicator,
            IDiagnosticStore diagnosticStore,
            IDiagnosticDisabler diagnosticDisabler,
            Logger logger,
            Action testActionOnDiagnosticSend
            )
        {
            _logger  = logger;
            _stopped = new AtomicBoolean(false);
            _offline = new AtomicBoolean(false);
            _sentInitialDiagnostics = new AtomicBoolean(false);
            _inputCapacityExceeded  = new AtomicBoolean(false);
            _messageQueue           = new BlockingCollection <EventProcessorInternal.IEventMessage>(
                config.EventCapacity > 0 ? config.EventCapacity : 1);

            _processorInternal = new EventProcessorInternal(
                config,
                _messageQueue,
                eventSender,
                userDeduplicator,
                diagnosticStore,
                _logger,
                testActionOnDiagnosticSend
                );

            if (config.EventFlushInterval > TimeSpan.Zero)
            {
                _flushTimer = new Timer(DoBackgroundFlush, null, config.EventFlushInterval,
                                        config.EventFlushInterval);
            }
            _diagnosticStore             = diagnosticStore;
            _diagnosticRecordingInterval = config.DiagnosticRecordingInterval;
            if (userDeduplicator != null && userDeduplicator.FlushInterval.HasValue)
            {
                _flushUsersTimer = new Timer(DoUserKeysFlush, null, userDeduplicator.FlushInterval.Value,
                                             userDeduplicator.FlushInterval.Value);
            }
            else
            {
                _flushUsersTimer = null;
            }

            if (diagnosticStore != null)
            {
                SetupDiagnosticInit(diagnosticDisabler == null || !diagnosticDisabler.Disabled);

                if (diagnosticDisabler != null)
                {
                    diagnosticDisabler.DisabledChanged += ((sender, args) => SetupDiagnosticInit(!args.Disabled));
                }
            }
        }
 internal DefaultEventProcessor(IBaseConfiguration config,
                                IUserDeduplicator userDeduplicator, HttpClient httpClient, string eventsUriPath)
 {
     _messageQueue = new BlockingCollection <IEventMessage>(config.EventQueueCapacity);
     _dispatcher   = new EventDispatcher(config, _messageQueue, userDeduplicator, httpClient, eventsUriPath);
     _flushTimer   = new Timer(DoBackgroundFlush, null, config.EventQueueFrequency,
                               config.EventQueueFrequency);
     if (userDeduplicator != null && userDeduplicator.FlushInterval.HasValue)
     {
         _flushUsersTimer = new Timer(DoUserKeysFlush, null, userDeduplicator.FlushInterval.Value,
                                      userDeduplicator.FlushInterval.Value);
     }
     else
     {
         _flushUsersTimer = null;
     }
     _stopped = new AtomicBoolean(false);
     _inputCapacityExceeded = new AtomicBoolean(false);
 }
Exemplo n.º 4
0
        internal EventDispatcher(IEventProcessorConfiguration config,
                                 BlockingCollection <IEventMessage> messageQueue,
                                 IUserDeduplicator userDeduplicator,
                                 HttpClient httpClient,
                                 string eventsUriPath)
        {
            _config              = config;
            _userDeduplicator    = userDeduplicator;
            _flushWorkersCounter = new CountdownEvent(1);
            _httpClient          = httpClient;
            _uri    = new Uri(_config.EventsUri, eventsUriPath);
            _random = new Random();

            _httpClient.DefaultRequestHeaders.Add("X-LaunchDarkly-Event-Schema",
                                                  DefaultEventProcessor.CurrentSchemaVersion);

            EventBuffer buffer = new EventBuffer(config.EventCapacity);

            Task.Run(() => RunMainLoop(messageQueue, buffer));
        }