Fixed: Some exception not managed fixed

This commit is contained in:
rubenpirreram
2026-05-15 16:01:09 +02:00
parent f3aaab516f
commit df1b41b666
6 changed files with 131 additions and 90 deletions
@@ -97,9 +97,8 @@ public class ServerLauncher {
* All clients (both TCP and RMI) are notified of the event
* @return the outcome of applying the event to the controller
* @throws InterruptedException if an error occurs while accessing the actionQueue
* @throws RemoteException if an RMI error occurs
*/
public boolean doFirstEvent() throws InterruptedException, RemoteException {
public boolean doFirstEvent() throws InterruptedException {
NetworkEvent event = actionQueue.take();
if(gameController.getModel()!=null && !gameController.getModel().getCurrentState().equals(GameStages.ENDED))
{
@@ -114,7 +113,7 @@ public class ServerLauncher {
disconnectionTimer.cancel(false);
disconnectionTimer = null;
}
int roundPrec=gameController.getModel().getCurrentState().getRound();
int roundPrev=gameController.getModel().getCurrentState().getRound();
synchronized(gameController){
event.setIsError(!event.apply(gameController));
Game game=gameController.getModel();
@@ -134,7 +133,7 @@ public class ServerLauncher {
}
serverRMI.notifyAll(event);
serverTCP.notifyAll(event);
if(game.getCurrentState().getRound()!=roundPrec)
if(game.getCurrentState().getRound()!=roundPrev)
{
ApplyNextRound nextRound=new ApplyNextRound(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(),game.getPlayers());
serverRMI.notifyAll(nextRound);
@@ -161,8 +160,8 @@ public class ServerLauncher {
disconnectionTimer.cancel(false);
}
disconnectionTimer = timerExecutor.schedule(() -> {
System.out.println("Timer scaduto: nessun giocatore riconnesso in 30s.");
}, 30, TimeUnit.SECONDS);
System.out.println("Timer expired: no player reconnected in 60s.");
}, 1, TimeUnit.MINUTES);
}
return !event.getIsError();
}
@@ -221,29 +220,24 @@ public class ServerLauncher {
}
playerList.setAction(()->{
new Thread(()->{
try {
System.out.println("\n\nNotifying model");
MiniModel miniModel;
synchronized (gameController) {
Game game = gameController.getModel();
miniModel= new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers(), new ArrayList<>(List.of(Totems.values())));
}
serverRMI.notifyAll(miniModel);
serverTCP.notifyAll(miniModel);
view = new TUI(miniModel);
view.fullRender();
} catch (RemoteException e) {
throw new RuntimeException(e);
System.out.println("\n\nNotifying model");
MiniModel miniModel;
synchronized (gameController) {
Game game = gameController.getModel();
miniModel= new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers(), new ArrayList<>(List.of(Totems.values())));
}
serverRMI.notifyAll(miniModel);
serverTCP.notifyAll(miniModel);
view = new TUI(miniModel);
view.fullRender();
}).start();
});
new Thread(()-> {
try {
launcher.run();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (RemoteException e) {
throw new RuntimeException(e);
} catch (Exception e)
{
System.out.println("Generic exception occurred"+e.getMessage());
}
}).start();
@@ -257,28 +251,17 @@ public class ServerLauncher {
* Game creation: TCP/RMI servers send the game model to all players.
* Game execution: repeatedly calls doFirstEvent() to process the events in the actionQueue.
* @throws InterruptedException if the TCP server thread is interrupted
* @throws RemoteException if an RMI error occurs
*/
public void run() throws InterruptedException, RemoteException {
// Game execution
public void run() {
while (true) {
try{
this.doFirstEvent();
try{
this.view.fullRender();
}
catch (NullPointerException e){
}
this.view.fullRender();
}
catch(InterruptedException e){
Thread.currentThread().interrupt();
break;
}
catch(RemoteException e){
//throw new RuntimeException(e);
}
}
}