/** * Overrides the executor service for all parallel execution. This could be helpful for Espresso * tests. * * @param executorService The new executor service. */ public static void setExecutorService(@NonNull ExecutorService executorService) { JobConfig.executorService = JobPreconditions.checkNotNull(executorService); }
/** * Change the back-off policy for a non periodic job. The default value is set to 30 seconds * and {@link BackoffPolicy#EXPONENTIAL}. The time is increasing each time a job fails and * returns {@link Job.Result#RESCHEDULE}, but capped at 5 hours. * * <br> * <br> * * Note that it's not allowed to change the back-off criteria for a periodic job. * * @param backoffMs The initial interval to wait when the job has been rescheduled. * @param backoffPolicy Is either {@link BackoffPolicy#LINEAR} or {@link BackoffPolicy#EXPONENTIAL}. * @see Job.Result#RESCHEDULE * @see Job#onReschedule(int) */ public Builder setBackoffCriteria(long backoffMs, @NonNull BackoffPolicy backoffPolicy) { mBackoffMs = JobPreconditions.checkArgumentPositive(backoffMs, "backoffMs must be > 0"); mBackoffPolicy = JobPreconditions.checkNotNull(backoffPolicy); return this; }
/** * Helper method to schedule a request on a background thread. This is helpful to avoid IO operations * on the main thread. The callback notifies you about the job ID or a possible failure. * * @param callback The callback which is invoked after the request has been scheduled. */ public void scheduleAsync(@NonNull final JobScheduledCallback callback) { JobPreconditions.checkNotNull(callback); JobConfig.getExecutorService().execute(new Runnable() { @Override public void run() { try { int jobId = schedule(); callback.onJobScheduled(jobId, getTag(), null); } catch (Exception e) { callback.onJobScheduled(JobScheduledCallback.JOB_ID_ERROR, getTag(), e); } } }); }
/** * Helper method to schedule a daily job on a background thread. This is helpful to avoid IO operations * on the main thread. The callback notifies you about the job ID or a possible failure. For more * information about scheduling daily jobs see {@link #schedule(JobRequest.Builder, long, long)}. * * @param callback The callback which is invoked after the request has been scheduled. */ public static void scheduleAsync(@NonNull final JobRequest.Builder baseBuilder, final long startMs, final long endMs, @NonNull final JobRequest.JobScheduledCallback callback) { JobPreconditions.checkNotNull(callback); JobConfig.getExecutorService().execute(new Runnable() { @Override public void run() { try { int jobId = schedule(baseBuilder, startMs, endMs); callback.onJobScheduled(jobId, baseBuilder.mTag, null); } catch (Exception e) { callback.onJobScheduled(JobRequest.JobScheduledCallback.JOB_ID_ERROR, baseBuilder.mTag, e); } } }); }
checkNotNull(value, valueName + " must not be null");
synchronized (JobManager.class) { if (instance == null) { JobPreconditions.checkNotNull(context, "Context cannot be null");
JobPreconditions.checkNotEmpty(mTag); JobPreconditions.checkArgumentPositive(mBackoffMs, "backoffMs must be > 0"); JobPreconditions.checkNotNull(mBackoffPolicy); JobPreconditions.checkNotNull(mNetworkType);
/** * Overrides the executor service for all parallel execution. This could be helpful for Espresso * tests. * * @param executorService The new executor service. */ public static void setExecutorService(@NonNull ExecutorService executorService) { JobConfig.executorService = JobPreconditions.checkNotNull(executorService); }
/** * Helper method to schedule a request on a background thread. This is helpful to avoid IO operations * on the main thread. The callback notifies you about the job ID or a possible failure. * * @param callback The callback which is invoked after the request has been scheduled. */ public void scheduleAsync(@NonNull final JobScheduledCallback callback) { JobPreconditions.checkNotNull(callback); JobConfig.getExecutorService().execute(new Runnable() { @Override public void run() { try { int jobId = schedule(); callback.onJobScheduled(jobId, getTag(), null); } catch (Exception e) { callback.onJobScheduled(JobScheduledCallback.JOB_ID_ERROR, getTag(), e); } } }); }
/** * Change the back-off policy for a non periodic job. The default value is set to 30 seconds * and {@link BackoffPolicy#EXPONENTIAL}. The time is increasing each time a job fails and * returns {@link Job.Result#RESCHEDULE}, but capped at 5 hours. * * <br> * <br> * * Note that it's not allowed to change the back-off criteria for a periodic job. * * @param backoffMs The initial interval to wait when the job has been rescheduled. * @param backoffPolicy Is either {@link BackoffPolicy#LINEAR} or {@link BackoffPolicy#EXPONENTIAL}. * @see Job.Result#RESCHEDULE * @see Job#onReschedule(int) */ public Builder setBackoffCriteria(long backoffMs, @NonNull BackoffPolicy backoffPolicy) { mBackoffMs = JobPreconditions.checkArgumentPositive(backoffMs, "backoffMs must be > 0"); mBackoffPolicy = JobPreconditions.checkNotNull(backoffPolicy); return this; }
/** * Helper method to schedule a daily job on a background thread. This is helpful to avoid IO operations * on the main thread. The callback notifies you about the job ID or a possible failure. For more * information about scheduling daily jobs see {@link #schedule(JobRequest.Builder, long, long)}. * * @param callback The callback which is invoked after the request has been scheduled. */ public static void scheduleAsync(@NonNull final JobRequest.Builder baseBuilder, final long startMs, final long endMs, @NonNull final JobRequest.JobScheduledCallback callback) { JobPreconditions.checkNotNull(callback); JobConfig.getExecutorService().execute(new Runnable() { @Override public void run() { try { int jobId = schedule(baseBuilder, startMs, endMs); callback.onJobScheduled(jobId, baseBuilder.mTag, null); } catch (Exception e) { callback.onJobScheduled(JobRequest.JobScheduledCallback.JOB_ID_ERROR, baseBuilder.mTag, e); } } }); }
checkNotNull(value, valueName + " must not be null");
synchronized (JobManager.class) { if (instance == null) { JobPreconditions.checkNotNull(context, "Context cannot be null");
JobPreconditions.checkNotEmpty(mTag); JobPreconditions.checkArgumentPositive(mBackoffMs, "backoffMs must be > 0"); JobPreconditions.checkNotNull(mBackoffPolicy); JobPreconditions.checkNotNull(mNetworkType);