Search in sources :

Example 41 with FullSpec

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

the class JobDatabase method insertJobs.

public synchronized void insertJobs(@NonNull List<FullSpec> fullSpecs) {
    if (Stream.of(fullSpecs).map(FullSpec::getJobSpec).allMatch(JobSpec::isMemoryOnly)) {
        return;
    }
    SQLiteDatabase db = getWritableDatabase();
    db.beginTransaction();
    try {
        for (FullSpec fullSpec : fullSpecs) {
            insertJobSpec(db, fullSpec.getJobSpec());
            insertConstraintSpecs(db, fullSpec.getConstraintSpecs());
            insertDependencySpecs(db, fullSpec.getDependencySpecs());
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}
Also used : SQLiteDatabase(net.zetetic.database.sqlcipher.SQLiteDatabase) FullSpec(org.thoughtcrime.securesms.jobmanager.persistence.FullSpec) JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec)

Example 42 with FullSpec

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

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)

Aggregations

FullSpec (org.thoughtcrime.securesms.jobmanager.persistence.FullSpec)42 JobSpec (org.thoughtcrime.securesms.jobmanager.persistence.JobSpec)38 Test (org.junit.Test)32 Stream (com.annimon.stream.Stream)6 DependencySpec (org.thoughtcrime.securesms.jobmanager.persistence.DependencySpec)6 Application (android.app.Application)4 NonNull (androidx.annotation.NonNull)4 Nullable (androidx.annotation.Nullable)4 WorkerThread (androidx.annotation.WorkerThread)4 Collectors (com.annimon.stream.Collectors)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 List (java.util.List)4 Map (java.util.Map)4 Set (java.util.Set)4 Log (org.signal.core.util.logging.Log)4