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