Add: shared actionQueue between ServerLauncher, ServerRMI and ServerTCP
This commit is contained in:
@@ -18,8 +18,8 @@ public class ServerLauncher {
|
||||
|
||||
|
||||
|
||||
public ServerLauncher(GameController gameController, RMIServer serverRMI, TCPServer serverTCP) {
|
||||
this.actionQueue = new LinkedBlockingQueue<>();
|
||||
public ServerLauncher(BlockingQueue<NetworkEvent> actionQueue, GameController gameController, RMIServer serverRMI, TCPServer serverTCP) {
|
||||
this.actionQueue = actionQueue;
|
||||
this.serverRMI = serverRMI;
|
||||
this.gameController = gameController;
|
||||
this.serverTCP = serverTCP;
|
||||
@@ -33,30 +33,27 @@ public class ServerLauncher {
|
||||
serverTCP.broadcastUpdate(event);
|
||||
return true;
|
||||
} else {
|
||||
//serverRMI.notifyError(); // TODO difficile trovare username. Converrebbe mettere in network event un booleano che dice se è stato accettato e fare una notifyAll anche per errori
|
||||
//serverTCP // TODO non esiste un notify error
|
||||
serverRMI.notifyError(event.getUsername(), "Mossa non valida"); // TODO Converrebbe mettere in network event un booleano che dice se è stato accettato e fare una notifyAll anche per errori
|
||||
//serverTCP // TODO non esiste un notify error (guarda sopra)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addEvent(NetworkEvent event) {
|
||||
return actionQueue.offer(event);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws RemoteException {
|
||||
public static void main() throws RemoteException {
|
||||
// TODO
|
||||
// Deve avere una coda con gli eventi.
|
||||
// Il server RMI e il server TCP quando ricevono un doEvent devono aggiungere l'evento alla coda condivisa
|
||||
// Questa classe esegue gli eventi nella coda e chiama il notify all e notify error sia RMI che TCP
|
||||
|
||||
BlockingQueue<NetworkEvent> actionQueue = new LinkedBlockingQueue<>();
|
||||
GameController gameController = new GameController();
|
||||
RMIServer serverRMI = new RMIServer(gameController, 1099);
|
||||
TCPServer serverTCP = new TCPServer(gameController, 8080);
|
||||
RMIServer serverRMI = new RMIServer(gameController, 1099, actionQueue);
|
||||
TCPServer serverTCP = new TCPServer(gameController, 8080, actionQueue);
|
||||
|
||||
ServerLauncher launcher = new ServerLauncher(gameController, serverRMI, serverTCP);
|
||||
ServerLauncher launcher = new ServerLauncher(actionQueue, gameController, serverRMI, serverTCP);
|
||||
launcher.run();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user