From ad62ab65917f27a7171b51f0c009f34387e98920 Mon Sep 17 00:00:00 2001 From: JFronny Date: Sat, 29 Jun 2024 20:24:45 +0200 Subject: [PATCH] chore: clean up some leftovers --- .../inceptum/launcher/system/mds/flow/FlowMds.java | 6 ++---- .../launcher/system/mds/flow/MdsDiscoverTask.java | 7 ++++--- .../system/mds/flow/MdsTaskRetryWrapper.java | 7 ++++--- .../ExponentialBackoff.java} | 12 ++++++++---- packaging/arch-linux | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) rename launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/{system/mds/flow/MdsRetryState.java => util/ExponentialBackoff.java} (59%) diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/FlowMds.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/FlowMds.java index 3a4b4e9..f45a683 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/FlowMds.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/FlowMds.java @@ -9,8 +9,7 @@ import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta; import io.gitlab.jfronny.inceptum.launcher.system.instance.ModPath; import io.gitlab.jfronny.inceptum.launcher.system.mds.*; import io.gitlab.jfronny.inceptum.launcher.system.mds.noop.NoopMod; -import io.gitlab.jfronny.inceptum.launcher.util.GameVersionParser; -import io.gitlab.jfronny.inceptum.launcher.util.VoidClaimPool; +import io.gitlab.jfronny.inceptum.launcher.util.*; import java.io.IOException; import java.nio.file.*; @@ -163,7 +162,7 @@ public class FlowMds implements ModsDirScanner { } } - private final HashMap timeouts = new HashMap<>(); + private final HashMap timeouts = new HashMap<>(); private void performScanTask(Map> discovered) throws IOException { if (!Files.isDirectory(instance.modsDir())) { return; @@ -200,7 +199,6 @@ public class FlowMds implements ModsDirScanner { Utils.LOGGER.error("Could not scan file for mod info", e); } } - runOnce(ScanStage.ALL, R::nop); } private Set getToScan() throws IOException { diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/MdsDiscoverTask.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/MdsDiscoverTask.java index 3ff7ce9..76ba70b 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/MdsDiscoverTask.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/MdsDiscoverTask.java @@ -7,13 +7,14 @@ import io.gitlab.jfronny.inceptum.launcher.model.inceptum.ModMeta; import io.gitlab.jfronny.inceptum.launcher.system.instance.ModPath; import io.gitlab.jfronny.inceptum.launcher.system.mds.*; import io.gitlab.jfronny.inceptum.launcher.system.mds.noop.NoopMod; +import io.gitlab.jfronny.inceptum.launcher.util.ExponentialBackoff; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; -public record MdsDiscoverTask(HashMap timeouts, ProtoInstance instance, String gameVersion) implements ThrowingFunction { +public record MdsDiscoverTask(HashMap timeouts, ProtoInstance instance, String gameVersion) implements ThrowingFunction { @Override public Mod apply(Path file) throws IOException { if (!Files.exists(file)) return null; @@ -25,8 +26,8 @@ public record MdsDiscoverTask(HashMap timeouts, ProtoInst private Mod discover(Path jarPath, Path imodPath) throws IOException { String key = imodPath.getFileName().toString() + "/" + MdsDiscoverTask.class.getTypeName(); - MdsRetryState state = timeouts.computeIfAbsent(key, _ -> new MdsRetryState()); - if (!state.shouldRetry()) return null; + ExponentialBackoff state = timeouts.computeIfAbsent(key, _ -> new ExponentialBackoff()); + if (!state.shouldTry()) return null; try { ModMeta meta; if (Files.exists(imodPath)) meta = GC_ModMeta.deserialize(imodPath, GsonPreset.CONFIG); diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/MdsTaskRetryWrapper.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/MdsTaskRetryWrapper.java index 5c48e14..3556181 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/MdsTaskRetryWrapper.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/MdsTaskRetryWrapper.java @@ -2,16 +2,17 @@ package io.gitlab.jfronny.inceptum.launcher.system.mds.flow; import io.gitlab.jfronny.commons.throwable.ThrowingConsumer; import io.gitlab.jfronny.inceptum.launcher.system.mds.MdsMod; +import io.gitlab.jfronny.inceptum.launcher.util.ExponentialBackoff; import java.io.IOException; import java.util.Map; -public record MdsTaskRetryWrapper(Map timeouts, ThrowingConsumer inner) implements ThrowingConsumer { +public record MdsTaskRetryWrapper(Map timeouts, ThrowingConsumer inner) implements ThrowingConsumer { @Override public void accept(MdsMod mod) throws IOException { String key = mod.getMetadataPath().getFileName().toString() + "/" + inner.getClass().getTypeName(); - MdsRetryState state = timeouts.computeIfAbsent(key, _ -> new MdsRetryState()); - if (!state.shouldRetry()) return; + ExponentialBackoff state = timeouts.computeIfAbsent(key, _ -> new ExponentialBackoff()); + if (!state.shouldTry()) return; try { inner.accept(mod); state.success(); diff --git a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/MdsRetryState.java b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/util/ExponentialBackoff.java similarity index 59% rename from launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/MdsRetryState.java rename to launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/util/ExponentialBackoff.java index 2c2eaa1..fe5fe77 100644 --- a/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/system/mds/flow/MdsRetryState.java +++ b/launcher/src/main/java/io/gitlab/jfronny/inceptum/launcher/util/ExponentialBackoff.java @@ -1,10 +1,14 @@ -package io.gitlab.jfronny.inceptum.launcher.system.mds.flow; +package io.gitlab.jfronny.inceptum.launcher.util; -public class MdsRetryState { +/** + * A simple class to manage exponential backoff. + * Used within the MDS to manage task retries. + */ +public class ExponentialBackoff { private int retries = 0; private long nextRetry = 0; - public boolean shouldRetry() { + public boolean shouldTry() { return retries == 0 || System.currentTimeMillis() > nextRetry; } @@ -13,7 +17,7 @@ public class MdsRetryState { } public void fail() { - retries++; nextRetry = System.currentTimeMillis() + (1L << retries) * 1000; + retries++; } } diff --git a/packaging/arch-linux b/packaging/arch-linux index 51000ec..2159562 160000 --- a/packaging/arch-linux +++ b/packaging/arch-linux @@ -1 +1 @@ -Subproject commit 51000ec505afe15dafc6c9476382a302c5093fd2 +Subproject commit 2159562d3cf32e48814e0913481f88e204ba27e9