Class ServerLauncher
Responsibilities of this class are intentionally limited to wiring: it creates all components, connects them together, restores a previously saved game if one exists, and starts the event-processing loop and the network servers.
All game-logic and event-routing decisions are delegated to
GameEventProcessor; persistence is delegated to SaveManager.
The original ServerLauncher class is preserved and untouched.
This class is a clean replacement that uses the new component structure.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final GameEventProcessorDrives the main game-event loop. -
Constructor Summary
ConstructorsConstructorDescriptionServerLauncher(BlockingQueue<NetworkEvent> actionQueue, GameController gameController, LimitedMap<String, Boolean> playerList, CompositeClientBroadcaster broadcaster, SaveManager saveManager) Constructs aServerLauncherTestand wires all components together. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringchooseNetworkInterface(Scanner scanner) Lists active non-loopback IPv4 network interfaces and prompts the operator to choose one.(package private) static voidInitializes all server components, wires them together, restores a saved game if available, and starts the event-processing loop and both network servers.private static voidrestoreGameIfSaved(GameController gameController, LimitedMap<String, Boolean> playerList, SaveManager saveManager) Attempts to restore a previously saved game.voidrun()Runs the event-processing loop until the thread is interrupted.
-
Field Details
-
eventProcessor
Drives the main game-event loop.
-
-
Constructor Details
-
ServerLauncher
public ServerLauncher(BlockingQueue<NetworkEvent> actionQueue, GameController gameController, LimitedMap<String, Boolean> playerList, CompositeClientBroadcaster broadcaster, SaveManager saveManager) Constructs aServerLauncherTestand wires all components together.- Parameters:
actionQueue- the shared event queue.gameController- the server-side game controller.playerList- the shared player-status map.broadcaster- the broadcaster used to reach all connected clients.saveManager- the save manager used to persist game state.
-
-
Method Details
-
main
Initializes all server components, wires them together, restores a saved game if available, and starts the event-processing loop and both network servers.- Parameters:
args- command-line arguments (unused).- Throws:
RemoteException- if the RMI server cannot be created.
-
run
public void run()Runs the event-processing loop until the thread is interrupted.A
ConcurrentModificationExceptionis caught and logged rather -
restoreGameIfSaved
private static void restoreGameIfSaved(GameController gameController, LimitedMap<String, Boolean> playerList, SaveManager saveManager) Attempts to restore a previously saved game.The save is discarded if all but at most one player was offline at the time of the crash, since there would be nobody to resume the game with. Otherwise, the model is restored, the player-list limit is set, and each player who was offline at crash time is pre-populated as offline so the reconnection flow can handle them correctly.
- Parameters:
gameController- the controller that will receive the restored model.playerList- the player-status map to populate.saveManager- the save manager to load from.
-
chooseNetworkInterface
Lists active non-loopback IPv4 network interfaces and prompts the operator to choose one. If only one interface is available it is selected automatically.- Parameters:
scanner- the scanner used to read the operator's choice.- Returns:
- the IPv4 address of the selected interface.
- Throws:
Exception- if no valid network interface is available.
-