Skip to content

fix: change eventDispatcherInterval units for consistency #323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions android-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ dependencies {

testImplementation "junit:junit:$junit_ver"
testImplementation "org.mockito:mockito-core:$mockito_ver"
testImplementation "org.powermock:powermock-mockito-release-full:$powermock_ver"
testImplementation "com.noveogroup.android:android-logger:$android_logger_ver"

androidTestImplementation "com.android.support.test:runner:$support_test_runner_ver"
Expand All @@ -79,8 +80,9 @@ dependencies {
// Set this dependency to build and run Espresso tests
androidTestImplementation "com.android.support.test.espresso:espresso-core:$espresso_ver"
androidTestImplementation "org.mockito:mockito-core:$mockito_ver"
androidTestImplementation "com.google.dexmaker:dexmaker:$dexmaker_ver"
androidTestImplementation "com.google.dexmaker:dexmaker-mockito:$dexmaker_ver"
androidTestImplementation "com.crittercism.dexmaker:dexmaker:$dexmaker_ver"
androidTestImplementation "com.crittercism.dexmaker:dexmaker-dx:$dexmaker_ver"
androidTestImplementation "com.crittercism.dexmaker:dexmaker-mockito:$dexmaker_ver"
androidTestImplementation "com.noveogroup.android:android-logger:$android_logger_ver"
androidTestImplementation "com.google.code.gson:gson:$gson_ver"
androidTestImplementation "com.fasterxml.jackson.core:jackson-databind:$jacksonversion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.io.InputStream;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;


/**
Expand All @@ -68,7 +69,7 @@ public class OptimizelyManager {

@NonNull private DatafileHandler datafileHandler;
private final long datafileDownloadInterval;
private final long eventDispatchInterval;
private final long eventDispatchRetryInterval;
@Nullable private EventHandler eventHandler = null;
@Nullable private EventProcessor eventProcessor = null;
@Nullable private NotificationCenter notificationCenter = null;
Expand All @@ -89,7 +90,7 @@ public class OptimizelyManager {
long datafileDownloadInterval,
@NonNull DatafileHandler datafileHandler,
@Nullable ErrorHandler errorHandler,
long eventDispatchInterval,
long eventDispatchRetryInterval,
@NonNull EventHandler eventHandler,
@Nullable EventProcessor eventProcessor,
@NonNull UserProfileService userProfileService,
Expand All @@ -109,7 +110,7 @@ public class OptimizelyManager {
this.logger = logger;
this.datafileDownloadInterval = datafileDownloadInterval;
this.datafileHandler = datafileHandler;
this.eventDispatchInterval = eventDispatchInterval;
this.eventDispatchRetryInterval = eventDispatchRetryInterval;
this.eventHandler = eventHandler;
this.eventProcessor = eventProcessor;
this.errorHandler = errorHandler;
Expand Down Expand Up @@ -591,7 +592,7 @@ public UserProfileService getUserProfileService() {
protected EventHandler getEventHandler(Context context) {
if (eventHandler == null) {
DefaultEventHandler eventHandler = DefaultEventHandler.getInstance(context);
eventHandler.setDispatchInterval(eventDispatchInterval);
eventHandler.setDispatchInterval(eventDispatchRetryInterval);
this.eventHandler = eventHandler;
}

Expand Down Expand Up @@ -695,8 +696,10 @@ public static class Builder {

// -1 will cause the background download to not be initiated.
private long datafileDownloadInterval = -1L;
// -1 will cause the background download to not be initiated.
private long eventDispatchInterval = -1L;
// -1 will disable event batching.
private long eventFlushInterval = -1L;
// -l will disable periodic retries on event dispatch failures (but queued and retried on next event dispatch request)
private long eventDispatchRetryInterval = -1L;
@Nullable private DatafileHandler datafileHandler = null;
@Nullable private Logger logger = null;
@Nullable private EventHandler eventHandler = null;
Expand All @@ -719,21 +722,6 @@ public static class Builder {
this.projectId = null;
}


/**
* Sets the interval which {@link DatafileService} through the {@link DatafileHandler} will attempt to update the
* cached datafile. If you set this to -1, you disable background updates. If you don't set
* a download interval (or set to less than 0), then no background updates will be scheduled or occur.
* The minimum interval is 900 secs (15 minutes) (enforced by the Android JobScheduler API. See {@link android.app.job.JobInfo})
*
* @param interval the interval in seconds
* @return this {@link Builder} instance
*/
public Builder withDatafileDownloadInterval(long interval) {
this.datafileDownloadInterval = interval;
return this;
}

/**
* Override the default {@link DatafileHandler}.
* @param overrideHandler datafile handler to replace default handler
Expand Down Expand Up @@ -770,18 +758,76 @@ public Builder withErrorHandler(ErrorHandler errorHandler) {
}

/**
* Sets the interval which {@link EventIntentService} will flush events.
* If you set this to -1, you disable background updates. If you don't set
* a event dispatch interval, then no background updates will be scheduled or occur.
* Sets the interval which {@link DatafileService} through the {@link DatafileHandler} will attempt to update the
* cached datafile. If you set this to -1, you disable background updates. If you don't set
* a download interval (or set to less than 0), then no background updates will be scheduled or occur.
* The minimum interval is 15 minutes (enforced by the Android JobScheduler API. See {@link android.app.job.JobInfo})
*
* @param interval the interval
* @param timeUnit the time unit of the timeout argument
* @return this {@link Builder} instance
*/
public Builder withDatafileDownloadInterval(long interval, TimeUnit timeUnit) {
this.datafileDownloadInterval = interval > 0 ? timeUnit.toSeconds(interval) : interval;
return this;
}

/**
* Sets the interval which {@link DatafileService} through the {@link DatafileHandler} will attempt to update the
* cached datafile. If you set this to -1, you disable background updates. If you don't set
* a download interval (or set to less than 0), then no background updates will be scheduled or occur.
* The minimum interval is 900 secs (15 minutes) (enforced by the Android JobScheduler API. See {@link android.app.job.JobInfo})
*
* @param interval the interval in seconds
* @return this {@link Builder} instance
*/
@Deprecated
public Builder withDatafileDownloadInterval(long interval) {
this.datafileDownloadInterval = interval;
return this;
}

/**
* Sets the interval which queued events will be flushed periodically.
* If you don't set this value or set this to -1, the default interval will be used (30 seconds).
*
* @param interval the interval
* @param timeUnit the time unit of the timeout argument
* @return this {@link Builder} instance
*/
public Builder withEventDispatchInterval(long interval, TimeUnit timeUnit) {
this.eventFlushInterval = interval > 0 ? timeUnit.toMillis(interval) : interval;
return this;
}

/**
* Sets the interval which {@link EventIntentService} will retry event dispatch periodically.
* 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)
*
* @param interval the interval
* @param timeUnit the time unit of the timeout argument
* @return this {@link Builder} instance
*/
public Builder withEventDispatchRetryInterval(long interval, TimeUnit timeUnit) {
this.eventDispatchRetryInterval = interval > 0 ? timeUnit.toMillis(interval) : interval;
return this;
}

/**
* Sets the interval which {@link EventIntentService} will retry event dispatch periodically.
* 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)
*
* @param interval the interval in milliseconds
* @return this {@link Builder} instance
*/
@Deprecated
public Builder withEventDispatchInterval(long interval) {
this.eventDispatchInterval = interval;
this.eventFlushInterval = interval;
this.eventDispatchRetryInterval = interval;
return this;
}


/**
* Override the default {@link EventHandler}.
*
Expand Down Expand Up @@ -869,7 +915,7 @@ public OptimizelyManager build(Context context) {
eventProcessor = BatchEventProcessor.builder()
.withNotificationCenter(notificationCenter)
.withEventHandler(eventHandler)
.withFlushInterval(eventDispatchInterval)
.withFlushInterval(eventFlushInterval)
.build();

}
Expand All @@ -885,7 +931,7 @@ public OptimizelyManager build(Context context) {
datafileDownloadInterval,
datafileHandler,
errorHandler,
eventDispatchInterval,
eventDispatchRetryInterval,
eventHandler,
eventProcessor,
userProfileService,
Expand Down
Loading