style: rename backoffs
This commit is contained in:
parent
ad62ab6591
commit
9db150efe6
@ -162,7 +162,7 @@ public class FlowMds implements ModsDirScanner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final HashMap<String, ExponentialBackoff> timeouts = new HashMap<>();
|
private final HashMap<String, ExponentialBackoff> backoffs = 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;
|
||||||
@ -178,19 +178,19 @@ public class FlowMds implements ModsDirScanner {
|
|||||||
pipeline.addFeedbackTask(discovered.get(ScanStage.NONE));
|
pipeline.addFeedbackTask(discovered.get(ScanStage.NONE));
|
||||||
pipeline.addFeedbackTask(discovered.get(ScanStage.DISCOVER));
|
pipeline.addFeedbackTask(discovered.get(ScanStage.DISCOVER));
|
||||||
if (targetStage.contains(ScanStage.DOWNLOAD)) {
|
if (targetStage.contains(ScanStage.DOWNLOAD)) {
|
||||||
pipeline.addTask(ScanStage.DOWNLOAD, new MdsTaskRetryWrapper(timeouts, new MdsDownloadTask(instance)));
|
pipeline.addTask(ScanStage.DOWNLOAD, new MdsTaskRetryWrapper(backoffs, new MdsDownloadTask(instance)));
|
||||||
pipeline.addFeedbackTask(discovered.get(ScanStage.DOWNLOAD));
|
pipeline.addFeedbackTask(discovered.get(ScanStage.DOWNLOAD));
|
||||||
}
|
}
|
||||||
if (targetStage.contains(ScanStage.CROSSREFERENCE)) {
|
if (targetStage.contains(ScanStage.CROSSREFERENCE)) {
|
||||||
pipeline.addTask(ScanStage.CROSSREFERENCE, new MdsTaskRetryWrapper(timeouts, new MdsCrossReferenceTask(instance)));
|
pipeline.addTask(ScanStage.CROSSREFERENCE, new MdsTaskRetryWrapper(backoffs, new MdsCrossReferenceTask(instance)));
|
||||||
pipeline.addFeedbackTask(discovered.get(ScanStage.CROSSREFERENCE));
|
pipeline.addFeedbackTask(discovered.get(ScanStage.CROSSREFERENCE));
|
||||||
}
|
}
|
||||||
if (targetStage.contains(ScanStage.UPDATECHECK)) {
|
if (targetStage.contains(ScanStage.UPDATECHECK)) {
|
||||||
pipeline.addTask(ScanStage.UPDATECHECK, new MdsTaskRetryWrapper(timeouts, new MdsUpdateTask(instance, getGameVersion())));
|
pipeline.addTask(ScanStage.UPDATECHECK, new MdsTaskRetryWrapper(backoffs, new MdsUpdateTask(instance, getGameVersion())));
|
||||||
pipeline.addFeedbackTask(discovered.get(ScanStage.UPDATECHECK));
|
pipeline.addFeedbackTask(discovered.get(ScanStage.UPDATECHECK));
|
||||||
}
|
}
|
||||||
pipeline.addFeedbackTask(discovered.get(ScanStage.ALL));
|
pipeline.addFeedbackTask(discovered.get(ScanStage.ALL));
|
||||||
var futures1 = pipeline.run(factory, getToScan(), new MdsDiscoverTask(timeouts, instance, getGameVersion()));
|
var futures1 = pipeline.run(factory, getToScan(), new MdsDiscoverTask(backoffs, instance, getGameVersion()));
|
||||||
var futures2 = pipeline.run(factory, descriptions.entrySet().stream().map(Tuple::from).collect(Collectors.toSet()));
|
var futures2 = pipeline.run(factory, descriptions.entrySet().stream().map(Tuple::from).collect(Collectors.toSet()));
|
||||||
for (CompletableFuture<Void> future : Stream.concat(futures1.stream(), futures2.stream()).toList()) {
|
for (CompletableFuture<Void> future : Stream.concat(futures1.stream(), futures2.stream()).toList()) {
|
||||||
try {
|
try {
|
||||||
|
@ -14,7 +14,7 @@ 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, ExponentialBackoff> timeouts, ProtoInstance instance, String gameVersion) implements ThrowingFunction<Path, Mod, IOException> {
|
public record MdsDiscoverTask(HashMap<String, ExponentialBackoff> backoffs, 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;
|
||||||
@ -26,8 +26,8 @@ public record MdsDiscoverTask(HashMap<String, ExponentialBackoff> timeouts, Prot
|
|||||||
|
|
||||||
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();
|
||||||
ExponentialBackoff state = timeouts.computeIfAbsent(key, _ -> new ExponentialBackoff());
|
ExponentialBackoff backoff = backoffs.computeIfAbsent(key, _ -> new ExponentialBackoff());
|
||||||
if (!state.shouldTry()) return null;
|
if (!backoff.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);
|
||||||
@ -36,10 +36,10 @@ public record MdsDiscoverTask(HashMap<String, ExponentialBackoff> timeouts, Prot
|
|||||||
GC_ModMeta.serialize(meta, imodPath, GsonPreset.CONFIG);
|
GC_ModMeta.serialize(meta, imodPath, GsonPreset.CONFIG);
|
||||||
}
|
}
|
||||||
Mod result = new MdsMod(instance, imodPath, jarPath, meta);
|
Mod result = new MdsMod(instance, imodPath, jarPath, meta);
|
||||||
state.success();
|
backoff.success();
|
||||||
return result;
|
return result;
|
||||||
} catch (RuntimeException | IOException e) {
|
} catch (RuntimeException | IOException e) {
|
||||||
state.fail();
|
backoff.fail();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,17 +7,17 @@ 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, ExponentialBackoff> timeouts, ThrowingConsumer<MdsMod, IOException> inner) implements ThrowingConsumer<MdsMod, IOException> {
|
public record MdsTaskRetryWrapper(Map<String, ExponentialBackoff> backoffs, 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();
|
||||||
ExponentialBackoff state = timeouts.computeIfAbsent(key, _ -> new ExponentialBackoff());
|
ExponentialBackoff backoff = backoffs.computeIfAbsent(key, _ -> new ExponentialBackoff());
|
||||||
if (!state.shouldTry()) return;
|
if (!backoff.shouldTry()) return;
|
||||||
try {
|
try {
|
||||||
inner.accept(mod);
|
inner.accept(mod);
|
||||||
state.success();
|
backoff.success();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
state.fail();
|
backoff.fail();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user