chore: clean up some leftovers
This commit is contained in:
parent
fabe5afed0
commit
ad62ab6591
@ -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.instance.ModPath;
|
||||||
import io.gitlab.jfronny.inceptum.launcher.system.mds.*;
|
import io.gitlab.jfronny.inceptum.launcher.system.mds.*;
|
||||||
import io.gitlab.jfronny.inceptum.launcher.system.mds.noop.NoopMod;
|
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.*;
|
||||||
import io.gitlab.jfronny.inceptum.launcher.util.VoidClaimPool;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
@ -163,7 +162,7 @@ public class FlowMds implements ModsDirScanner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final HashMap<String, MdsRetryState> timeouts = new HashMap<>();
|
private final HashMap<String, ExponentialBackoff> timeouts = new HashMap<>();
|
||||||
private void performScanTask(Map<ScanStage, ThrowingBiConsumer<Path, Mod, IOException>> discovered) throws IOException {
|
private void performScanTask(Map<ScanStage, ThrowingBiConsumer<Path, Mod, IOException>> discovered) throws IOException {
|
||||||
if (!Files.isDirectory(instance.modsDir())) {
|
if (!Files.isDirectory(instance.modsDir())) {
|
||||||
return;
|
return;
|
||||||
@ -200,7 +199,6 @@ public class FlowMds implements ModsDirScanner {
|
|||||||
Utils.LOGGER.error("Could not scan file for mod info", e);
|
Utils.LOGGER.error("Could not scan file for mod info", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
runOnce(ScanStage.ALL, R::nop);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<Path> getToScan() throws IOException {
|
private Set<Path> getToScan() throws IOException {
|
||||||
|
@ -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.instance.ModPath;
|
||||||
import io.gitlab.jfronny.inceptum.launcher.system.mds.*;
|
import io.gitlab.jfronny.inceptum.launcher.system.mds.*;
|
||||||
import io.gitlab.jfronny.inceptum.launcher.system.mds.noop.NoopMod;
|
import io.gitlab.jfronny.inceptum.launcher.system.mds.noop.NoopMod;
|
||||||
|
import io.gitlab.jfronny.inceptum.launcher.util.ExponentialBackoff;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public record MdsDiscoverTask(HashMap<String, MdsRetryState> timeouts, ProtoInstance instance, String gameVersion) implements ThrowingFunction<Path, Mod, IOException> {
|
public record MdsDiscoverTask(HashMap<String, ExponentialBackoff> timeouts, ProtoInstance instance, String gameVersion) implements ThrowingFunction<Path, Mod, IOException> {
|
||||||
@Override
|
@Override
|
||||||
public Mod apply(Path file) throws IOException {
|
public Mod apply(Path file) throws IOException {
|
||||||
if (!Files.exists(file)) return null;
|
if (!Files.exists(file)) return null;
|
||||||
@ -25,8 +26,8 @@ public record MdsDiscoverTask(HashMap<String, MdsRetryState> timeouts, ProtoInst
|
|||||||
|
|
||||||
private Mod discover(Path jarPath, Path imodPath) throws IOException {
|
private Mod discover(Path jarPath, Path imodPath) throws IOException {
|
||||||
String key = imodPath.getFileName().toString() + "/" + MdsDiscoverTask.class.getTypeName();
|
String key = imodPath.getFileName().toString() + "/" + MdsDiscoverTask.class.getTypeName();
|
||||||
MdsRetryState state = timeouts.computeIfAbsent(key, _ -> new MdsRetryState());
|
ExponentialBackoff state = timeouts.computeIfAbsent(key, _ -> new ExponentialBackoff());
|
||||||
if (!state.shouldRetry()) return null;
|
if (!state.shouldTry()) return null;
|
||||||
try {
|
try {
|
||||||
ModMeta meta;
|
ModMeta meta;
|
||||||
if (Files.exists(imodPath)) meta = GC_ModMeta.deserialize(imodPath, GsonPreset.CONFIG);
|
if (Files.exists(imodPath)) meta = GC_ModMeta.deserialize(imodPath, GsonPreset.CONFIG);
|
||||||
|
@ -2,16 +2,17 @@ package io.gitlab.jfronny.inceptum.launcher.system.mds.flow;
|
|||||||
|
|
||||||
import io.gitlab.jfronny.commons.throwable.ThrowingConsumer;
|
import io.gitlab.jfronny.commons.throwable.ThrowingConsumer;
|
||||||
import io.gitlab.jfronny.inceptum.launcher.system.mds.MdsMod;
|
import io.gitlab.jfronny.inceptum.launcher.system.mds.MdsMod;
|
||||||
|
import io.gitlab.jfronny.inceptum.launcher.util.ExponentialBackoff;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public record MdsTaskRetryWrapper(Map<String, MdsRetryState> timeouts, ThrowingConsumer<MdsMod, IOException> inner) implements ThrowingConsumer<MdsMod, IOException> {
|
public record MdsTaskRetryWrapper(Map<String, ExponentialBackoff> timeouts, ThrowingConsumer<MdsMod, IOException> inner) implements ThrowingConsumer<MdsMod, IOException> {
|
||||||
@Override
|
@Override
|
||||||
public void accept(MdsMod mod) throws IOException {
|
public void accept(MdsMod mod) throws IOException {
|
||||||
String key = mod.getMetadataPath().getFileName().toString() + "/" + inner.getClass().getTypeName();
|
String key = mod.getMetadataPath().getFileName().toString() + "/" + inner.getClass().getTypeName();
|
||||||
MdsRetryState state = timeouts.computeIfAbsent(key, _ -> new MdsRetryState());
|
ExponentialBackoff state = timeouts.computeIfAbsent(key, _ -> new ExponentialBackoff());
|
||||||
if (!state.shouldRetry()) return;
|
if (!state.shouldTry()) return;
|
||||||
try {
|
try {
|
||||||
inner.accept(mod);
|
inner.accept(mod);
|
||||||
state.success();
|
state.success();
|
||||||
|
@ -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 int retries = 0;
|
||||||
private long nextRetry = 0;
|
private long nextRetry = 0;
|
||||||
|
|
||||||
public boolean shouldRetry() {
|
public boolean shouldTry() {
|
||||||
return retries == 0 || System.currentTimeMillis() > nextRetry;
|
return retries == 0 || System.currentTimeMillis() > nextRetry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13,7 +17,7 @@ public class MdsRetryState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void fail() {
|
public void fail() {
|
||||||
retries++;
|
|
||||||
nextRetry = System.currentTimeMillis() + (1L << retries) * 1000;
|
nextRetry = System.currentTimeMillis() + (1L << retries) * 1000;
|
||||||
|
retries++;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1 +1 @@
|
|||||||
Subproject commit 51000ec505afe15dafc6c9476382a302c5093fd2
|
Subproject commit 2159562d3cf32e48814e0913481f88e204ba27e9
|
Loading…
Reference in New Issue
Block a user