Microfix: SevrerLauncher
This commit is contained in:
@@ -26,35 +26,30 @@ public class ServerLauncher {
|
||||
this.serverTCP = serverTCP;
|
||||
}
|
||||
|
||||
public boolean doFirstEven() throws InterruptedException, RemoteException {
|
||||
if(!actionQueue.isEmpty()) {
|
||||
NetworkEvent event = actionQueue.take();
|
||||
if(event.apply(gameController)) {
|
||||
serverRMI.notifyAll(event);
|
||||
serverTCP.broadcastUpdate(event);
|
||||
return true;
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
public boolean doFirstEvent() throws InterruptedException, RemoteException {
|
||||
NetworkEvent event = actionQueue.take();
|
||||
if(event.apply(gameController)) {
|
||||
serverRMI.notifyAll(event);
|
||||
serverTCP.broadcastUpdate(event);
|
||||
return true;
|
||||
} else {
|
||||
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 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<>();
|
||||
Game model = new Game();
|
||||
GameController gameController = new GameController(model);
|
||||
RMIServer serverRMI = new RMIServer(gameController, 1099, actionQueue);
|
||||
TCPServer serverTCP = new TCPServer(gameController, 8080, actionQueue);
|
||||
|
||||
serverRMI.start();
|
||||
new Thread (()->{serverTCP.start();}).start();
|
||||
|
||||
ServerLauncher launcher = new ServerLauncher(actionQueue, gameController, serverRMI, serverTCP);
|
||||
launcher.run();
|
||||
}
|
||||
@@ -62,7 +57,7 @@ public class ServerLauncher {
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
this.doFirstEven();
|
||||
this.doFirstEvent();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user