56
56
import java .io .InputStream ;
57
57
import java .util .List ;
58
58
import java .util .Set ;
59
+ import java .util .concurrent .TimeUnit ;
59
60
60
61
61
62
/**
@@ -68,7 +69,7 @@ public class OptimizelyManager {
68
69
69
70
@ NonNull private DatafileHandler datafileHandler ;
70
71
private final long datafileDownloadInterval ;
71
- private final long eventDispatchInterval ;
72
+ private final long eventDispatchRetryInterval ;
72
73
@ Nullable private EventHandler eventHandler = null ;
73
74
@ Nullable private EventProcessor eventProcessor = null ;
74
75
@ Nullable private NotificationCenter notificationCenter = null ;
@@ -89,7 +90,7 @@ public class OptimizelyManager {
89
90
long datafileDownloadInterval ,
90
91
@ NonNull DatafileHandler datafileHandler ,
91
92
@ Nullable ErrorHandler errorHandler ,
92
- long eventDispatchInterval ,
93
+ long eventDispatchRetryInterval ,
93
94
@ NonNull EventHandler eventHandler ,
94
95
@ Nullable EventProcessor eventProcessor ,
95
96
@ NonNull UserProfileService userProfileService ,
@@ -109,7 +110,7 @@ public class OptimizelyManager {
109
110
this .logger = logger ;
110
111
this .datafileDownloadInterval = datafileDownloadInterval ;
111
112
this .datafileHandler = datafileHandler ;
112
- this .eventDispatchInterval = eventDispatchInterval ;
113
+ this .eventDispatchRetryInterval = eventDispatchRetryInterval ;
113
114
this .eventHandler = eventHandler ;
114
115
this .eventProcessor = eventProcessor ;
115
116
this .errorHandler = errorHandler ;
@@ -591,7 +592,7 @@ public UserProfileService getUserProfileService() {
591
592
protected EventHandler getEventHandler (Context context ) {
592
593
if (eventHandler == null ) {
593
594
DefaultEventHandler eventHandler = DefaultEventHandler .getInstance (context );
594
- eventHandler .setDispatchInterval (eventDispatchInterval );
595
+ eventHandler .setDispatchInterval (eventDispatchRetryInterval );
595
596
this .eventHandler = eventHandler ;
596
597
}
597
598
@@ -695,8 +696,10 @@ public static class Builder {
695
696
696
697
// -1 will cause the background download to not be initiated.
697
698
private long datafileDownloadInterval = -1L ;
698
- // -1 will cause the background download to not be initiated.
699
- private long eventDispatchInterval = -1L ;
699
+ // -1 will disable event batching.
700
+ private long eventFlushInterval = -1L ;
701
+ // -l will disable periodic retries on event dispatch failures (but queued and retried on next event dispatch request)
702
+ private long eventDispatchRetryInterval = -1L ;
700
703
@ Nullable private DatafileHandler datafileHandler = null ;
701
704
@ Nullable private Logger logger = null ;
702
705
@ Nullable private EventHandler eventHandler = null ;
@@ -719,21 +722,6 @@ public static class Builder {
719
722
this .projectId = null ;
720
723
}
721
724
722
-
723
- /**
724
- * Sets the interval which {@link DatafileService} through the {@link DatafileHandler} will attempt to update the
725
- * cached datafile. If you set this to -1, you disable background updates. If you don't set
726
- * a download interval (or set to less than 0), then no background updates will be scheduled or occur.
727
- * The minimum interval is 900 secs (15 minutes) (enforced by the Android JobScheduler API. See {@link android.app.job.JobInfo})
728
- *
729
- * @param interval the interval in seconds
730
- * @return this {@link Builder} instance
731
- */
732
- public Builder withDatafileDownloadInterval (long interval ) {
733
- this .datafileDownloadInterval = interval ;
734
- return this ;
735
- }
736
-
737
725
/**
738
726
* Override the default {@link DatafileHandler}.
739
727
* @param overrideHandler datafile handler to replace default handler
@@ -770,18 +758,76 @@ public Builder withErrorHandler(ErrorHandler errorHandler) {
770
758
}
771
759
772
760
/**
773
- * Sets the interval which {@link EventIntentService} will flush events.
774
- * If you set this to -1, you disable background updates. If you don't set
775
- * a event dispatch interval, then no background updates will be scheduled or occur.
761
+ * Sets the interval which {@link DatafileService} through the {@link DatafileHandler} will attempt to update the
762
+ * cached datafile. If you set this to -1, you disable background updates. If you don't set
763
+ * a download interval (or set to less than 0), then no background updates will be scheduled or occur.
764
+ * The minimum interval is 15 minutes (enforced by the Android JobScheduler API. See {@link android.app.job.JobInfo})
765
+ *
766
+ * @param interval the interval
767
+ * @param timeUnit the time unit of the timeout argument
768
+ * @return this {@link Builder} instance
769
+ */
770
+ public Builder withDatafileDownloadInterval (long interval , TimeUnit timeUnit ) {
771
+ this .datafileDownloadInterval = interval > 0 ? timeUnit .toSeconds (interval ) : interval ;
772
+ return this ;
773
+ }
774
+
775
+ /**
776
+ * Sets the interval which {@link DatafileService} through the {@link DatafileHandler} will attempt to update the
777
+ * cached datafile. If you set this to -1, you disable background updates. If you don't set
778
+ * a download interval (or set to less than 0), then no background updates will be scheduled or occur.
779
+ * The minimum interval is 900 secs (15 minutes) (enforced by the Android JobScheduler API. See {@link android.app.job.JobInfo})
776
780
*
777
781
* @param interval the interval in seconds
778
782
* @return this {@link Builder} instance
779
783
*/
784
+ @ Deprecated
785
+ public Builder withDatafileDownloadInterval (long interval ) {
786
+ this .datafileDownloadInterval = interval ;
787
+ return this ;
788
+ }
789
+
790
+ /**
791
+ * Sets the interval which queued events will be flushed periodically.
792
+ * If you don't set this value or set this to -1, the default interval will be used (30 seconds).
793
+ *
794
+ * @param interval the interval
795
+ * @param timeUnit the time unit of the timeout argument
796
+ * @return this {@link Builder} instance
797
+ */
798
+ public Builder withEventDispatchInterval (long interval , TimeUnit timeUnit ) {
799
+ this .eventFlushInterval = interval > 0 ? timeUnit .toMillis (interval ) : interval ;
800
+ return this ;
801
+ }
802
+
803
+ /**
804
+ * Sets the interval which {@link EventIntentService} will retry event dispatch periodically.
805
+ * If you don't set this value or set this to -1, periodic retries on event dispatch failures will be disabled (but still queued and retried on next event dispatch request)
806
+ *
807
+ * @param interval the interval
808
+ * @param timeUnit the time unit of the timeout argument
809
+ * @return this {@link Builder} instance
810
+ */
811
+ public Builder withEventDispatchRetryInterval (long interval , TimeUnit timeUnit ) {
812
+ this .eventDispatchRetryInterval = interval > 0 ? timeUnit .toMillis (interval ) : interval ;
813
+ return this ;
814
+ }
815
+
816
+ /**
817
+ * Sets the interval which {@link EventIntentService} will retry event dispatch periodically.
818
+ * If you don't set this value or set this to -1, periodic retries on event dispatch failures will be disabled (but still queued and retried on next event dispatch request)
819
+ *
820
+ * @param interval the interval in milliseconds
821
+ * @return this {@link Builder} instance
822
+ */
823
+ @ Deprecated
780
824
public Builder withEventDispatchInterval (long interval ) {
781
- this .eventDispatchInterval = interval ;
825
+ this .eventFlushInterval = interval ;
826
+ this .eventDispatchRetryInterval = interval ;
782
827
return this ;
783
828
}
784
829
830
+
785
831
/**
786
832
* Override the default {@link EventHandler}.
787
833
*
@@ -869,7 +915,7 @@ public OptimizelyManager build(Context context) {
869
915
eventProcessor = BatchEventProcessor .builder ()
870
916
.withNotificationCenter (notificationCenter )
871
917
.withEventHandler (eventHandler )
872
- .withFlushInterval (eventDispatchInterval )
918
+ .withFlushInterval (eventFlushInterval )
873
919
.build ();
874
920
875
921
}
@@ -885,7 +931,7 @@ public OptimizelyManager build(Context context) {
885
931
datafileDownloadInterval ,
886
932
datafileHandler ,
887
933
errorHandler ,
888
- eventDispatchInterval ,
934
+ eventDispatchRetryInterval ,
889
935
eventHandler ,
890
936
eventProcessor ,
891
937
userProfileService ,
0 commit comments