Search in sources :

Example 1 with DependencySpec

use of org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec 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 DependencySpec

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

the class FastJobStorage method deleteJobs.

@Override
public synchronized void deleteJobs(@NonNull List<String> jobIds) {
    List<String> durableIds = new ArrayList<>(jobIds.size());
    for (String id : jobIds) {
        JobSpec job = getJobById(id);
        if (job == null || !job.isMemoryOnly()) {
            durableIds.add(id);
        }
    }
    if (durableIds.size() > 0) {
        jobDatabase.deleteJobs(durableIds);
    }
    Set<String> deleteIds = new HashSet<>(jobIds);
    Iterator<JobSpec> jobIter = jobs.iterator();
    while (jobIter.hasNext()) {
        if (deleteIds.contains(jobIter.next().getId())) {
            jobIter.remove();
        }
    }
    for (String jobId : jobIds) {
        constraintsByJobId.remove(jobId);
        dependenciesByJobId.remove(jobId);
        for (Map.Entry<String, List<DependencySpec>> entry : dependenciesByJobId.entrySet()) {
            Iterator<DependencySpec> depedencyIter = entry.getValue().iterator();
            while (depedencyIter.hasNext()) {
                if (depedencyIter.next().getDependsOnJobId().equals(jobId)) {
                    depedencyIter.remove();
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) DependencySpec(org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 3 with DependencySpec

use of org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec 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)

Example 4 with DependencySpec

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

the class FastJobStorageTest method getPendingJobsWithNoDependenciesInCreatedOrder_noneWhenDependentOnAnotherJob.

@Test
public void getPendingJobsWithNoDependenciesInCreatedOrder_noneWhenDependentOnAnotherJob() {
    FullSpec fullSpec1 = new FullSpec(new JobSpec("1", "f1", null, 0, 0, 0, 0, -1, EMPTY_DATA, null, true, false), Collections.emptyList(), Collections.emptyList());
    FullSpec fullSpec2 = new FullSpec(new JobSpec("2", "f2", null, 0, 0, 0, 0, -1, EMPTY_DATA, null, false, false), Collections.emptyList(), Collections.singletonList(new DependencySpec("2", "1", false)));
    FastJobStorage subject = new FastJobStorage(fixedDataDatabase(Arrays.asList(fullSpec1, fullSpec2)));
    subject.init();
    assertEquals(0, subject.getPendingJobsWithNoDependenciesInCreatedOrder(0).size());
}
Also used : FullSpec(org.thoughtcrime.securesms.jobmanager.persistence.FullSpec) DependencySpec(org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) Test(org.junit.Test)

Aggregations

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