chore: move threaded mds into its own package
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Johannes Frohnmeyer 2024-06-03 10:32:46 +02:00
parent aede030a7f
commit aae97feeca
Signed by: Johannes
GPG Key ID: E76429612C2929F4
6 changed files with 17 additions and 14 deletions

View File

@ -3,6 +3,7 @@ package io.gitlab.jfronny.inceptum.launcher.system.mds;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta;
import io.gitlab.jfronny.inceptum.launcher.system.instance.Mod;
import io.gitlab.jfronny.inceptum.launcher.system.mds.noop.NoopMds;
import io.gitlab.jfronny.inceptum.launcher.system.mds.threaded.ThreadedMds;
import io.gitlab.jfronny.inceptum.launcher.util.GameVersionParser;
import java.io.Closeable;
@ -14,12 +15,12 @@ import java.util.function.BiConsumer;
public interface ModsDirScanner extends Closeable {
static ModsDirScanner get(Path modsDir, InstanceMeta meta) throws IOException {
if (Files.exists(modsDir)) return ModsDirScannerImpl.get(modsDir, meta);
if (Files.exists(modsDir)) return ThreadedMds.get(modsDir, meta);
return new NoopMds(GameVersionParser.getGameVersion(meta.gameVersion));
}
static void closeAll() {
ModsDirScannerImpl.closeAll();
ThreadedMds.closeAll();
}
boolean isComplete();

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.inceptum.launcher.system.mds;
package io.gitlab.jfronny.inceptum.launcher.system.mds.threaded;
import io.gitlab.jfronny.gson.JsonParseException;
import io.gitlab.jfronny.inceptum.common.Utils;

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.inceptum.launcher.system.mds;
package io.gitlab.jfronny.inceptum.launcher.system.mds.threaded;
import io.gitlab.jfronny.inceptum.launcher.model.fabric.FabricModJson;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.GC_ModMeta;

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.inceptum.launcher.system.mds;
package io.gitlab.jfronny.inceptum.launcher.system.mds.threaded;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

View File

@ -1,6 +1,7 @@
package io.gitlab.jfronny.inceptum.launcher.system.mds;
package io.gitlab.jfronny.inceptum.launcher.system.mds.threaded;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta;
import io.gitlab.jfronny.inceptum.launcher.system.mds.ModsDirScanner;
import java.nio.file.Path;

View File

@ -1,4 +1,4 @@
package io.gitlab.jfronny.inceptum.launcher.system.mds;
package io.gitlab.jfronny.inceptum.launcher.system.mds.threaded;
import io.gitlab.jfronny.commons.io.JFiles;
import io.gitlab.jfronny.commons.ref.R;
@ -6,6 +6,7 @@ import io.gitlab.jfronny.inceptum.common.Utils;
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta;
import io.gitlab.jfronny.inceptum.launcher.system.instance.Mod;
import io.gitlab.jfronny.inceptum.launcher.system.instance.ModPath;
import io.gitlab.jfronny.inceptum.launcher.system.mds.ModsDirScanner;
import io.gitlab.jfronny.inceptum.launcher.system.mds.noop.NoopMod;
import io.gitlab.jfronny.inceptum.launcher.util.GameVersionParser;
@ -17,8 +18,8 @@ import java.util.function.BiConsumer;
import static java.nio.file.StandardWatchEventKinds.*;
class ModsDirScannerImpl implements ModsDirScanner {
private static final Map<Path, ModsDirScannerImpl> SCANNERS = new HashMap<>();
public class ThreadedMds implements ModsDirScanner {
private static final Map<Path, ThreadedMds> SCANNERS = new HashMap<>();
private static final ExecutorService POOL = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new NamedThreadFactory("mds"));
private final Map<Path, Mod> descriptions = new HashMap<>();
private final Set<Path> scannedPaths = new HashSet<>();
@ -27,20 +28,20 @@ class ModsDirScannerImpl implements ModsDirScanner {
private final WatchService service;
private boolean disposed = false;
private ModsDirScannerImpl(Path modsDir, InstanceMeta instance) throws IOException {
private ThreadedMds(Path modsDir, InstanceMeta instance) throws IOException {
this.instance = new ProtoInstance(modsDir, this, instance);
this.th = new Thread(this::scanTaskInternal, "mds-" + modsDir.getParent().getFileName());
this.service = FileSystems.getDefault().newWatchService();
modsDir.register(service, ENTRY_MODIFY, ENTRY_CREATE, ENTRY_DELETE);
}
protected static ModsDirScannerImpl get(Path modsDir, InstanceMeta instance) throws IOException {
public static ThreadedMds get(Path modsDir, InstanceMeta instance) throws IOException {
if (SCANNERS.containsKey(modsDir)) {
ModsDirScannerImpl mds = SCANNERS.get(modsDir);
ThreadedMds mds = SCANNERS.get(modsDir);
if (mds.instance.meta().equals(instance)) return mds;
mds.close();
}
ModsDirScannerImpl mds = new ModsDirScannerImpl(modsDir, instance);
ThreadedMds mds = new ThreadedMds(modsDir, instance);
SCANNERS.put(modsDir, mds);
return mds;
}
@ -150,7 +151,7 @@ class ModsDirScannerImpl implements ModsDirScanner {
}
public static void closeAll() {
for (ModsDirScannerImpl value : SCANNERS.values().toArray(ModsDirScannerImpl[]::new)) {
for (ThreadedMds value : SCANNERS.values().toArray(ThreadedMds[]::new)) {
try {
value.close();
} catch (IOException e) {