43
43
import com .optimizely .ab .config .parser .ConfigParseException ;
44
44
import com .optimizely .ab .error .ErrorHandler ;
45
45
import com .optimizely .ab .event .EventHandler ;
46
+ import com .optimizely .ab .event .EventProcessor ;
47
+ import com .optimizely .ab .event .ForwardingEventProcessor ;
46
48
import com .optimizely .ab .event .internal .payload .EventBatch ;
47
49
import com .optimizely .ab .notification .NotificationCenter ;
48
50
import com .optimizely .ab .notification .UpdateConfigNotification ;
@@ -66,6 +68,8 @@ public class OptimizelyManager {
66
68
private final long datafileDownloadInterval ;
67
69
private final long eventDispatchInterval ;
68
70
@ Nullable private EventHandler eventHandler = null ;
71
+ @ Nullable private EventProcessor eventProcessor = null ;
72
+ @ Nullable private NotificationCenter notificationCenter = null ;
69
73
@ Nullable private ErrorHandler errorHandler ;
70
74
@ NonNull private Logger logger ;
71
75
@ Nullable private final String projectId ;
@@ -85,7 +89,9 @@ public class OptimizelyManager {
85
89
@ Nullable ErrorHandler errorHandler ,
86
90
long eventDispatchInterval ,
87
91
@ NonNull EventHandler eventHandler ,
88
- @ NonNull UserProfileService userProfileService ) {
92
+ @ Nullable EventProcessor eventProcessor ,
93
+ @ NonNull UserProfileService userProfileService ,
94
+ @ NonNull NotificationCenter notificationCenter ) {
89
95
90
96
if (projectId == null && sdkKey == null ) {
91
97
logger .error ("projectId and sdkKey are both null!" );
@@ -103,8 +109,10 @@ public class OptimizelyManager {
103
109
this .datafileHandler = datafileHandler ;
104
110
this .eventDispatchInterval = eventDispatchInterval ;
105
111
this .eventHandler = eventHandler ;
112
+ this .eventProcessor = eventProcessor ;
106
113
this .errorHandler = errorHandler ;
107
114
this .userProfileService = userProfileService ;
115
+ this .notificationCenter = notificationCenter ;
108
116
}
109
117
110
118
@ VisibleForTesting
@@ -501,6 +509,7 @@ private OptimizelyClient buildOptimizely(@NonNull Context context, @NonNull Stri
501
509
Optimizely .Builder builder = Optimizely .builder ();
502
510
503
511
builder .withEventHandler (eventHandler );
512
+ builder .withEventProcessor (eventProcessor );
504
513
505
514
if (datafileHandler instanceof DefaultDatafileHandler ) {
506
515
DefaultDatafileHandler handler = (DefaultDatafileHandler )datafileHandler ;
@@ -519,7 +528,7 @@ private OptimizelyClient buildOptimizely(@NonNull Context context, @NonNull Stri
519
528
}
520
529
521
530
builder .withUserProfileService (userProfileService );
522
-
531
+ builder . withNotificationCenter ( notificationCenter );
523
532
Optimizely optimizely = builder .build ();
524
533
return new OptimizelyClient (optimizely , LoggerFactory .getLogger (OptimizelyClient .class ));
525
534
}
@@ -644,6 +653,8 @@ public static class Builder {
644
653
@ Nullable private Logger logger = null ;
645
654
@ Nullable private EventHandler eventHandler = null ;
646
655
@ Nullable private ErrorHandler errorHandler = null ;
656
+ @ Nullable private EventProcessor eventProcessor = null ;
657
+ @ Nullable private NotificationCenter notificationCenter = null ;
647
658
@ Nullable private UserProfileService userProfileService = null ;
648
659
@ Nullable private String sdkKey = null ;
649
660
@ Nullable private DatafileConfig datafileConfig = null ;
@@ -748,6 +759,16 @@ public Builder withDatafileConfig(DatafileConfig datafileConfig) {
748
759
return this ;
749
760
}
750
761
762
+ public Builder withEventProcessor (EventProcessor eventProcessor ) {
763
+ this .eventProcessor = eventProcessor ;
764
+ return this ;
765
+ }
766
+
767
+ public Builder withNotificationCenter (NotificationCenter notificationCenter ) {
768
+ this .notificationCenter = notificationCenter ;
769
+ return this ;
770
+ }
771
+
751
772
/**
752
773
* Get a new {@link Builder} instance to create {@link OptimizelyManager} with.
753
774
* @param context the application context used to create default service if not provided.
@@ -791,6 +812,14 @@ public OptimizelyManager build(Context context) {
791
812
eventHandler = DefaultEventHandler .getInstance (context );
792
813
}
793
814
815
+ if (notificationCenter == null ) {
816
+ notificationCenter = new NotificationCenter ();
817
+ }
818
+
819
+ if (eventProcessor == null ) {
820
+ eventProcessor = new ForwardingEventProcessor (eventHandler , notificationCenter );
821
+ }
822
+
794
823
if (projectId == null && sdkKey == null ) {
795
824
logger .error ("ProjectId and SDKKey cannot both be null" );
796
825
return null ;
@@ -804,7 +833,9 @@ public OptimizelyManager build(Context context) {
804
833
errorHandler ,
805
834
eventDispatchInterval ,
806
835
eventHandler ,
807
- userProfileService );
836
+ eventProcessor ,
837
+ userProfileService ,
838
+ notificationCenter );
808
839
}
809
840
}
810
841
}
0 commit comments