mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 13:19:02 +00:00

Look, this will make the git history look funny, but trimming unnecessary depth from the source tree is a very necessary sanity-preserving measure when dealing with a super-modularized codebase like this one. While it makes the project configuration a bit less conventional, it will save you several clicks every time you jump between modules. Which you'll do a lot, because it's *modul*ar. The src/main/java convention makes a lot of sense for a non-modular project though. This ain't that.
38 lines
1.1 KiB
Java
38 lines
1.1 KiB
Java
package nu.marginalia;
|
|
|
|
import com.google.inject.AbstractModule;
|
|
import com.google.inject.name.Names;
|
|
|
|
import java.util.UUID;
|
|
|
|
public class ProcessConfigurationModule extends AbstractModule {
|
|
private final String processName;
|
|
|
|
public ProcessConfigurationModule(String processName) {
|
|
this.processName = processName;
|
|
}
|
|
|
|
public void configure() {
|
|
bind(Integer.class).annotatedWith(Names.named("wmsa-system-node")).toInstance(getNode());
|
|
bind(ProcessConfiguration.class).toInstance(new ProcessConfiguration(processName, getNode(), UUID.randomUUID()));
|
|
}
|
|
|
|
private int getNode() {
|
|
|
|
String nodeEnv = System.getenv("WMSA_PROCESS_NODE");
|
|
|
|
if (null == nodeEnv) {
|
|
// fallback logic, try to inherit from parent
|
|
nodeEnv = System.getenv("WMSA_SERVICE_NODE");
|
|
}
|
|
|
|
//
|
|
if (null == nodeEnv) {
|
|
throw new IllegalStateException("Either WMSA_PROCESS_NODE or WMSA_SERVICE_NODE must be set, indicating the node affinity of the process!");
|
|
}
|
|
|
|
return Integer.parseInt(nodeEnv);
|
|
}
|
|
|
|
}
|