コード例 #1
0
        protected override Task OnInitializingPartitionAsync(EventProcessorHostPartition partition, CancellationToken cancellationToken)
        {
            partition.ProcessorHost  = this;
            partition.EventProcessor = _processorFactory.CreateEventProcessor();
            partition.ReadLastEnqueuedEventPropertiesFunc = ReadLastEnqueuedEventProperties;

            // Since we are re-initializing this partition, any cached information we have about the partition will be incorrect.
            // Clear it out now, if there is any, we'll refresh it in ListCheckpointsAsync, which EventProcessor will call before starting to pump messages.
            partition.Checkpoint = null;
            return(partition.EventProcessor.OpenAsync(partition));
        }
コード例 #2
0
        protected override async Task OnInitializingPartitionAsync(EventProcessorHostPartition partition, CancellationToken cancellationToken)
        {
            partition.ProcessorHost  = this;
            partition.EventProcessor = _processorFactory.CreateEventProcessor();

            // Since we are re-initializing this partition, any cached information we have about the partition will be incorrect.
            // Clear it out now, if there is any, we'll refresh it in ListCheckpointsAsync, which EventProcessor will call before starting to pump messages.
            partition.Checkpoint = null;
            await partition.EventProcessor.OpenAsync(partition).ConfigureAwait(false);

            // No ReadLastEnqueuedEventProperties information is available at this moment set the ReadLastEnqueuedEventPropertiesFunc last
            // to avoid an exception in OpenAsync
            partition.ReadLastEnqueuedEventPropertiesFunc = ReadLastEnqueuedEventProperties;
        }
コード例 #3
0
        public LdClient(Configuration config, IEventProcessor eventProcessor)
        {
            Log.InfoFormat("Starting LaunchDarkly Client {0}",
                           ServerSideClientEnvironment.Instance.Version);

            _configuration = config;
            ServerDiagnosticStore diagnosticStore = null;

            if (!_configuration.DiagnosticOptOut)
            {
                diagnosticStore = new ServerDiagnosticStore(_configuration);
            }

            if (eventProcessor == null)
            {
                IEventProcessorFactory eventProcessorFactory = _configuration.EventProcessorFactory ?? Components.DefaultEventProcessor;
                if (eventProcessorFactory is IEventProcessorFactoryWithDiagnostics epfwd)
                {
                    _eventProcessor = epfwd.CreateEventProcessor(_configuration, diagnosticStore);
                }
                else
                {
                    _eventProcessor = eventProcessorFactory.CreateEventProcessor(_configuration);
                }
                _shouldDisposeEventProcessor = true;
            }
            else
            {
                _eventProcessor = eventProcessor;
                // The following line is for backward compatibility with the obsolete mechanism by which the
                // caller could pass in an IStoreEvents implementation instance that we did not create.  We
                // were not disposing of that instance when the client was closed, so we should continue not
                // doing so until the next major version eliminates that mechanism.  We will always dispose
                // of instances that we created ourselves from a factory.
                _shouldDisposeEventProcessor = false;
            }

            IFeatureStore store;

            if (_configuration.FeatureStore == null)
            {
                store = (_configuration.FeatureStoreFactory ??
                         Components.InMemoryFeatureStore).CreateFeatureStore();
                _shouldDisposeFeatureStore = true;
            }
            else
            {
                store = _configuration.FeatureStore;
                _shouldDisposeFeatureStore = false; // see previous comment
            }
            _featureStore = new FeatureStoreClientWrapper(store);

            IUpdateProcessorFactory updateProcessorFactory = _configuration.UpdateProcessorFactory ?? Components.DefaultUpdateProcessor;

            if (updateProcessorFactory is IUpdateProcessorFactoryWithDiagnostics upfwd)
            {
                _updateProcessor = upfwd.CreateUpdateProcessor(_configuration, _featureStore, diagnosticStore);
            }
            else
            {
                _updateProcessor = updateProcessorFactory.CreateUpdateProcessor(_configuration, _featureStore);
            }

            var initTask = _updateProcessor.Start();

            if (!(_updateProcessor is NullUpdateProcessor))
            {
                Log.InfoFormat("Waiting up to {0} milliseconds for LaunchDarkly client to start..",
                               _configuration.StartWaitTime.TotalMilliseconds);
            }

            try
            {
                var unused = initTask.Wait(_configuration.StartWaitTime);
            }
            catch (AggregateException)
            {
                // StreamProcessor may throw an exception if initialization fails, because we want that behavior
                // in the Xamarin client. However, for backward compatibility we do not want to throw exceptions
                // from the LdClient constructor in the .NET client, so we'll just swallow this.
            }
        }