Search in sources :

Example 1 with JobSpec

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

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 2 with JobSpec

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

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 3 with JobSpec

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

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

the class JobController method update.

@WorkerThread
synchronized void update(@NonNull JobUpdater updater) {
    List<JobSpec> allJobs = jobStorage.getAllJobSpecs();
    List<JobSpec> updatedJobs = new LinkedList<>();
    for (JobSpec job : allJobs) {
        JobSpec updated = updater.update(job, dataSerializer);
        if (updated != job) {
            updatedJobs.add(updated);
        }
    }
    jobStorage.updateJobs(updatedJobs);
    notifyAll();
}
Also used : JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) LinkedList(java.util.LinkedList) WorkerThread(androidx.annotation.WorkerThread)

Example 5 with JobSpec

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

the class JobController method cancelJob.

@WorkerThread
synchronized void cancelJob(@NonNull String id) {
    Job runningJob = runningJobs.get(id);
    if (runningJob != null) {
        Log.w(TAG, JobLogger.format(runningJob, "Canceling while running."));
        runningJob.cancel();
    } else {
        JobSpec jobSpec = jobStorage.getJobSpec(id);
        if (jobSpec != null) {
            Job job = createJob(jobSpec, jobStorage.getConstraintSpecs(id));
            Log.w(TAG, JobLogger.format(job, "Canceling while inactive."));
            Log.w(TAG, JobLogger.format(job, "Job failed."));
            job.cancel();
            List<Job> dependents = onFailure(job);
            job.onFailure();
            Stream.of(dependents).forEach(Job::onFailure);
        } else {
            Log.w(TAG, "Tried to cancel JOB::" + id + ", but it could not be found.");
        }
    }
}
Also used : JobSpec(org.thoughtcrime.securesms.jobmanager.persistence.JobSpec) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

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