// Path: shared/src/main/java/com/optimizely/ab/android/shared/WorkerScheduler.java
// public class WorkerScheduler {
//     // when true, work requested only when connection is available.
//     public static boolean requestOnlyWhenConnected = true;
// 
//     /**
//      * Unschedule a scheduled service for a given worker id
//      * @param context current application context
//      * @param workerId work id to cancel
//      */
//     public static void unscheduleService(Context context, String workerId) {
//         WorkManager.getInstance(context).cancelAllWorkByTag(workerId);
//     }
// 
//     /**
//      * Schedule a repeated service using the work scheduler from androidx.
//      * @param context current application context
//      * @param workerId worker id
//      * @param clazz class based on ListenableWorker
//      * @param data androidx.work.Data
//      * @param interval the interval for the repeated service
//      * @return An (WorkRequest, Operation) that can be used for tracing work state
//      */
//     public static AbstractMap.SimpleEntry<WorkRequest, Operation> scheduleService(Context context, String workerId, Class clazz, Data data, long interval) {
//         unscheduleService(context, workerId);
// 
//         long minutes = interval < 15 ? 15 : interval;
// 
//         WorkRequest.Builder workRequestBuilder = new PeriodicWorkRequest.Builder(clazz, minutes, TimeUnit.MINUTES)
//                 .addTag(workerId)
//                 .setInputData(data)
//                 .setInitialDelay(minutes, TimeUnit.MINUTES);
// 
//         if (requestOnlyWhenConnected) {
//              // requests only when connection is available (to control network connection failures)
//             Constraints constraints = new Constraints.Builder()
//                     .setRequiredNetworkType(NetworkType.CONNECTED)
//                     .build();
//             workRequestBuilder.setConstraints(constraints);
//         }
// 
//         WorkRequest workRequest = workRequestBuilder.build();
//         Operation operation = WorkManager.getInstance(context).enqueue(workRequest);
// 
//         return new AbstractMap.SimpleEntry<>(workRequest, operation);
//     }
// 
//     /**
//      * This method should be pulled out to a worker helper class.  This method uses the
//      * WorkManagerRequest
//      * @param context - application context
//      * @param workerId - the tag as well as unique identifier
//      * @param clazz - worker class
//      * @param data - input data for the worker
//      * @param retryInterval - the dispatch retry interval in milli-seconds
//      * @return An (WorkRequest, Operation) that can be used for tracing work state
//      */
//     public static AbstractMap.SimpleEntry<WorkRequest, Operation> startService(Context context, String workerId, Class clazz, Data data, Long retryInterval) {
//         // Create a WorkRequest for your Worker and sending it input
//         WorkRequest.Builder workRequestBuilder = new OneTimeWorkRequest.Builder(clazz)
//                 .setInputData(data)
//                 .addTag(workerId);
// 
//         if (requestOnlyWhenConnected) {
//             // requests only when connection is available (to control network connection failures)
//             Constraints constraints = new Constraints.Builder()
//                     .setRequiredNetworkType(NetworkType.CONNECTED)
//                     .build();
//             workRequestBuilder.setConstraints(constraints);
//         }
// 
//         if (retryInterval > 0) {
//             // NOTE: retry still enabled by default (LINEAR, 30secs) even when setBackoffCriteria is not called.
//             workRequestBuilder.setBackoffCriteria(
//                     BackoffPolicy.LINEAR,
//                     retryInterval,
//                     TimeUnit.MILLISECONDS);
//         }
// 
//         WorkRequest workRequest = workRequestBuilder.build();
//         Operation operation = WorkManager.getInstance(context).enqueue(workRequest);
// 
//         return new AbstractMap.SimpleEntry<>(workRequest, operation);
//     }
// 
// }


