mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-22 20:48:59 +00:00
(sys) Add springboard service that can spawn multiple different marginalia services to make distribution easier.
This commit is contained in:
parent
8c559c8121
commit
d2658d6f84
33
code/services-core/single-service-runner/build.gradle
Normal file
33
code/services-core/single-service-runner/build.gradle
Normal file
@ -0,0 +1,33 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'application'
|
||||
id 'jvm-test-suite'
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass = 'nu.marginalia.SingleService'
|
||||
applicationName = 'marginalia'
|
||||
}
|
||||
|
||||
tasks.distZip.enabled = false
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(22))
|
||||
}
|
||||
}
|
||||
|
||||
apply from: "$rootProject.projectDir/srcsets.gradle"
|
||||
|
||||
dependencies {
|
||||
implementation project(':code:services-core:query-service')
|
||||
implementation project(':code:services-core:index-service')
|
||||
implementation project(':code:services-core:control-service')
|
||||
implementation project(':code:services-core:executor-service')
|
||||
|
||||
testImplementation libs.bundles.slf4j.test
|
||||
testImplementation libs.bundles.junit
|
||||
testImplementation libs.mockito
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
package nu.marginalia;
|
||||
|
||||
public class SingleService {
|
||||
enum Service {
|
||||
IndexService("index", "nu.marginalia.index.IndexMain"),
|
||||
ControlService("control", "nu.marginalia.control.ControlMain"),
|
||||
ExecutorService("executor", "nu.marginalia.executor.ExecutorMain"),
|
||||
QueryService("query", "nu.marginalia.query.QueryMain"),
|
||||
;
|
||||
|
||||
public final String name;
|
||||
public final String className;
|
||||
|
||||
Service(String name, String className) {
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
/** Call the main method of the service class */
|
||||
public void run(String[] args) {
|
||||
try {
|
||||
// Use reflection to call the main method of the service class to avoid
|
||||
// loading all classes at startup time, which would invoke a bunch of contradictory
|
||||
// static initializers
|
||||
|
||||
Class<?> clazz = Class.forName(className);
|
||||
clazz.getMethod("main", String[].class).invoke(null, (Object) args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String... args) {
|
||||
if (args.length == 0) {
|
||||
System.out.println("Usage: SingleService <service> [args...]");
|
||||
}
|
||||
|
||||
String serviceName = args[0];
|
||||
String[] serviceArgs = new String[args.length - 1];
|
||||
System.arraycopy(args, 1, serviceArgs, 0, serviceArgs.length);
|
||||
|
||||
for (var service : Service.values()) {
|
||||
if (service.name.equals(serviceName)) {
|
||||
service.run(serviceArgs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ include 'code:services-core:assistant-service'
|
||||
include 'code:services-core:control-service'
|
||||
include 'code:services-core:query-service'
|
||||
include 'code:services-core:executor-service'
|
||||
include 'code:services-core:single-service-runner'
|
||||
|
||||
include 'code:services-application:search-service'
|
||||
include 'code:services-application:api-service'
|
||||
|
Loading…
Reference in New Issue
Block a user