60 lines
1.6 KiB
Java
60 lines
1.6 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* org.jspecify.annotations.Nullable
|
|
*/
|
|
package net.minecraft.client.telemetry.events;
|
|
|
|
import java.time.Duration;
|
|
import java.time.Instant;
|
|
import net.minecraft.client.telemetry.TelemetryEventSender;
|
|
import org.jspecify.annotations.Nullable;
|
|
|
|
public abstract class AggregatedTelemetryEvent {
|
|
private static final int SAMPLE_INTERVAL_MS = 60000;
|
|
private static final int SAMPLES_PER_EVENT = 10;
|
|
private int sampleCount;
|
|
private boolean ticking = false;
|
|
private @Nullable Instant lastSampleTime;
|
|
|
|
public void start() {
|
|
this.ticking = true;
|
|
this.lastSampleTime = Instant.now();
|
|
this.sampleCount = 0;
|
|
}
|
|
|
|
public void tick(TelemetryEventSender eventSender) {
|
|
if (this.shouldTakeSample()) {
|
|
this.takeSample();
|
|
++this.sampleCount;
|
|
this.lastSampleTime = Instant.now();
|
|
}
|
|
if (this.shouldSentEvent()) {
|
|
this.sendEvent(eventSender);
|
|
this.sampleCount = 0;
|
|
}
|
|
}
|
|
|
|
public boolean shouldTakeSample() {
|
|
return this.ticking && this.lastSampleTime != null && Duration.between(this.lastSampleTime, Instant.now()).toMillis() > 60000L;
|
|
}
|
|
|
|
public boolean shouldSentEvent() {
|
|
return this.sampleCount >= 10;
|
|
}
|
|
|
|
public void stop() {
|
|
this.ticking = false;
|
|
}
|
|
|
|
protected int getSampleCount() {
|
|
return this.sampleCount;
|
|
}
|
|
|
|
public abstract void takeSample();
|
|
|
|
public abstract void sendEvent(TelemetryEventSender var1);
|
|
}
|
|
|