import android.content.Context;
import androidx.annotation.NonNull;
import androidx.work.Data;
import com.optimizely.ab.android.shared.WorkerScheduler;
import com.optimizely.ab.event.EventHandler;
import com.optimizely.ab.event.LogEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
     */
    public void setDispatchInterval(long dispatchInterval) {
        if (dispatchInterval <= 0) {
            this.dispatchInterval = -1;
        } else {
            this.dispatchInterval = dispatchInterval;
        }
    }

    /**
     * @see EventHandler#dispatchEvent(LogEvent)
     */
    @Override
    public void dispatchEvent(@NonNull LogEvent logEvent) {
        if (logEvent.getEndpointUrl() == null) {
            logger.error("Event dispatcher received a null url");
            return;
        }
        if (logEvent.getBody() == null) {
            logger.error("Event dispatcher received a null request body");
            return;
        }
        if (logEvent.getEndpointUrl().isEmpty()) {
            logger.error("Event dispatcher received an empty url");
        }

        // NOTE: retryInterval (dispatchInterval) is passed to WorkManager:
        // - in InputData to enable/disable retries
        // - in BackOffCriteria to change retry interval
        Data inputData = EventWorker.getData(logEvent, dispatchInterval);
// Path: shared/src/main/java/com/optimizely/ab/android/shared/WorkerScheduler.java
// public class WorkerScheduler {
//     // when true, work requested only when connection is available.
//     public static boolean requestOnlyWhenConnected = true;
// 
//     /**
//      * Unschedule a scheduled service for a given worker id
//      * @param context current application context
//      * @param workerId work id to cancel
//      */
//     public static void unscheduleService(Context context, String workerId) {
//         WorkManager.getInstance(context).cancelAllWorkByTag(workerId);
//     }
// 
//     /**
//      * Schedule a repeated service using the work scheduler from androidx.
//      * @param context current application context
//      * @param workerId worker id
//      * @param clazz class based on ListenableWorker
//      * @param data androidx.work.Data
//      * @param interval the interval for the repeated service
//      * @return An (WorkRequest, Operation) that can be used for tracing work state
//      */
//     public static AbstractMap.SimpleEntry<WorkRequest, Operation> scheduleService(Context context, String workerId, Class clazz, Data data, long interval) {
//         unscheduleService(context, workerId);
// 
//         long minutes = interval < 15 ? 15 : interval;
// 
//         WorkRequest.Builder workRequestBuilder = new PeriodicWorkRequest.Builder(clazz, minutes, TimeUnit.MINUTES)
//                 .addTag(workerId)
//                 .setInputData(data)
//                 .setInitialDelay(minutes, TimeUnit.MINUTES);
// 
//         if (requestOnlyWhenConnected) {
//              // requests only when connection is available (to control network connection failures)
//             Constraints constraints = new Constraints.Builder()
//                     .setRequiredNetworkType(NetworkType.CONNECTED)
//                     .build();
//             workRequestBuilder.setConstraints(constraints);
//         }
// 
//         WorkRequest workRequest = workRequestBuilder.build();
//         Operation operation = WorkManager.getInstance(context).enqueue(workRequest);
// 
//         return new AbstractMap.SimpleEntry<>(workRequest, operation);
//     }
// 
//     /**
//      * This method should be pulled out to a worker helper class.  This method uses the
//      * WorkManagerRequest
//      * @param context - application context
//      * @param workerId - the tag as well as unique identifier
//      * @param clazz - worker class
//      * @param data - input data for the worker
//      * @param retryInterval - the dispatch retry interval in milli-seconds
//      * @return An (WorkRequest, Operation) that can be used for tracing work state
//      */
//     public static AbstractMap.SimpleEntry<WorkRequest, Operation> startService(Context context, String workerId, Class clazz, Data data, Long retryInterval) {
//         // Create a WorkRequest for your Worker and sending it input
//         WorkRequest.Builder workRequestBuilder = new OneTimeWorkRequest.Builder(clazz)
//                 .setInputData(data)
//                 .addTag(workerId);
// 
//         if (requestOnlyWhenConnected) {
//             // requests only when connection is available (to control network connection failures)
//             Constraints constraints = new Constraints.Builder()
//                     .setRequiredNetworkType(NetworkType.CONNECTED)
//                     .build();
//             workRequestBuilder.setConstraints(constraints);
//         }
// 
//         if (retryInterval > 0) {
//             // NOTE: retry still enabled by default (LINEAR, 30secs) even when setBackoffCriteria is not called.
//             workRequestBuilder.setBackoffCriteria(
//                     BackoffPolicy.LINEAR,
//                     retryInterval,
//                     TimeUnit.MILLISECONDS);
//         }
// 
//         WorkRequest workRequest = workRequestBuilder.build();
//         Operation operation = WorkManager.getInstance(context).enqueue(workRequest);
// 
//         return new AbstractMap.SimpleEntry<>(workRequest, operation);
//     }
// 
// }


// Path: event-handler/src/main/java/com/optimizely/ab/android/event_handler/DefaultEventHandler.java
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.work.Data;
import com.optimizely.ab.android.shared.WorkerScheduler;
import com.optimizely.ab.event.EventHandler;
import com.optimizely.ab.event.LogEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

     */
    public void setDispatchInterval(long dispatchInterval) {
        if (dispatchInterval <= 0) {
            this.dispatchInterval = -1;
        } else {
            this.dispatchInterval = dispatchInterval;
        }
    }

    /**
     * @see EventHandler#dispatchEvent(LogEvent)
     */
    @Override
    public void dispatchEvent(@NonNull LogEvent logEvent) {
        if (logEvent.getEndpointUrl() == null) {
            logger.error("Event dispatcher received a null url");
            return;
        }
        if (logEvent.getBody() == null) {
            logger.error("Event dispatcher received a null request body");
            return;
        }
        if (logEvent.getEndpointUrl().isEmpty()) {
            logger.error("Event dispatcher received an empty url");
        }

        // NOTE: retryInterval (dispatchInterval) is passed to WorkManager:
        // - in InputData to enable/disable retries
        // - in BackOffCriteria to change retry interval
        Data inputData = EventWorker.getData(logEvent, dispatchInterval);
        WorkerScheduler.startService(context, EventWorker.workerId, EventWorker.class, inputData, dispatchInterval);