From 14a8e07b915983dc6d790f293c373825db4f9280 Mon Sep 17 00:00:00 2001 From: aleandro Date: Wed, 10 Jun 2026 16:53:47 +0200 Subject: [PATCH] Fix: useless interface removed --- .../polimi/ingsw/gc14/GameEventProcessor.java | 6 ++-- .../ingsw/gc14/Network/ClientBroadcaster.java | 34 ------------------- .../Network/CompositeClientBroadcaster.java | 15 +++----- .../it/polimi/ingsw/gc14/ServerLauncher.java | 5 ++- 4 files changed, 9 insertions(+), 51 deletions(-) delete mode 100644 src/main/java/it/polimi/ingsw/gc14/Network/ClientBroadcaster.java diff --git a/src/main/java/it/polimi/ingsw/gc14/GameEventProcessor.java b/src/main/java/it/polimi/ingsw/gc14/GameEventProcessor.java index 2e6e0af..7916e91 100644 --- a/src/main/java/it/polimi/ingsw/gc14/GameEventProcessor.java +++ b/src/main/java/it/polimi/ingsw/gc14/GameEventProcessor.java @@ -3,7 +3,7 @@ package it.polimi.ingsw.gc14; import it.polimi.ingsw.gc14.Controller.GameController; import it.polimi.ingsw.gc14.Model.Game; import it.polimi.ingsw.gc14.Model.GamePackage.GameStages; -import it.polimi.ingsw.gc14.Network.ClientBroadcaster; +import it.polimi.ingsw.gc14.Network.CompositeClientBroadcaster; import it.polimi.ingsw.gc14.Network.EventType; import it.polimi.ingsw.gc14.Network.NetworkEvent; import it.polimi.ingsw.gc14.Network.NetworkEvents.*; @@ -37,7 +37,7 @@ public class GameEventProcessor { private final BlockingQueue actionQueue; private final GameController gameController; private final LimitedMap playerList; - private final ClientBroadcaster broadcaster; + private final CompositeClientBroadcaster broadcaster; private final SaveManager saveManager; /** Single-thread executor used exclusively for the forfeit timer. */ @@ -63,7 +63,7 @@ public class GameEventProcessor { BlockingQueue actionQueue, GameController gameController, LimitedMap playerList, - ClientBroadcaster broadcaster, + CompositeClientBroadcaster broadcaster, SaveManager saveManager) { this.actionQueue = actionQueue; this.gameController = gameController; diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/ClientBroadcaster.java b/src/main/java/it/polimi/ingsw/gc14/Network/ClientBroadcaster.java deleted file mode 100644 index b813478..0000000 --- a/src/main/java/it/polimi/ingsw/gc14/Network/ClientBroadcaster.java +++ /dev/null @@ -1,34 +0,0 @@ -package it.polimi.ingsw.gc14.Network; - -import it.polimi.ingsw.gc14.Model.MiniModel; - -/** - * Abstraction over the set of connected clients. - * - *

Implementations are expected to forward events and model snapshots - * to every transport layer (TCP, RMI, ...) in use, hiding the details - * of each protocol from the caller. - * - *

Error events (where {@link NetworkEvent#getIsError()} is {@code true}) - * must be delivered only to the requesting player; non-error events must - * be delivered to every connected client. Implementations are responsible - * for enforcing this rule. - */ -public interface ClientBroadcaster { - - /** - * Sends a network event to the appropriate connected clients. - * - * @param event the event to deliver; if it represents an error it is - * sent only to the player identified by - * {@link NetworkEvent#getUsername()}. - */ - void notifyAll(NetworkEvent event); - - /** - * Sends an updated game snapshot to every connected client. - * - * @param model the mini-model to deliver. - */ - void notifyAll(MiniModel model); -} diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/CompositeClientBroadcaster.java b/src/main/java/it/polimi/ingsw/gc14/Network/CompositeClientBroadcaster.java index 122d78d..8fdbc5b 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/CompositeClientBroadcaster.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/CompositeClientBroadcaster.java @@ -5,13 +5,12 @@ import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer; import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer; /** - * {@link ClientBroadcaster} implementation that forwards every notification - * to both the RMI and the TCP transport layers. + * Forwards every notification to both the RMI and the TCP transport layers. * *

This follows the Composite pattern: the caller interacts with a single * broadcaster without knowing which protocols are active underneath. */ -public class CompositeClientBroadcaster implements ClientBroadcaster { +public class CompositeClientBroadcaster { private final RMIServer rmiServer; private final TCPServer tcpServer; @@ -28,24 +27,18 @@ public class CompositeClientBroadcaster implements ClientBroadcaster { } /** - * {@inheritDoc} - * - *

Forwards the event to both the RMI and the TCP server. + * Forwards the event to both the RMI and the TCP server. * Each server is responsible for filtering error events to the * requesting player only. */ - @Override public void notifyAll(NetworkEvent event) { rmiServer.notifyAll(event); tcpServer.notifyAll(event); } /** - * {@inheritDoc} - * - *

Forwards the model snapshot to every client on both transports. + * Forwards the model snapshot to every client on both transports. */ - @Override public void notifyAll(MiniModel model) { rmiServer.notifyAll(model); tcpServer.notifyAll(model); diff --git a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java index c8e628a..3303a5e 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java +++ b/src/main/java/it/polimi/ingsw/gc14/ServerLauncher.java @@ -4,7 +4,6 @@ import it.polimi.ingsw.gc14.Controller.GameController; import it.polimi.ingsw.gc14.Model.Game; import it.polimi.ingsw.gc14.Model.MiniModel; import it.polimi.ingsw.gc14.Model.Player; -import it.polimi.ingsw.gc14.Network.ClientBroadcaster; import it.polimi.ingsw.gc14.Network.CompositeClientBroadcaster; import it.polimi.ingsw.gc14.Network.NetworkEvent; import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer; @@ -49,7 +48,7 @@ public class ServerLauncher { BlockingQueue actionQueue, GameController gameController, LimitedMap playerList, - ClientBroadcaster broadcaster, + CompositeClientBroadcaster broadcaster, SaveManager saveManager) { this.eventProcessor = new GameEventProcessor( actionQueue, gameController, playerList, broadcaster, saveManager); @@ -81,7 +80,7 @@ public class ServerLauncher { RMIServer rmiServer = new RMIServer(gameController, NetworkConfig.RMI_PORT, actionQueue, playerList, ip); TCPServer tcpServer = new TCPServer(gameController, NetworkConfig.TCP_PORT, NetworkConfig.HEARTBEAT_PORT, actionQueue, playerList); - ClientBroadcaster broadcaster = new CompositeClientBroadcaster(rmiServer, tcpServer); + CompositeClientBroadcaster broadcaster = new CompositeClientBroadcaster(rmiServer, tcpServer); SaveManager saveManager = new SaveManager(ServerLauncher.class); restoreGameIfSaved(gameController, playerList, saveManager);