Last commit

This commit is contained in:
Willem Cazander 2024-04-22 20:31:23 +02:00
parent a2a9a937a7
commit 0a14669566
6 changed files with 148 additions and 82 deletions

View file

@ -1,5 +1,11 @@
package love.distributedrebirth.no2all.zerofungus;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import love.distributedrebirth.no2all.react.nostr.client.NoStrRtsClient;
import love.distributedrebirth.no2all.react.nostr.server.NoStrRtsServer;
import love.distributedrebirth.no2all.react.nostr.server.relay.NoStrRtsServerRelay;
@ -14,43 +20,56 @@ import love.distributedrebirth.no2all.zerofungus.service.ZFunRtsConfigLogger;
//import ᒢᐩᐩ.ᔿᐤᒄʸ.ᣔᒃᣔᒼᓑᔆ.BãßBȍőnAbacusInstanceMBeanʸᴰ;
import love.distributedrebirth.no2all.zerofungus.service.ZFunRtsInitJdbc;
public enum ZeroFungus /*implements BãßBȍőnAbacusInstanceMBeanʸᴰ<ZeroFungus>*/ {
public enum ZeroFungus /* implements BãßBȍőnAbacusInstanceMBeanʸᴰ<ZeroFungus> */ {
INSTANCE;
private No2AllReactWarpCore foei = new No2AllReactWarpCore();
private List<ZFunRtsConfigJetty> jetties = new ArrayList<>();
public static void main(String[] args) {
Iterator<String> arguments = Arrays.asList(args).iterator();
boolean hasPort = arguments.hasNext() && arguments.next().equals("-p") && arguments.hasNext();
// config jetty
INSTANCE.jetties.clear();
if (hasPort) {
// note: multiple currently does not work...
INSTANCE.jetties.add(Arrays.asList(arguments.next().split(",")).stream().map(v -> Integer.parseInt(v)).findFirst().map(v -> new ZFunRtsConfigJetty(v)).get());
} else {
INSTANCE.jetties.add(new ZFunRtsConfigJetty(8080));
}
INSTANCE.start();
}
public void stop() {
//foei.fire(No2AllReactWarpCore.DILITHIUM, new Object());
jetties.forEach(v -> v.stop());
// foei.fire(No2AllReactWarpCore.DILITHIUM, new EjectWrapCoreShutdown());
}
public void start() {
// setup logger + warp monitor
foei.load(new ZFunRtsConfigLogger());
foei.load(new No2AllRtsWarpSpeedMonitor());
// add websocket wire support + log
foei.load(new No2AllRtsClient());
foei.load(new No2AllRtsServer());
foei.load(new No2AllRtsServerLog());
// add nostr support
foei.load(new NoStrRtsClient());
foei.load(new NoStrRtsServer());
foei.load(new NoStrRtsServerRelay());
foei.load(new NoStrRtsServerRelaySubs());
// config zero fungus servers and clients
foei.load(new ZFunRtsInitJdbc(foei));
foei.load(new ZFunRtsServer());
//foei.load(new ZFunRtsClientReplay());
// start jetty
foei.load(ZFunRtsConfigJetty.INSTANCE);
// foei.load(new ZFunRtsClientReplay());
// load jetties and join
jetties.forEach(v -> foei.load(v));
foei.load(new ZFunRtsServerBooted());
ZFunRtsConfigJetty.INSTANCE.join();
jetties.stream().findFirst().ifPresent(v -> v.join());
}
}

View file

@ -6,7 +6,6 @@ import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.server.CustomRequestLog;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
@ -31,8 +30,7 @@ import love.distributedrebirth.no2all.react.wire.server.No2AllRtsServer;
import love.distributedrebirth.no2all.wire.jetty.JettyWireServerEndpoint;
import love.distributedrebirth.no2all.zerofungus.web.RedirectServlet;
public enum ZFunRtsConfigJetty implements No2AllReactTypeScript {
INSTANCE;
public final class ZFunRtsConfigJetty implements No2AllReactTypeScript {
public static final No2AllReactSlot API = No2AllReactSlot.ofClass(ZFunRtsConfigJetty.class);
private static final Logger logger = Logger.getLogger(ZFunRtsConfigJetty.class.getName());
@ -41,27 +39,25 @@ public enum ZFunRtsConfigJetty implements No2AllReactTypeScript {
private JettyWireServerEndpoint endpoint1;
private JettyWireServerEndpoint endpoint2;
private JettyWireServerEndpoint endpoint3;
private ZFunRtsConfigJetty() {
public ZFunRtsConfigJetty(int port) {
server = new Server();
connector = new ServerConnector(server);
connector.setPort(port);
server.addConnector(connector);
}
@Override
public void onEvent(No2AllReactSlotSignal<No2AllReactSlotLoad> signal) {
logger.info(" ╦┌─┐╔╦╗╔╦╗┬ ┬ ╔═╗┌─┐╦ ╦╔═╗┬─┐┌┬┐");
logger.info(" ║├┤ ║ ║ └┬┘ ╠═╝│ │║║║║╣ ├┬┘ ││");
logger.info("╚╝└─┘ ╩ ╩ ┴ ╩ └─┘╚╩╝╚═╝┴└──┴┘");
connector.setPort(8080);
server.addConnector(connector);
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setBaseResource(buildBaseResource(getClass().getClassLoader()));
context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/target/classes/|.*\\.jar");
context.setConfigurations(new Configuration[]{
new AnnotationConfiguration(),
//new AnnotationConfiguration(),
new WebInfConfiguration(),
});
server.setHandler(context);
@ -105,14 +101,6 @@ public enum ZFunRtsConfigJetty implements No2AllReactTypeScript {
}
}
public void join() {
try {
server.join();
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
}
private Resource buildBaseResource(ClassLoader cl) {
try {
List<URL> paths = Collections.list(cl.getResources("META-INF/resources"));
@ -126,4 +114,20 @@ public enum ZFunRtsConfigJetty implements No2AllReactTypeScript {
throw new IllegalStateException(e);
}
}
public void join() {
try {
server.join();
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
}
public void stop() {
try {
server.stop();
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
}