Style: Line length

This commit is contained in:
Lars Simon Winzer
2026-03-14 13:45:29 +01:00
parent 34c89b671e
commit 59494ea2d4
3 changed files with 10 additions and 5 deletions
@@ -9,11 +9,13 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.sessions.SessionManager;
public class ServerApp { public class ServerApp {
public static void start(String arg) { public static void start(String arg) {
int port = Integer.parseInt(arg); int port = Integer.parseInt(arg);
System.out.println("You've selected the server. It will accept connections at port " + port); System.out.println(
"You've selected the server. It will accept connections at port " + port);
EventBus eventBus = new EventBus(); EventBus eventBus = new EventBus();
SessionManager sessionManager = new SessionManager(); SessionManager sessionManager = new SessionManager();
eventBus.subscribe(DisconnectEvent.class, event -> sessionManager.removeSession(event.sessionId())); eventBus.subscribe(
DisconnectEvent.class, event -> sessionManager.removeSession(event.sessionId()));
NetworkManager networkManager = new NetworkManager(port, sessionManager, eventBus); NetworkManager networkManager = new NetworkManager(port, sessionManager, eventBus);
networkManager.start(); networkManager.start();
} }
@@ -59,7 +59,8 @@ public class NetworkManager implements Runnable {
while (running) { while (running) {
Socket clientSocket = serverSocket.accept(); Socket clientSocket = serverSocket.accept();
System.out.println("Accepted connection from " + clientSocket.getRemoteSocketAddress()); System.out.println(
"Accepted connection from " + clientSocket.getRemoteSocketAddress());
Session session = new Session(new TcpTransport(clientSocket), eventBus); Session session = new Session(new TcpTransport(clientSocket), eventBus);
sessionManager.addSession(session); sessionManager.addSession(session);
@@ -17,7 +17,9 @@ public class EventBus {
* @param eventType the class of the event to subscribe to * @param eventType the class of the event to subscribe to
* @param handler the consumer to handle the event * @param handler the consumer to handle the event
*/ */
@SuppressWarnings("unchecked") // This cast is safe, because handlers only get passed the type they subscribed to @SuppressWarnings(
"unchecked") // This cast is safe, because handlers only get passed the type they
// subscribed to
public <T extends Event> void subscribe(Class<T> eventType, Consumer<T> handler) { public <T extends Event> void subscribe(Class<T> eventType, Consumer<T> handler) {
handlers.computeIfAbsent(eventType, k -> new CopyOnWriteArrayList<>()) handlers.computeIfAbsent(eventType, k -> new CopyOnWriteArrayList<>())
.add((Consumer<Object>) (Consumer<?>) handler); .add((Consumer<Object>) (Consumer<?>) handler);