Fix: useless interface removed
This commit is contained in:
@@ -3,7 +3,7 @@ package it.polimi.ingsw.gc14;
|
|||||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||||
import it.polimi.ingsw.gc14.Model.Game;
|
import it.polimi.ingsw.gc14.Model.Game;
|
||||||
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
|
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.EventType;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
|
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
|
||||||
@@ -37,7 +37,7 @@ public class GameEventProcessor {
|
|||||||
private final BlockingQueue<NetworkEvent> actionQueue;
|
private final BlockingQueue<NetworkEvent> actionQueue;
|
||||||
private final GameController gameController;
|
private final GameController gameController;
|
||||||
private final LimitedMap<String, Boolean> playerList;
|
private final LimitedMap<String, Boolean> playerList;
|
||||||
private final ClientBroadcaster broadcaster;
|
private final CompositeClientBroadcaster broadcaster;
|
||||||
private final SaveManager saveManager;
|
private final SaveManager saveManager;
|
||||||
|
|
||||||
/** Single-thread executor used exclusively for the forfeit timer. */
|
/** Single-thread executor used exclusively for the forfeit timer. */
|
||||||
@@ -63,7 +63,7 @@ public class GameEventProcessor {
|
|||||||
BlockingQueue<NetworkEvent> actionQueue,
|
BlockingQueue<NetworkEvent> actionQueue,
|
||||||
GameController gameController,
|
GameController gameController,
|
||||||
LimitedMap<String, Boolean> playerList,
|
LimitedMap<String, Boolean> playerList,
|
||||||
ClientBroadcaster broadcaster,
|
CompositeClientBroadcaster broadcaster,
|
||||||
SaveManager saveManager) {
|
SaveManager saveManager) {
|
||||||
this.actionQueue = actionQueue;
|
this.actionQueue = actionQueue;
|
||||||
this.gameController = gameController;
|
this.gameController = gameController;
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
package it.polimi.ingsw.gc14.Network;
|
|
||||||
|
|
||||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Abstraction over the set of connected clients.
|
|
||||||
*
|
|
||||||
* <p>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.
|
|
||||||
*
|
|
||||||
* <p>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);
|
|
||||||
}
|
|
||||||
@@ -5,13 +5,12 @@ import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
|
|||||||
import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer;
|
import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link ClientBroadcaster} implementation that forwards every notification
|
* Forwards every notification to both the RMI and the TCP transport layers.
|
||||||
* to both the RMI and the TCP transport layers.
|
|
||||||
*
|
*
|
||||||
* <p>This follows the Composite pattern: the caller interacts with a single
|
* <p>This follows the Composite pattern: the caller interacts with a single
|
||||||
* broadcaster without knowing which protocols are active underneath.
|
* broadcaster without knowing which protocols are active underneath.
|
||||||
*/
|
*/
|
||||||
public class CompositeClientBroadcaster implements ClientBroadcaster {
|
public class CompositeClientBroadcaster {
|
||||||
|
|
||||||
private final RMIServer rmiServer;
|
private final RMIServer rmiServer;
|
||||||
private final TCPServer tcpServer;
|
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.
|
||||||
*
|
|
||||||
* <p>Forwards the event to both the RMI and the TCP server.
|
|
||||||
* Each server is responsible for filtering error events to the
|
* Each server is responsible for filtering error events to the
|
||||||
* requesting player only.
|
* requesting player only.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void notifyAll(NetworkEvent event) {
|
public void notifyAll(NetworkEvent event) {
|
||||||
rmiServer.notifyAll(event);
|
rmiServer.notifyAll(event);
|
||||||
tcpServer.notifyAll(event);
|
tcpServer.notifyAll(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* Forwards the model snapshot to every client on both transports.
|
||||||
*
|
|
||||||
* <p>Forwards the model snapshot to every client on both transports.
|
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void notifyAll(MiniModel model) {
|
public void notifyAll(MiniModel model) {
|
||||||
rmiServer.notifyAll(model);
|
rmiServer.notifyAll(model);
|
||||||
tcpServer.notifyAll(model);
|
tcpServer.notifyAll(model);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import it.polimi.ingsw.gc14.Controller.GameController;
|
|||||||
import it.polimi.ingsw.gc14.Model.Game;
|
import it.polimi.ingsw.gc14.Model.Game;
|
||||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||||
import it.polimi.ingsw.gc14.Model.Player;
|
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.CompositeClientBroadcaster;
|
||||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||||
import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
|
import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
|
||||||
@@ -49,7 +48,7 @@ public class ServerLauncher {
|
|||||||
BlockingQueue<NetworkEvent> actionQueue,
|
BlockingQueue<NetworkEvent> actionQueue,
|
||||||
GameController gameController,
|
GameController gameController,
|
||||||
LimitedMap<String, Boolean> playerList,
|
LimitedMap<String, Boolean> playerList,
|
||||||
ClientBroadcaster broadcaster,
|
CompositeClientBroadcaster broadcaster,
|
||||||
SaveManager saveManager) {
|
SaveManager saveManager) {
|
||||||
this.eventProcessor = new GameEventProcessor(
|
this.eventProcessor = new GameEventProcessor(
|
||||||
actionQueue, gameController, playerList, broadcaster, saveManager);
|
actionQueue, gameController, playerList, broadcaster, saveManager);
|
||||||
@@ -81,7 +80,7 @@ public class ServerLauncher {
|
|||||||
|
|
||||||
RMIServer rmiServer = new RMIServer(gameController, NetworkConfig.RMI_PORT, actionQueue, playerList, ip);
|
RMIServer rmiServer = new RMIServer(gameController, NetworkConfig.RMI_PORT, actionQueue, playerList, ip);
|
||||||
TCPServer tcpServer = new TCPServer(gameController, NetworkConfig.TCP_PORT, NetworkConfig.HEARTBEAT_PORT, actionQueue, playerList);
|
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);
|
SaveManager saveManager = new SaveManager(ServerLauncher.class);
|
||||||
|
|
||||||
restoreGameIfSaved(gameController, playerList, saveManager);
|
restoreGameIfSaved(gameController, playerList, saveManager);
|
||||||
|
|||||||
Reference in New Issue
Block a user