Servermanager and default tcpserver

This commit is contained in:
Bas de Jong
2025-09-15 19:04:21 +02:00
parent e2268a5d71
commit fe17404e80
9 changed files with 4524 additions and 83 deletions

View File

@@ -2,65 +2,71 @@ package org.toop;
import org.toop.eventbus.Events;
import org.toop.eventbus.GlobalEventBus;
import org.toop.server.ServerConnection;
import org.toop.server.ServerManager;
import org.toop.server.backend.Testsss;
import org.toop.server.backend.ServerManager;
import org.toop.server.frontend.ConnectionManager;
import org.toop.server.backend.TcpServer;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
public class Main {
private static final Logger logger = LogManager.getLogger(Main.class);
public static void main(String[] args) throws ExecutionException, InterruptedException {
public static void main(String[] args) throws ExecutionException, InterruptedException, IOException {
TcpServer server = new TcpServer(5001);
Thread serverThread = new Thread(server);
serverThread.start();
// TcpServer server = new TcpServer(5001);
// Thread serverThread = new Thread(server);
// serverThread.start();
ServerManager serverManager = new ServerManager();
initSystems();
GlobalEventBus.post(new Events.ServerEvents.StartServer("5001"));
CompletableFuture<String> future = new CompletableFuture<>();
GlobalEventBus.post(new Events.ServerEvents.StartConnectionRequest("127.0.0.1", "5001", future));
String serverId = future.get();
logger.info("Server ID: " + serverId);
CompletableFuture<String> future2 = new CompletableFuture<>();
GlobalEventBus.post(new Events.ServerEvents.StartConnectionRequest("127.0.0.2", "5002", future2));
String serverId2 = future2.get();
logger.info("Server ID: " + serverId2);
// for (int i = 0; i < 1; i++) {
// Thread thread = new Thread(() -> {
//// logger.info("Server ID: {}", serverId);
// GlobalEventBus.post(new Events.ServerEvents.Command(serverId, "HELP", "TEST"));
// });
// thread.start();
// }
CompletableFuture<String> future3 = new CompletableFuture<>();
GlobalEventBus.post(new Events.ServerEvents.StartConnectionRequest("127.0.0.3", "5003", future3));
String serverId3 = future3.get();
logger.info("Server ID: " + serverId3);
GlobalEventBus.post(new Events.ServerEvents.Command(serverId, "HELP", "TEST"));
CompletableFuture<String> future4 = new CompletableFuture<>();
GlobalEventBus.post(new Events.ServerEvents.StartConnectionRequest("127.0.0.4", "5004", future4));
String serverId4 = future4.get();
logger.info("Server ID: " + serverId4);
GlobalEventBus.post(new Events.ServerEvents.ForceCloseAllConnections());
GlobalEventBus.post(new Events.ServerEvents.ForceCloseAllServers());
CompletableFuture<String> future5 = new CompletableFuture<>();
GlobalEventBus.post(new Events.ServerEvents.StartConnectionRequest("127.0.0.5", "5005", future5));
String serverId5 = future5.get();
logger.info("Server ID: " + serverId5);
//
// CompletableFuture<String> future2 = new CompletableFuture<>();
// GlobalEventBus.post(new Events.ServerEvents.StartConnectionRequest("127.0.0.1", "5001", future2));
// String serverId2 = future.get();
// logger.info("Server ID: {}", serverId2);
// GlobalEventBus.post(new Events.ServerEvents.Command(serverId2, "HELP", "TEST2"));
// GlobalEventBus.post(new Events.ServerEvents.StartConnection("127.0.0.1", "5001"));
// Server.startNew("127.0.0.1", "5001");
// Testsss.start(""); // Used for testing server.
Window.start("");
// Window.start("");
CompletableFuture<String> future6 = new CompletableFuture<>();
GlobalEventBus.post(new Events.ServerEvents.RequestsAllConnections(future6));
String serverConnections = future6.get();
logger.info("Running connections: {}", serverConnections);
// CompletableFuture<String> future6 = new CompletableFuture<>();
// GlobalEventBus.post(new Events.ServerEvents.RequestsAllConnections(future6));
// String serverConnections = future6.get();
// logger.info("Running connections: {}", serverConnections);
}
public static void initSystems() {
new ServerManager();
new ConnectionManager();
}
}