MarginaliaSearch/code/common/service/java/nu/marginalia/service/ConfigLoader.java
Viktor Lofgren 51e46ad2b0 (refac) Move export tasks to a process and clean up process initialization for all ProcessMainClass descendents
Since some of the export tasks have been memory hungry, sometimes killing the executor-services, they've been moved to a separate process that can be given a larger Xmx.

While doing this, the ProcessMainClass was given utilities for the boilerplate surrounding receiving mq requests and responding to them, some effort was also put toward making the process boot process a bit more uniform.  It's still a bit heterogeneous between different processes, but a bit less so for now.
2024-11-21 16:00:09 +01:00

37 lines
1.1 KiB
Java

package nu.marginalia.service;
import nu.marginalia.WmsaHome;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
public class ConfigLoader {
public static Path getConfigPath(String configName) {
return WmsaHome.getHomePath().resolve("conf/properties/" + configName + ".properties");
}
public static void loadConfig(Path configPath) {
if (!Files.exists(configPath)) {
System.err.println("No config file found at " + configPath);
return;
}
System.out.println("Loading config from " + configPath);
try (var is = Files.newInputStream(configPath)) {
var toLoad = new Properties();
toLoad.load(is);
for (var key : toLoad.keySet()) {
String k = (String) key;
System.out.println("Loading property " + k + " = " + toLoad.getProperty(k));
System.setProperty(k, toLoad.getProperty(k));
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}