discord-jadx/app/src/main/java/com/adjust/sdk/scheduler/TimerCycle.java

92 lines
3.2 KiB
Java

package com.adjust.sdk.scheduler;
import com.adjust.sdk.AdjustFactory;
import com.adjust.sdk.ILogger;
import com.adjust.sdk.Util;
import java.text.DecimalFormat;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
public class TimerCycle {
private Runnable command;
private long cycleDelay;
private long initialDelay;
private boolean isPaused = true;
private ILogger logger = AdjustFactory.getLogger();
private String name;
private FutureScheduler scheduler;
private ScheduledFuture waitingTask;
/* renamed from: com.adjust.sdk.scheduler.TimerCycle$1 reason: invalid class name */
public class AnonymousClass1 implements Runnable {
public AnonymousClass1() {
}
@Override // java.lang.Runnable
public void run() {
TimerCycle.access$100(TimerCycle.this).verbose("%s fired", TimerCycle.access$000(TimerCycle.this));
TimerCycle.access$200(TimerCycle.this).run();
}
}
public TimerCycle(Runnable runnable, long j, long j2, String str) {
this.scheduler = new SingleThreadFutureScheduler(str, true);
this.name = str;
this.command = runnable;
this.initialDelay = j;
this.cycleDelay = j2;
DecimalFormat decimalFormat = Util.SecondsDisplayFormat;
String format = decimalFormat.format(((double) j2) / 1000.0d);
this.logger.verbose("%s configured to fire after %s seconds of starting and cycles every %s seconds", str, decimalFormat.format(((double) j) / 1000.0d), format);
}
public static /* synthetic */ String access$000(TimerCycle timerCycle) {
return timerCycle.name;
}
public static /* synthetic */ ILogger access$100(TimerCycle timerCycle) {
return timerCycle.logger;
}
public static /* synthetic */ Runnable access$200(TimerCycle timerCycle) {
return timerCycle.command;
}
private void cancel(boolean z2) {
ScheduledFuture scheduledFuture = this.waitingTask;
if (scheduledFuture != null) {
scheduledFuture.cancel(z2);
}
this.waitingTask = null;
}
public void start() {
if (!this.isPaused) {
this.logger.verbose("%s is already started", this.name);
return;
}
this.logger.verbose("%s starting", this.name);
this.waitingTask = this.scheduler.scheduleFutureWithFixedDelay(new AnonymousClass1(), this.initialDelay, this.cycleDelay);
this.isPaused = false;
}
public void suspend() {
if (this.isPaused) {
this.logger.verbose("%s is already suspended", this.name);
return;
}
this.initialDelay = this.waitingTask.getDelay(TimeUnit.MILLISECONDS);
this.waitingTask.cancel(false);
this.logger.verbose("%s suspended with %s seconds left", this.name, Util.SecondsDisplayFormat.format(((double) this.initialDelay) / 1000.0d));
this.isPaused = true;
}
public void teardown() {
cancel(true);
FutureScheduler futureScheduler = this.scheduler;
if (futureScheduler != null) {
futureScheduler.teardown();
}
this.scheduler = null;
}
}