From 6436ad0c2ff4fda27d7e7ed63c45632de1675103 Mon Sep 17 00:00:00 2001 From: Ivan Bodrov Date: Wed, 15 Nov 2023 19:54:24 -0500 Subject: [PATCH] concord-server: auto-wire modules in dist instead of impl Gives the option of excluding sisu from the classpath if auto-wiring is not required. --- .../testingserver/TestingConcordServer.java | 25 +++++++++++++++---- .../walmartlabs/concord/server/dist/Main.java | 13 ++++++++-- .../concord/server/ConcordServer.java | 14 ----------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/it/testing-server/src/main/java/com/walmartlabs/concord/it/testingserver/TestingConcordServer.java b/it/testing-server/src/main/java/com/walmartlabs/concord/it/testingserver/TestingConcordServer.java index e5d8acaebf..bcca549988 100644 --- a/it/testing-server/src/main/java/com/walmartlabs/concord/it/testingserver/TestingConcordServer.java +++ b/it/testing-server/src/main/java/com/walmartlabs/concord/it/testingserver/TestingConcordServer.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -40,10 +40,11 @@ public class TestingConcordServer implements AutoCloseable { + private final Map extraConfiguration; + private final List> extraModules; + private PostgreSQLContainer db; private ConcordServer server; - private Map extraConfiguration; - private List> extraModules; public TestingConcordServer(Map extraConfiguration, List> extraModules) { this.extraConfiguration = requireNonNull(extraConfiguration); @@ -119,10 +120,24 @@ private static String randomString() { return Base64.getEncoder().encodeToString(ab); } + /** + * Just an example. + */ public static void main(String[] args) throws Exception { try (TestingConcordServer server = new TestingConcordServer(Map.of("process.watchdogPeriod", "10 seconds"), List.of())) { server.start(); - Thread.sleep(100000); + + System.out.println(""" + ============================================================== + + UI: http://localhost:8001/ + DB: + JDBC URL: %s + username: %s + password: %s + """.formatted(server.getDb().getJdbcUrl(), server.getDb().getUsername(), server.getDb().getPassword())); + + Thread.currentThread().join(); } } } diff --git a/server/dist/src/main/java/com/walmartlabs/concord/server/dist/Main.java b/server/dist/src/main/java/com/walmartlabs/concord/server/dist/Main.java index 38627a69e4..d3cdd93996 100644 --- a/server/dist/src/main/java/com/walmartlabs/concord/server/dist/Main.java +++ b/server/dist/src/main/java/com/walmartlabs/concord/server/dist/Main.java @@ -22,6 +22,10 @@ import com.walmartlabs.concord.server.ConcordServer; import com.walmartlabs.concord.server.Version; +import org.eclipse.sisu.space.BeanScanning; +import org.eclipse.sisu.space.SpaceModule; +import org.eclipse.sisu.space.URLClassSpace; +import org.eclipse.sisu.wire.WireModule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.bridge.SLF4JBridgeHandler; @@ -38,10 +42,15 @@ public static void main(String[] args) throws Exception { long t1 = System.currentTimeMillis(); - ConcordServer.withAutoWiring() - .start(); + autoWire().start(); long t2 = System.currentTimeMillis(); log.info("main -> started in {}ms", (t2 - t1)); } + + public static ConcordServer autoWire() throws Exception { + // works as a plugin system by automatically wiring all @Named modules and beans in the classpath + ClassLoader cl = ConcordServer.class.getClassLoader(); + return ConcordServer.withModules(new WireModule(new SpaceModule(new URLClassSpace(cl), BeanScanning.GLOBAL_INDEX))); + } } diff --git a/server/impl/src/main/java/com/walmartlabs/concord/server/ConcordServer.java b/server/impl/src/main/java/com/walmartlabs/concord/server/ConcordServer.java index 333d8532ba..bbf0f63547 100644 --- a/server/impl/src/main/java/com/walmartlabs/concord/server/ConcordServer.java +++ b/server/impl/src/main/java/com/walmartlabs/concord/server/ConcordServer.java @@ -25,10 +25,6 @@ import com.google.inject.Module; import com.walmartlabs.concord.server.boot.BackgroundTasks; import com.walmartlabs.concord.server.boot.HttpServer; -import org.eclipse.sisu.space.BeanScanning; -import org.eclipse.sisu.space.SpaceModule; -import org.eclipse.sisu.space.URLClassSpace; -import org.eclipse.sisu.wire.WireModule; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,16 +47,6 @@ public final class ConcordServer { private final Object controlMutex = new Object(); - /** - * Start ConcordServer by scanning the local class path for the implementations of - * {@link HttpServer} or {@link BackgroundTasks}. - */ - public static ConcordServer withAutoWiring() throws Exception { - ClassLoader cl = ConcordServer.class.getClassLoader(); - return withModules( - new WireModule(new SpaceModule(new URLClassSpace(cl), BeanScanning.GLOBAL_INDEX))); - } - public static ConcordServer withModules(Module... modules) throws Exception { return withModules(List.of(modules)); }