Search in sources :

Example 1 with ConstraintSpec

use of org.thoughtcrime.securesms.jobmanager.persistence.ConstraintSpec in project Signal-Android by WhisperSystems.

the class JobController method buildFullSpec.

@WorkerThread
@NonNull
private FullSpec buildFullSpec(@NonNull Job job, @NonNull Collection<String> dependsOn) {
    job.setRunAttempt(0);
    JobSpec jobSpec = new JobSpec(job.getId(), job.getFactoryKey(), job.getParameters().getQueue(), System.currentTimeMillis(), job.getNextRunAttemptTime(), job.getRunAttempt(), job.getParameters().getMaxAttempts(), job.getParameters().getLifespan(), dataSerializer.serialize(job.serialize()), null, false, job.getParameters().isMemoryOnly());
    List<ConstraintSpec> constraintSpecs = Stream.of(job.getParameters().getConstraintKeys()).map(key -> new ConstraintSpec(jobSpec.getId(), key, jobSpec.isMemoryOnly())).toList();
    List<DependencySpec> dependencySpecs = Stream.of(dependsOn).map(depends -> {
        JobSpec dependsOnJobSpec = jobStorage.getJobSpec(depends);
        boolean memoryOnly = job.getParameters().isMemoryOnly() || (dependsOnJobSpec != null && dependsOnJobSpec.isMemoryOnly());
        return new DependencySpec(job.getId(), depends, memoryOnly);
    }).toList();
    return new FullSpec(jobSpec, constraintSpecs, dependencySpecs);
}
Also used : JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) Collectors(com.annimon.stream.Collectors) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Collection(java.util.Collection) WorkerThread(androidx.annotation.WorkerThread) Set(java.util.Set) Debouncer(org.thoughtcrime.securesms.util.Debouncer) HashMap(java.util.HashMap) ConstraintSpec(org.thoughtcrime.securesms.jobmanager.persistence.ConstraintSpec) DependencySpec(org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Log(org.signal.core.util.logging.Log) List(java.util.List) Nullable(androidx.annotation.Nullable) Application(android.app.Application) FullSpec(org.thoughtcrime.securesms.jobmanager.persistence.FullSpec) Map(java.util.Map) JobStorage(org.thoughtcrime.securesms.jobmanager.persistence.JobStorage) LinkedList(java.util.LinkedList) Collections(java.util.Collections) ConstraintSpec(org.thoughtcrime.securesms.jobmanager.persistence.ConstraintSpec) DependencySpec(org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec) FullSpec(org.thoughtcrime.securesms.jobmanager.persistence.FullSpec) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 2 with ConstraintSpec

use of org.thoughtcrime.securesms.jobmanager.persistence.ConstraintSpec in project Signal-Android by WhisperSystems.

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)

Example 3 with ConstraintSpec

use of org.thoughtcrime.securesms.jobmanager.persistence.ConstraintSpec in project Signal-Android by WhisperSystems.

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)

Aggregations

ConstraintSpec (org.thoughtcrime.securesms.jobmanager.persistence.ConstraintSpec)3 JobSpec (org.thoughtcrime.securesms.jobmanager.persistence.JobSpec)3 Nullable (androidx.annotation.Nullable)2 WorkerThread (androidx.annotation.WorkerThread)2 DependencySpec (org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec)2 Application (android.app.Application)1 NonNull (androidx.annotation.NonNull)1 Collectors (com.annimon.stream.Collectors)1 Stream (com.annimon.stream.Stream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Log (org.signal.core.util.logging.Log)1 FullSpec (org.thoughtcrime.securesms.jobmanager.persistence.FullSpec)1