Fix: full FA refactor
This commit is contained in:
@@ -29,7 +29,7 @@ import java.util.stream.Collectors;
|
||||
* </ul>
|
||||
*
|
||||
* <p>This class is not thread-safe by itself: it relies on the caller
|
||||
* (the game loop in {@code ServerLauncherTest}) to drive it from a single
|
||||
* (the game loop in {@code ServerLauncher}) to drive it from a single
|
||||
* thread via {@link #doFirstEvent()}.
|
||||
*/
|
||||
public class GameEventProcessor {
|
||||
@@ -40,9 +40,13 @@ public class GameEventProcessor {
|
||||
private final CompositeClientBroadcaster broadcaster;
|
||||
private final SaveManager saveManager;
|
||||
|
||||
/** Single-thread executor used exclusively for the forfeit timer. */
|
||||
/** Single-thread executor used exclusively for the forfeit timer. Daemon so it does not block JVM shutdown. */
|
||||
private final ScheduledExecutorService timerExecutor =
|
||||
Executors.newSingleThreadScheduledExecutor();
|
||||
Executors.newSingleThreadScheduledExecutor(r -> {
|
||||
Thread t = new Thread(r, "forfeit-timer");
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
});
|
||||
|
||||
/**
|
||||
* Handle to the running forfeit timer, or {@code null} when no timer is active.
|
||||
@@ -267,7 +271,7 @@ public class GameEventProcessor {
|
||||
}
|
||||
|
||||
disconnectionTimer = timerExecutor.schedule(
|
||||
() -> endGameForFeit(game),
|
||||
() -> endGameForfeit(game),
|
||||
1, TimeUnit.MINUTES
|
||||
);
|
||||
}
|
||||
@@ -278,9 +282,9 @@ public class GameEventProcessor {
|
||||
*
|
||||
* @param game the game model captured when the timer was scheduled.
|
||||
*/
|
||||
private void endGameForFeit(Game game) {
|
||||
private void endGameForfeit(Game game) {
|
||||
synchronized (gameController) {
|
||||
gameController.endGameForFeit();
|
||||
gameController.endGameForfeit();
|
||||
EndedGame forfeitEnd = new EndedGame(
|
||||
game.getSlotMap(), game.getOrderLogicCard(),
|
||||
game.getCurrentState(), game.getPlayerStanding()
|
||||
@@ -363,7 +367,7 @@ public class GameEventProcessor {
|
||||
List<String> toRemove = playerList.entrySet().stream()
|
||||
.filter(e -> !e.getValue())
|
||||
.map(Map.Entry::getKey)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
toRemove.forEach(playerList::remove);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user