Skip to content

Commit 1ce6fcf

Browse files
authored
fix: change eventDispatcherInterval units for consistency (#323)
1 parent ed86c8c commit 1ce6fcf

File tree

11 files changed

+351
-51
lines changed

11 files changed

+351
-51
lines changed

android-sdk/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ dependencies {
7171

7272
testImplementation "junit:junit:$junit_ver"
7373
testImplementation "org.mockito:mockito-core:$mockito_ver"
74+
testImplementation "org.powermock:powermock-mockito-release-full:$powermock_ver"
7475
testImplementation "com.noveogroup.android:android-logger:$android_logger_ver"
7576

7677
androidTestImplementation "com.android.support.test:runner:$support_test_runner_ver"
@@ -79,8 +80,9 @@ dependencies {
7980
// Set this dependency to build and run Espresso tests
8081
androidTestImplementation "com.android.support.test.espresso:espresso-core:$espresso_ver"
8182
androidTestImplementation "org.mockito:mockito-core:$mockito_ver"
82-
androidTestImplementation "com.google.dexmaker:dexmaker:$dexmaker_ver"
83-
androidTestImplementation "com.google.dexmaker:dexmaker-mockito:$dexmaker_ver"
83+
androidTestImplementation "com.crittercism.dexmaker:dexmaker:$dexmaker_ver"
84+
androidTestImplementation "com.crittercism.dexmaker:dexmaker-dx:$dexmaker_ver"
85+
androidTestImplementation "com.crittercism.dexmaker:dexmaker-mockito:$dexmaker_ver"
8486
androidTestImplementation "com.noveogroup.android:android-logger:$android_logger_ver"
8587
androidTestImplementation "com.google.code.gson:gson:$gson_ver"
8688
androidTestImplementation "com.fasterxml.jackson.core:jackson-databind:$jacksonversion"

android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyManager.java

Lines changed: 73 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import java.io.InputStream;
5757
import java.util.List;
5858
import java.util.Set;
59+
import java.util.concurrent.TimeUnit;
5960

6061

6162
/**
@@ -68,7 +69,7 @@ public class OptimizelyManager {
6869

6970
@NonNull private DatafileHandler datafileHandler;
7071
private final long datafileDownloadInterval;
71-
private final long eventDispatchInterval;
72+
private final long eventDispatchRetryInterval;
7273
@Nullable private EventHandler eventHandler = null;
7374
@Nullable private EventProcessor eventProcessor = null;
7475
@Nullable private NotificationCenter notificationCenter = null;
@@ -89,7 +90,7 @@ public class OptimizelyManager {
8990
long datafileDownloadInterval,
9091
@NonNull DatafileHandler datafileHandler,
9192
@Nullable ErrorHandler errorHandler,
92-
long eventDispatchInterval,
93+
long eventDispatchRetryInterval,
9394
@NonNull EventHandler eventHandler,
9495
@Nullable EventProcessor eventProcessor,
9596
@NonNull UserProfileService userProfileService,
@@ -109,7 +110,7 @@ public class OptimizelyManager {
109110
this.logger = logger;
110111
this.datafileDownloadInterval = datafileDownloadInterval;
111112
this.datafileHandler = datafileHandler;
112-
this.eventDispatchInterval = eventDispatchInterval;
113+
this.eventDispatchRetryInterval = eventDispatchRetryInterval;
113114
this.eventHandler = eventHandler;
114115
this.eventProcessor = eventProcessor;
115116
this.errorHandler = errorHandler;
@@ -591,7 +592,7 @@ public UserProfileService getUserProfileService() {
591592
protected EventHandler getEventHandler(Context context) {
592593
if (eventHandler == null) {
593594
DefaultEventHandler eventHandler = DefaultEventHandler.getInstance(context);
594-
eventHandler.setDispatchInterval(eventDispatchInterval);
595+
eventHandler.setDispatchInterval(eventDispatchRetryInterval);
595596
this.eventHandler = eventHandler;
596597
}
597598

@@ -695,8 +696,10 @@ public static class Builder {
695696

696697
// -1 will cause the background download to not be initiated.
697698
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;
700703
@Nullable private DatafileHandler datafileHandler = null;
701704
@Nullable private Logger logger = null;
702705
@Nullable private EventHandler eventHandler = null;
@@ -719,21 +722,6 @@ public static class Builder {
719722
this.projectId = null;
720723
}
721724

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-
737725
/**
738726
* Override the default {@link DatafileHandler}.
739727
* @param overrideHandler datafile handler to replace default handler
@@ -770,18 +758,76 @@ public Builder withErrorHandler(ErrorHandler errorHandler) {
770758
}
771759

772760
/**
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})
776780
*
777781
* @param interval the interval in seconds
778782
* @return this {@link Builder} instance
779783
*/
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
780824
public Builder withEventDispatchInterval(long interval) {
781-
this.eventDispatchInterval = interval;
825+
this.eventFlushInterval = interval;
826+
this.eventDispatchRetryInterval = interval;
782827
return this;
783828
}
784829

830+
785831
/**
786832
* Override the default {@link EventHandler}.
787833
*
@@ -869,7 +915,7 @@ public OptimizelyManager build(Context context) {
869915
eventProcessor = BatchEventProcessor.builder()
870916
.withNotificationCenter(notificationCenter)
871917
.withEventHandler(eventHandler)
872-
.withFlushInterval(eventDispatchInterval)
918+
.withFlushInterval(eventFlushInterval)
873919
.build();
874920

875921
}
@@ -885,7 +931,7 @@ public OptimizelyManager build(Context context) {
885931
datafileDownloadInterval,
886932
datafileHandler,
887933
errorHandler,
888-
eventDispatchInterval,
934+
eventDispatchRetryInterval,
889935
eventHandler,
890936
eventProcessor,
891937
userProfileService,

0 commit comments

Comments
 (0)