chore: move threaded mds into its own package
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
parent
aede030a7f
commit
aae97feeca
@ -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();
|
||||
|
@ -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;
|
@ -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;
|
@ -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;
|
@ -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;
|
||||
|
@ -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) {
|
Loading…
Reference in New Issue
Block a user