コード例 #1
0
        internal StreamProcessor(
            LdClientContext context,
            IDataSourceUpdates dataSourceUpdates,
            Uri baseUri,
            TimeSpan initialReconnectDelay,
            EventSourceCreator eventSourceCreator
            )
        {
            _log = context.Basic.Logger.SubLogger(LogNames.DataSourceSubLog);
            _log.Info("Connecting to LaunchDarkly stream");

            _dataSourceUpdates     = dataSourceUpdates;
            _httpConfig            = context.Http;
            _initialReconnectDelay = initialReconnectDelay;
            _diagnosticStore       = context.DiagnosticStore;
            _initTask  = new TaskCompletionSource <bool>();
            _streamUri = new Uri(baseUri, "/all");

            _storeStatusMonitoringEnabled = _dataSourceUpdates.DataStoreStatusProvider.StatusMonitoringEnabled;
            if (_storeStatusMonitoringEnabled)
            {
                _dataSourceUpdates.DataStoreStatusProvider.StatusChanged += OnDataStoreStatusChanged;
            }

            _es = (eventSourceCreator ?? CreateEventSource)(_streamUri, _httpConfig);
            _es.MessageReceived += OnMessage;
            _es.Error           += OnError;
            _es.Opened          += OnOpen;
        }
コード例 #2
0
 /// <summary>
 /// Constructs a StreamManager instance.
 /// </summary>
 /// <param name="streamProcessor">A platform-specific implementation of IStreamProcessor.</param>
 /// <param name="streamProperties">HTTP request properties for the stream.</param>
 /// <param name="config">An implementation of IBaseConfiguration.</param>
 /// <param name="clientEnvironment">A subclass of ClientEnvironment.</param>
 /// <param name="eventSourceCreator">Null in normal usage; pass a non-null delegate if you
 /// are in a unit test and want to mock out the event source.</param>
 public StreamManager(IStreamProcessor streamProcessor, StreamProperties streamProperties,
                      IBaseConfiguration config, ClientEnvironment clientEnvironment,
                      EventSourceCreator eventSourceCreator)
 {
     _streamProcessor   = streamProcessor;
     _streamProperties  = streamProperties;
     _config            = config;
     _clientEnvironment = clientEnvironment;
     _esCreator         = eventSourceCreator ?? DefaultEventSourceCreator;
     _initTask          = new TaskCompletionSource <bool>();
     _backOff           = new EventSource.ExponentialBackoffWithDecorrelation(_config.ReconnectTime, TimeSpan.FromMilliseconds(30000));
 }