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);
}
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();
}
}
}
}
}
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);
}
}
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());
}
Aggregations