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