Add pre-execution checks with CommandHandlerExecutor to CommandHandler #242

Merged
lars.winzer merged 12 commits from feat/57-pre-execution-checks-for-commandhandler into main 2026-04-08 18:58:21 +02:00
3 changed files with 11 additions and 11 deletions
Showing only changes of commit a62da1235d - Show all commits
@@ -46,11 +46,11 @@ public class ServerApp {
EventBus eventBus = new EventBus();
CommandParserDispatcher dispatcher = new CommandParserDispatcher();
SessionManager sessionManager = new SessionManager(eventBus, dispatcher);
ResponseDispatcher responseDispatcher = new ResponseDispatcher(sessionManager);
CommandRouter router = new CommandRouter();
SessionManager sessionManager = new SessionManager(eventBus, dispatcher, router);
eventBus.subscribe(DisconnectEvent.class, event -> sessionManager.onDisconnect(event));
NetworkManager networkManager = new NetworkManager(port, sessionManager);
UserRegistry userRegistry = new UserRegistry();
eventBus.subscribe(
@@ -71,10 +71,9 @@ public class ServerApp {
SESSION_DISCONNECT_JOB_PERIOD,
TimeUnit.SECONDS);
ResponseDispatcher responseDispatcher = new ResponseDispatcher(sessionManager);
registerCommands(dispatcher, router, responseDispatcher, userRegistry);
NetworkManager networkManager = new NetworkManager(port, sessionManager, router);
networkManager.start();
}
@@ -1,5 +1,6 @@
package ch.unibas.dmi.dbis.cs108.casono.server.network;
import ch.unibas.dmi.dbis.cs108.casono.server.network.command.execution.CommandRouter;
import ch.unibas.dmi.dbis.cs108.casono.server.network.sessions.SessionManager;
import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.TcpTransport;
import java.io.IOException;
@@ -15,6 +16,7 @@ public class NetworkManager implements Runnable {
private Thread thread;
private Boolean running;
private SessionManager sessionManager;
private CommandRouter router;
/**
* Creates a new NetworkManager with the given port, session manager, and event bus.
@@ -22,12 +24,13 @@ public class NetworkManager implements Runnable {
* @param port the port to listen on
* @param sessionManager the session manager to use
*/
public NetworkManager(Integer port, SessionManager sessionManager) {
public NetworkManager(Integer port, SessionManager sessionManager, CommandRouter router) {
this.port = port;
this.logger = LogManager.getLogger(NetworkManager.class);
this.thread = new Thread(this, "networkManager");
this.running = true;
this.sessionManager = sessionManager;
this.router = router;
}
/** Starts the internal thread to accept new connections. */
@@ -45,7 +48,7 @@ public class NetworkManager implements Runnable {
logger.debug("Accepted connection from {}", clientSocket.getRemoteSocketAddress());
sessionManager.create(new TcpTransport(clientSocket));
sessionManager.create(new TcpTransport(clientSocket), router);
}
} catch (IOException e) {
@@ -19,16 +19,13 @@ public class SessionManager {
private final EventBus eventBus;
private final Logger logger;
private final CommandParserDispatcher dispatcher;
private final CommandRouter router;
/** Constructs a new SessionManager. */
public SessionManager(
EventBus eventBus, CommandParserDispatcher dispatcher, CommandRouter router) {
public SessionManager(EventBus eventBus, CommandParserDispatcher dispatcher) {
this.sessions = new ConcurrentHashMap<>();
this.eventBus = eventBus;
this.logger = LogManager.getLogger(SessionManager.class);
this.dispatcher = dispatcher;
this.router = router;
}
/**
@@ -37,9 +34,10 @@ public class SessionManager {
* <p>Will create both worker threads and start them.
*
* @param transport to create session from
* @param router the command router used by the created session
* @return newly created session
*/
public Session create(TransportLayer transport) {
public Session create(TransportLayer transport, CommandRouter router) {
Session session = new Session(transport, eventBus, dispatcher, router);
SessionReader reader = new SessionReader(session, eventBus);
SessionWriter writer = new SessionWriter(session);