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(); EventBus eventBus = new EventBus();
CommandParserDispatcher dispatcher = new CommandParserDispatcher(); CommandParserDispatcher dispatcher = new CommandParserDispatcher();
SessionManager sessionManager = new SessionManager(eventBus, dispatcher);
ResponseDispatcher responseDispatcher = new ResponseDispatcher(sessionManager);
CommandRouter router = new CommandRouter(); CommandRouter router = new CommandRouter();
SessionManager sessionManager = new SessionManager(eventBus, dispatcher, router);
eventBus.subscribe(DisconnectEvent.class, event -> sessionManager.onDisconnect(event)); eventBus.subscribe(DisconnectEvent.class, event -> sessionManager.onDisconnect(event));
NetworkManager networkManager = new NetworkManager(port, sessionManager);
UserRegistry userRegistry = new UserRegistry(); UserRegistry userRegistry = new UserRegistry();
eventBus.subscribe( eventBus.subscribe(
@@ -71,10 +71,9 @@ public class ServerApp {
SESSION_DISCONNECT_JOB_PERIOD, SESSION_DISCONNECT_JOB_PERIOD,
TimeUnit.SECONDS); TimeUnit.SECONDS);
ResponseDispatcher responseDispatcher = new ResponseDispatcher(sessionManager);
registerCommands(dispatcher, router, responseDispatcher, userRegistry); registerCommands(dispatcher, router, responseDispatcher, userRegistry);
NetworkManager networkManager = new NetworkManager(port, sessionManager, router);
networkManager.start(); networkManager.start();
} }
@@ -1,5 +1,6 @@
package ch.unibas.dmi.dbis.cs108.casono.server.network; 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.sessions.SessionManager;
import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.TcpTransport; import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.TcpTransport;
import java.io.IOException; import java.io.IOException;
@@ -15,6 +16,7 @@ public class NetworkManager implements Runnable {
private Thread thread; private Thread thread;
private Boolean running; private Boolean running;
private SessionManager sessionManager; private SessionManager sessionManager;
private CommandRouter router;
/** /**
* Creates a new NetworkManager with the given port, session manager, and event bus. * 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 port the port to listen on
* @param sessionManager the session manager to use * @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.port = port;
this.logger = LogManager.getLogger(NetworkManager.class); this.logger = LogManager.getLogger(NetworkManager.class);
this.thread = new Thread(this, "networkManager"); this.thread = new Thread(this, "networkManager");
this.running = true; this.running = true;
this.sessionManager = sessionManager; this.sessionManager = sessionManager;
this.router = router;
} }
/** Starts the internal thread to accept new connections. */ /** Starts the internal thread to accept new connections. */
@@ -45,7 +48,7 @@ public class NetworkManager implements Runnable {
logger.debug("Accepted connection from {}", clientSocket.getRemoteSocketAddress()); logger.debug("Accepted connection from {}", clientSocket.getRemoteSocketAddress());
sessionManager.create(new TcpTransport(clientSocket)); sessionManager.create(new TcpTransport(clientSocket), router);
} }
} catch (IOException e) { } catch (IOException e) {
@@ -19,16 +19,13 @@ public class SessionManager {
private final EventBus eventBus; private final EventBus eventBus;
private final Logger logger; private final Logger logger;
private final CommandParserDispatcher dispatcher; private final CommandParserDispatcher dispatcher;
private final CommandRouter router;
/** Constructs a new SessionManager. */ /** Constructs a new SessionManager. */
public SessionManager( public SessionManager(EventBus eventBus, CommandParserDispatcher dispatcher) {
EventBus eventBus, CommandParserDispatcher dispatcher, CommandRouter router) {
this.sessions = new ConcurrentHashMap<>(); this.sessions = new ConcurrentHashMap<>();
this.eventBus = eventBus; this.eventBus = eventBus;
this.logger = LogManager.getLogger(SessionManager.class); this.logger = LogManager.getLogger(SessionManager.class);
this.dispatcher = dispatcher; this.dispatcher = dispatcher;
this.router = router;
} }
/** /**
@@ -37,9 +34,10 @@ public class SessionManager {
* <p>Will create both worker threads and start them. * <p>Will create both worker threads and start them.
* *
* @param transport to create session from * @param transport to create session from
* @param router the command router used by the created session
* @return newly 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); Session session = new Session(transport, eventBus, dispatcher, router);
SessionReader reader = new SessionReader(session, eventBus); SessionReader reader = new SessionReader(session, eventBus);
SessionWriter writer = new SessionWriter(session); SessionWriter writer = new SessionWriter(session);