Search in sources :

Example 26 with JobManager

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

the class MessageRetrievalStrategy method blockUntilQueueDrained.

protected static void blockUntilQueueDrained(@NonNull String tag, @NonNull String queue, long timeoutMs) {
    long startTime = System.currentTimeMillis();
    final JobManager jobManager = ApplicationDependencies.getJobManager();
    final MarkerJob markerJob = new MarkerJob(queue);
    Optional<JobTracker.JobState> jobState = jobManager.runSynchronously(markerJob, timeoutMs);
    if (!jobState.isPresent()) {
        Log.w(tag, "Timed out waiting for " + queue + " job(s) to finish!");
    }
    long endTime = System.currentTimeMillis();
    long duration = endTime - startTime;
    Log.d(tag, "Waited " + duration + " ms for the " + queue + " job(s) to finish.");
}
Also used : JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) MarkerJob(org.thoughtcrime.securesms.jobs.MarkerJob)

Example 27 with JobManager

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

the class StorageCapabilityMigrationJob method performMigration.

@Override
public void performMigration() {
    JobManager jobManager = ApplicationDependencies.getJobManager();
    jobManager.add(new RefreshAttributesJob());
    if (TextSecurePreferences.isMultiDevice(context)) {
        Log.i(TAG, "Multi-device.");
        jobManager.startChain(new StorageForcePushJob()).then(new MultiDeviceKeysUpdateJob()).then(new MultiDeviceStorageSyncRequestJob()).enqueue();
    } else {
        Log.i(TAG, "Single-device.");
        jobManager.add(new StorageForcePushJob());
    }
}
Also used : StorageForcePushJob(org.thoughtcrime.securesms.jobs.StorageForcePushJob) RefreshAttributesJob(org.thoughtcrime.securesms.jobs.RefreshAttributesJob) MultiDeviceStorageSyncRequestJob(org.thoughtcrime.securesms.jobs.MultiDeviceStorageSyncRequestJob) MultiDeviceKeysUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceKeysUpdateJob) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager)

Example 28 with JobManager

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

the class RestStrategy method execute.

@WorkerThread
@Override
public boolean execute(long timeout) {
    long startTime = System.currentTimeMillis();
    JobManager jobManager = ApplicationDependencies.getJobManager();
    QueueFindingJobListener queueListener = new QueueFindingJobListener();
    try (IncomingMessageProcessor.Processor processor = ApplicationDependencies.getIncomingMessageProcessor().acquire()) {
        jobManager.addListener(job -> job.getParameters().getQueue() != null && job.getParameters().getQueue().startsWith(PushProcessMessageJob.QUEUE_PREFIX), queueListener);
        int jobCount = enqueuePushDecryptJobs(processor, startTime, timeout);
        if (jobCount == 0) {
            Log.d(TAG, "No PushDecryptMessageJobs were enqueued.");
            return true;
        } else {
            Log.d(TAG, jobCount + " PushDecryptMessageJob(s) were enqueued.");
        }
        long timeRemainingMs = blockUntilQueueDrained(PushDecryptMessageJob.QUEUE, TimeUnit.SECONDS.toMillis(10));
        Set<String> processQueues = queueListener.getQueues();
        Log.d(TAG, "Discovered " + processQueues.size() + " queue(s): " + processQueues);
        if (timeRemainingMs > 0) {
            Iterator<String> iter = processQueues.iterator();
            while (iter.hasNext() && timeRemainingMs > 0) {
                timeRemainingMs = blockUntilQueueDrained(iter.next(), timeRemainingMs);
            }
            if (timeRemainingMs <= 0) {
                Log.w(TAG, "Ran out of time while waiting for queues to drain.");
            }
        } else {
            Log.w(TAG, "Ran out of time before we could even wait on individual queues!");
        }
        return true;
    } catch (IOException e) {
        Log.w(TAG, "Failed to retrieve messages. Resetting the SignalServiceMessageReceiver.", e);
        ApplicationDependencies.resetSignalServiceMessageReceiver();
        return false;
    } finally {
        jobManager.removeListener(queueListener);
    }
}
Also used : JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) IOException(java.io.IOException) WorkerThread(androidx.annotation.WorkerThread)

Example 29 with JobManager

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

the class RestStrategy method blockUntilQueueDrained.

private static long blockUntilQueueDrained(@NonNull String queue, long timeoutMs) {
    long startTime = System.currentTimeMillis();
    final JobManager jobManager = ApplicationDependencies.getJobManager();
    final MarkerJob markerJob = new MarkerJob(queue);
    Optional<JobTracker.JobState> jobState = jobManager.runSynchronously(markerJob, timeoutMs);
    if (!jobState.isPresent()) {
        Log.w(TAG, "Timed out waiting for " + queue + " job(s) to finish!");
    }
    long endTime = System.currentTimeMillis();
    long duration = endTime - startTime;
    Log.d(TAG, "Waited " + duration + " ms for the " + queue + " job(s) to finish.");
    return timeoutMs - duration;
}
Also used : JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) MarkerJob(org.thoughtcrime.securesms.jobs.MarkerJob)

Example 30 with JobManager

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

the class StickerAdditionMigrationJob method performMigration.

@Override
public void performMigration() {
    JobManager jobManager = ApplicationDependencies.getJobManager();
    for (BlessedPacks.Pack pack : packs) {
        Log.i(TAG, "Installing reference for blessed pack: " + pack.getPackId());
        jobManager.add(StickerPackDownloadJob.forReference(pack.getPackId(), pack.getPackKey()));
    }
}
Also used : BlessedPacks(org.thoughtcrime.securesms.stickers.BlessedPacks) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager)

Aggregations

JobManager (org.thoughtcrime.securesms.jobmanager.JobManager)58 Job (org.thoughtcrime.securesms.jobmanager.Job)18 IOException (java.io.IOException)14 List (java.util.List)14 NonNull (androidx.annotation.NonNull)10 Log (org.signal.core.util.logging.Log)10 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)10 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)10 Recipient (org.thoughtcrime.securesms.recipients.Recipient)10 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)10 WorkerThread (androidx.annotation.WorkerThread)8 TimeUnit (java.util.concurrent.TimeUnit)8 Data (org.thoughtcrime.securesms.jobmanager.Data)8 NetworkConstraint (org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint)8 Application (android.app.Application)6 ArrayList (java.util.ArrayList)6 Collections (java.util.Collections)6 MessageId (org.thoughtcrime.securesms.database.model.MessageId)6 SmsSendJob (org.thoughtcrime.securesms.jobs.SmsSendJob)6 AttachmentCompressionJob (org.thoughtcrime.securesms.jobs.AttachmentCompressionJob)5