use of com.birbit.android.jobqueue.scheduling.SchedulerConstraint in project android-priority-jobqueue by yigit.
the class JobManagerThread method scheduleWakeUpFor.
private void scheduleWakeUpFor(JobHolder holder, long now) {
if (scheduler == null) {
return;
}
int requiredNetwork = holder.requiredNetworkType;
long delayUntilNs = holder.getDelayUntilNs();
long deadlineNs = holder.getDeadlineNs();
long delay = delayUntilNs > now ? TimeUnit.NANOSECONDS.toMillis(delayUntilNs - now) : 0;
Long deadline = deadlineNs != Params.FOREVER ? TimeUnit.NANOSECONDS.toMillis(deadlineNs - now) : null;
boolean hasLargeDelay = delayUntilNs > now && delay >= JobManager.MIN_DELAY_TO_USE_SCHEDULER_IN_MS;
boolean hasLargeDeadline = deadline != null && deadline >= JobManager.MIN_DELAY_TO_USE_SCHEDULER_IN_MS;
if (requiredNetwork == NetworkUtil.DISCONNECTED && !hasLargeDelay && !hasLargeDeadline) {
return;
}
SchedulerConstraint constraint = new SchedulerConstraint(UUID.randomUUID().toString());
constraint.setNetworkStatus(requiredNetwork);
constraint.setDelayInMs(delay);
constraint.setOverrideDeadlineInMs(deadline);
scheduler.request(constraint);
shouldCancelAllScheduledWhenEmpty = true;
}
use of com.birbit.android.jobqueue.scheduling.SchedulerConstraint in project android-priority-jobqueue by yigit.
the class JobManagerThread method handleSchedulerStop.
private void handleSchedulerStop(SchedulerConstraint constraint) {
final List<SchedulerConstraint> pendingCallbacks = this.pendingSchedulerCallbacks;
if (pendingCallbacks != null) {
for (int i = pendingCallbacks.size() - 1; i >= 0; i--) {
SchedulerConstraint pendingConstraint = pendingCallbacks.get(i);
if (pendingConstraint.getUuid().equals(constraint.getUuid())) {
pendingCallbacks.remove(i);
}
}
}
if (scheduler == null) {
//nothing to do
return;
}
final boolean hasMatchingJobs = hasJobsWithSchedulerConstraint(constraint);
if (hasMatchingJobs) {
// reschedule
scheduler.request(constraint);
}
}
use of com.birbit.android.jobqueue.scheduling.SchedulerConstraint in project android-priority-jobqueue by yigit.
the class BatchingSchedulerTest method testAddOne.
@Test
public void testAddOne() {
SchedulerConstraint constraint = new SchedulerConstraint("abc");
constraint.setDelayInMs(0);
constraint.setNetworkStatus(NetworkUtil.DISCONNECTED);
bs.request(constraint);
verify(scheduler, times(1)).request(constraint);
MatcherAssert.assertThat(constraint.getDelayInMs(), CoreMatchers.is(DEFAULT_BATCHING_PERIOD_IN_MS));
}
use of com.birbit.android.jobqueue.scheduling.SchedulerConstraint in project android-priority-jobqueue by yigit.
the class BatchingSchedulerTest method testAddTwoWithDifferentNetwork.
@Test
public void testAddTwoWithDifferentNetwork() {
SchedulerConstraint constraint = createConstraint(NetworkUtil.METERED, 0);
bs.request(constraint);
SchedulerConstraint constraint2 = createConstraint(NetworkUtil.UNMETERED, 0);
bs.request(constraint2);
verify(scheduler, times(1)).request(constraint);
verify(scheduler, times(1)).request(constraint2);
MatcherAssert.assertThat(constraint.getDelayInMs(), CoreMatchers.is(DEFAULT_BATCHING_PERIOD_IN_MS));
MatcherAssert.assertThat(constraint2.getDelayInMs(), CoreMatchers.is(DEFAULT_BATCHING_PERIOD_IN_MS));
}
use of com.birbit.android.jobqueue.scheduling.SchedulerConstraint in project android-priority-jobqueue by yigit.
the class BatchingSchedulerTest method testAddTwoOfTheSameWithEnoughTimeDifference.
@Test
public void testAddTwoOfTheSameWithEnoughTimeDifference() {
SchedulerConstraint constraint = createConstraint(NetworkUtil.METERED, 0);
bs.request(constraint);
timer.incrementMs(DEFAULT_BATCHING_PERIOD_IN_MS);
SchedulerConstraint constraint2 = createConstraint(NetworkUtil.METERED, 0);
bs.request(constraint2);
verify(scheduler, times(1)).request(constraint);
verify(scheduler, times(1)).request(constraint2);
MatcherAssert.assertThat(constraint.getDelayInMs(), CoreMatchers.is(DEFAULT_BATCHING_PERIOD_IN_MS));
MatcherAssert.assertThat(constraint2.getDelayInMs(), CoreMatchers.is(DEFAULT_BATCHING_PERIOD_IN_MS));
}
Aggregations