@@ -66,7 +66,6 @@ public abstract class SplitClient : ISplitClient
6666 protected IEventsManager < SdkEvent , SdkInternalEvent , EventMetadata > _eventsManager ;
6767 protected IInternalEventsTask _internalEventsTask ;
6868 private EventHandler < EventMetadata > SdkReadyEvent ;
69- private Mode _configMode ;
7069
7170 public event EventHandler < EventMetadata > SdkReady
7271 {
@@ -86,24 +85,9 @@ public event EventHandler<EventMetadata> SdkReady
8685 }
8786 public event EventHandler < EventMetadata > SdkUpdate ;
8887
89- protected SplitClient ( string apikey , Mode configMode )
88+ protected SplitClient ( string apikey )
9089 {
9190 ApiKey = apikey ;
92- _configMode = configMode ;
93-
94- if ( configMode == Mode . Standalone )
95- {
96- _eventsManager = new EventsManager < SdkEvent , SdkInternalEvent , EventMetadata > ( new EventsManagerConfig ( ) , new EventDelivery < SdkEvent , EventMetadata > ( ) ) ;
97- _internalEventsTask = new InternalEventsTask ( _eventsManager , new SplitQueue < EventSource . Workers . SdkEventNotification > ( ) ) ;
98- _internalEventsTask . Start ( ) ;
99- RegisterEvents ( ) ;
100- }
101- else
102- {
103- _eventsManager = null ;
104- _internalEventsTask = new NoOpInternalEventsTask ( ) ;
105- }
106-
10791 _wrapperAdapter = WrapperAdapter . Instance ( ) ;
10892 _keyValidator = new KeyValidator ( ) ;
10993 _splitNameValidator = new SplitNameValidator ( ) ;
@@ -112,8 +96,6 @@ protected SplitClient(string apikey, Mode configMode)
11296 _factoryInstantiationsService = FactoryInstantiationsService . Instance ( ) ;
11397 _flagSetsValidator = new FlagSetsValidator ( ) ;
11498 _configService = new ConfigService ( _wrapperAdapter , _flagSetsValidator , new SdkMetadataValidator ( ) ) ;
115- _statusManager = new InMemoryReadinessGatesCache ( _internalEventsTask ) ;
116- _tasksManager = new TasksManager ( _statusManager ) ;
11799 }
118100
119101 #region GetTreatment
@@ -330,12 +312,14 @@ public virtual async Task DestroyAsync()
330312 if ( _statusManager . IsDestroyed ( ) ) return ;
331313
332314 _log . Info ( Messages . InitDestroy ) ;
333- _internalEventsTask . Stop ( ) ;
334315 _factoryInstantiationsService . Decrease ( ApiKey ) ;
335316 _statusManager . SetDestroy ( ) ;
336317 await _syncManager . ShutdownAsync ( ) ;
337- UnregisterEvents ( ) ;
338-
318+ if ( _eventsManager != null )
319+ {
320+ _internalEventsTask . Stop ( ) ;
321+ UnregisterEvents ( ) ;
322+ }
339323 _log . Info ( Messages . Destroyed ) ;
340324 }
341325
@@ -345,12 +329,14 @@ public virtual void Destroy()
345329
346330 _log . Info ( Messages . InitDestroy ) ;
347331
348- _internalEventsTask . Stop ( ) ;
349332 _factoryInstantiationsService . Decrease ( ApiKey ) ;
350333 _statusManager . SetDestroy ( ) ;
351334 _syncManager . Shutdown ( ) ;
352- UnregisterEvents ( ) ;
353-
335+ if ( _eventsManager != null )
336+ {
337+ _internalEventsTask . Stop ( ) ;
338+ UnregisterEvents ( ) ;
339+ }
354340 _log . Info ( Messages . Destroyed ) ;
355341 }
356342 #endregion
@@ -427,6 +413,12 @@ public ISplitManager GetSplitManager()
427413 #endregion
428414
429415 #region Protected Methods
416+ protected void BuildStatusAndTaskManager ( )
417+ {
418+ _statusManager = new InMemoryReadinessGatesCache ( _internalEventsTask ) ;
419+ _tasksManager = new TasksManager ( _statusManager ) ;
420+ }
421+
430422 protected void BuildUniqueKeysTracker ( BaseConfig config )
431423 {
432424 var bloomFilter = new BloomFilter ( config . BfExpectedElements , config . BfErrorRate ) ;
@@ -464,6 +456,14 @@ protected void BuildFallbackCalculator(FallbackTreatmentsConfiguration fallbackT
464456 {
465457 _fallbackTreatmentCalculator = new FallbackTreatmentCalculator ( fallbackTreatmentsConfiguration ) ;
466458 }
459+
460+ protected void BuildEventsManager ( )
461+ {
462+ _eventsManager = new EventsManager < SdkEvent , SdkInternalEvent , EventMetadata > ( new EventsManagerConfig ( ) , new EventDelivery < SdkEvent , EventMetadata > ( ) ) ;
463+ _internalEventsTask = new InternalEventsTask ( _eventsManager , new SplitQueue < EventSource . Workers . SdkEventNotification > ( ) ) ;
464+ _internalEventsTask . Start ( ) ;
465+ RegisterEvents ( ) ;
466+ }
467467 #endregion
468468
469469 #region Private Async Methods
@@ -532,11 +532,8 @@ private void RegisterEvents()
532532 }
533533 private void UnregisterEvents ( )
534534 {
535- if ( _configMode == Mode . Standalone )
536- {
537- _eventsManager . Unregister ( SdkEvent . SdkReady ) ;
538- _eventsManager . Unregister ( SdkEvent . SdkUpdate ) ;
539- }
535+ _eventsManager . Unregister ( SdkEvent . SdkReady ) ;
536+ _eventsManager . Unregister ( SdkEvent . SdkUpdate ) ;
540537 }
541538 private List < TreatmentResult > GetTreatmentsSync ( Enums . API method , Key key , List < string > features , Dictionary < string , object > attributes = null , EvaluationOptions evaluationOptions = null )
542539 {
0 commit comments