Search in sources :

Example 61 with JobSpec

use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.

the class FastJobStorage method init.

@Override
public synchronized void init() {
    List<JobSpec> jobSpecs = jobDatabase.getAllJobSpecs();
    List<ConstraintSpec> constraintSpecs = jobDatabase.getAllConstraintSpecs();
    List<DependencySpec> dependencySpecs = jobDatabase.getAllDependencySpecs();
    jobs.addAll(jobSpecs);
    for (ConstraintSpec constraintSpec : constraintSpecs) {
        List<ConstraintSpec> jobConstraints = Util.getOrDefault(constraintsByJobId, constraintSpec.getJobSpecId(), new LinkedList<>());
        jobConstraints.add(constraintSpec);
        constraintsByJobId.put(constraintSpec.getJobSpecId(), jobConstraints);
    }
    for (DependencySpec dependencySpec : dependencySpecs) {
        List<DependencySpec> jobDependencies = Util.getOrDefault(dependenciesByJobId, dependencySpec.getJobId(), new LinkedList<>());
        jobDependencies.add(dependencySpec);
        dependenciesByJobId.put(dependencySpec.getJobId(), jobDependencies);
    }
}
Also used : ConstraintSpec(org.thoughtcrime.securesms.jobmanager.persistence.ConstraintSpec) DependencySpec(org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec)

Example 62 with JobSpec

use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.

the class FastJobStorage method updateAllJobsToBePending.

@Override
public synchronized void updateAllJobsToBePending() {
    jobDatabase.updateAllJobsToBePending();
    ListIterator<JobSpec> iter = jobs.listIterator();
    while (iter.hasNext()) {
        JobSpec existing = iter.next();
        JobSpec updated = new JobSpec(existing.getId(), existing.getFactoryKey(), existing.getQueueKey(), existing.getCreateTime(), existing.getNextRunAttemptTime(), existing.getRunAttempt(), existing.getMaxAttempts(), existing.getLifespan(), existing.getSerializedData(), existing.getSerializedInputData(), false, existing.isMemoryOnly());
        iter.set(updated);
    }
}
Also used : JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec)

Example 63 with JobSpec

use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.

the class FastJobStorage method updateJobRunningState.

@Override
public synchronized void updateJobRunningState(@NonNull String id, boolean isRunning) {
    JobSpec job = getJobById(id);
    if (job == null || !job.isMemoryOnly()) {
        jobDatabase.updateJobRunningState(id, isRunning);
    }
    ListIterator<JobSpec> iter = jobs.listIterator();
    while (iter.hasNext()) {
        JobSpec existing = iter.next();
        if (existing.getId().equals(id)) {
            JobSpec updated = new JobSpec(existing.getId(), existing.getFactoryKey(), existing.getQueueKey(), existing.getCreateTime(), existing.getNextRunAttemptTime(), existing.getRunAttempt(), existing.getMaxAttempts(), existing.getLifespan(), existing.getSerializedData(), existing.getSerializedInputData(), isRunning, existing.isMemoryOnly());
            iter.set(updated);
        }
    }
}
Also used : JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec)

Example 64 with JobSpec

use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.

the class FastJobStorage method updateJobAfterRetry.

@Override
public synchronized void updateJobAfterRetry(@NonNull String id, boolean isRunning, int runAttempt, long nextRunAttemptTime, @NonNull String serializedData) {
    JobSpec job = getJobById(id);
    if (job == null || !job.isMemoryOnly()) {
        jobDatabase.updateJobAfterRetry(id, isRunning, runAttempt, nextRunAttemptTime, serializedData);
    }
    ListIterator<JobSpec> iter = jobs.listIterator();
    while (iter.hasNext()) {
        JobSpec existing = iter.next();
        if (existing.getId().equals(id)) {
            JobSpec updated = new JobSpec(existing.getId(), existing.getFactoryKey(), existing.getQueueKey(), existing.getCreateTime(), nextRunAttemptTime, runAttempt, existing.getMaxAttempts(), existing.getLifespan(), serializedData, existing.getSerializedInputData(), isRunning, existing.isMemoryOnly());
            iter.set(updated);
        }
    }
}
Also used : JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec)

Example 65 with JobSpec

use of org.thoughtcrime.securesms.jobmanager.persistence.JobSpec in project Signal-Android by signalapp.

the class JobController method getNextEligibleJobForExecution.

@WorkerThread
@Nullable
private Job getNextEligibleJobForExecution(@NonNull JobPredicate predicate) {
    List<JobSpec> jobSpecs = Stream.of(jobStorage.getPendingJobsWithNoDependenciesInCreatedOrder(System.currentTimeMillis())).filter(predicate::shouldRun).toList();
    for (JobSpec jobSpec : jobSpecs) {
        List<ConstraintSpec> constraintSpecs = jobStorage.getConstraintSpecs(jobSpec.getId());
        List<Constraint> constraints = Stream.of(constraintSpecs).map(ConstraintSpec::getFactoryKey).map(constraintInstantiator::instantiate).toList();
        if (Stream.of(constraints).allMatch(Constraint::isMet)) {
            return createJob(jobSpec, constraintSpecs);
        }
    }
    return null;
}
Also used : ConstraintSpec(org.thoughtcrime.securesms.jobmanager.persistence.ConstraintSpec) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Aggregations

JobSpec (org.thoughtcrime.securesms.jobmanager.persistence.JobSpec)66 FullSpec (org.thoughtcrime.securesms.jobmanager.persistence.FullSpec)38 Test (org.junit.Test)36 WorkerThread (androidx.annotation.WorkerThread)10 DependencySpec (org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec)10 ArrayList (java.util.ArrayList)8 LinkedList (java.util.LinkedList)8 ConstraintSpec (org.thoughtcrime.securesms.jobmanager.persistence.ConstraintSpec)8 Nullable (androidx.annotation.Nullable)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 List (java.util.List)6 Map (java.util.Map)6 JobStorage (org.thoughtcrime.securesms.jobmanager.persistence.JobStorage)6 Application (android.app.Application)4 NonNull (androidx.annotation.NonNull)4 Collectors (com.annimon.stream.Collectors)4 Stream (com.annimon.stream.Stream)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4