Class RMIServer
- All Implemented Interfaces:
IGameServer, Serializable, Remote
The server manages player registration, reconnection handling, heartbeat monitoring, and the forwarding of client requests to the shared network event queue.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BlockingQueue<NetworkEvent> Shared queue to which player actions are added for sequential processing.private final Map<String, IClientCallback> username → callbackprivate final GameControllerServer-side game controller; all model access is synchronized on this object.private final StringHostname or IP address exposed by the RMI runtime (java.rmi.server.hostname).private final intPort on which the RMI registry is bound.private final LimitedMap<String, Boolean> Shared map tracking each player's connection status (true= online).private final Map<String, RMIHeartbeat> username → watchdog.Fields inherited from class RemoteObject
ref -
Constructor Summary
ConstructorsConstructorDescriptionRMIServer(GameController controller, int nPort, BlockingQueue<NetworkEvent> actionQueue, LimitedMap<String, Boolean> playerList, String host) Constructs an RMI server with the required game and network components. -
Method Summary
Modifier and TypeMethodDescriptiondisconnectedUsernames(Game game) Returns usernames of players currently marked as disconnected in the given game.voiddisconnectPlayer(String username) Triggers a voluntary disconnection for the specified player by stopping their heartbeat watchdog.voiddrawLowerBuildingCard(String playerUsername, int pos) Requests to draw a building card from the lower list.voiddrawLowerTribeCard(String playerUsername, int pos) Requests to draw a tribe card from the lower list.voiddrawUpperBuildingCard(String playerUsername, int pos) Requests to draw a building card from the upper list.voiddrawUpperTribeCard(String playerUsername, int pos) Requests to draw a tribe card from the upper list.joinGame(String username, int preferredInt, IClientCallback callback) Adds a player to the game and registers the callback used by the server to notify the corresponding RMI client.voidNotifies all connected RMI clients of a new game model.voidnotifyAll(NetworkEvent action) Notifies connected RMI clients of a new network event.voidReceives a heartbeat ping from the client.voidRequests to skip the turn.voidslotChoice(String playerUsername, int pos) Used to perform the slot choice action for the specified player at the specified position.voidstart()Starts the RMI server and binds it to the configured registry.private voidstartWatchdog(String username) Creates and starts anRMIHeartbeatfor the specified player.voidtotemChoice(String playerUsername, String totems) Enqueues a totem choice event for the specified player.Methods inherited from class UnicastRemoteObject
clone, exportObject, exportObject, exportObject, exportObject, exportObject, unexportObjectMethods inherited from class RemoteServer
getClientHost, getLog, setLog
-
Field Details
-
host
Hostname or IP address exposed by the RMI runtime (java.rmi.server.hostname). -
controller
Server-side game controller; all model access is synchronized on this object. -
nPort
private final int nPortPort on which the RMI registry is bound. -
clients
username → callback -
watchdogs
username → watchdog. One watchdog per connected player, mirrorspendingHeartbeat/ per-socket HeartbeatHandler in the TCP stack. -
actionQueue
Shared queue to which player actions are added for sequential processing. -
playerList
Shared map tracking each player's connection status (true= online).
-
-
Constructor Details
-
RMIServer
public RMIServer(GameController controller, int nPort, BlockingQueue<NetworkEvent> actionQueue, LimitedMap<String, Boolean> playerList, String host) throws RemoteExceptionConstructs an RMI server with the required game and network components.- Parameters:
controller- the game controller used to manage the game logic.nPort- the port used by the RMI registry.actionQueue- the queue containing incoming network events.playerList- the map storing the connection status of the players.host- the hostname or IP address exposed by the RMI server.- Throws:
RemoteException- if the remote object cannot be exported.
-
-
Method Details
-
joinGame
public ErrorType joinGame(String username, int preferredInt, IClientCallback callback) throws RemoteException Adds a player to the game and registers the callback used by the server to notify the corresponding RMI client.After a successful join an
RMIHeartbeatwatchdog is created and started for the new player — mirrors creating aHeartbeatHandlerinTCPServer.acceptHeartbeat().- Specified by:
joinGamein interfaceIGameServer- Parameters:
username- the username chosen by the player.preferredInt- the desired number of players proposed by this client.callback- the remote callback associated with the client.- Returns:
nullon success; anErrorTypevalue on rejection.- Throws:
RemoteException- if an RMI communication error occurs.
-
ping
Receives a heartbeat ping from the client. Mirrors the server readingPINGand replyingPONGinHeartbeatHandler.run().- Specified by:
pingin interfaceIGameServer- Parameters:
username- the username of the pinging client.- Throws:
RemoteException- if an RMI communication error occurs.
-
notifyAll
Notifies connected RMI clients of a new network event.If the event does not represent an error, it is sent to all registered clients. If it represents an error, it is sent only to the client that requested the action. Communication errors are logged without interrupting the notification process.
- Parameters:
action- the network event to send to the clients.
-
notifyAll
Notifies all connected RMI clients of a new game model.The updated mini model is sent to each registered client callback. If a communication error occurs for a client, the exception is logged without interrupting the notification of the remaining clients.
- Parameters:
model- the updated mini model to send to the connected clients.
-
drawUpperTribeCard
Requests to draw a tribe card from the upper list. Creates a NetworkEvent and sends it through the network client.- Specified by:
drawUpperTribeCardin interfaceIGameServer- Parameters:
playerUsername- the name of the player performing the actionpos- the index of the card to draw
-
drawLowerTribeCard
Requests to draw a tribe card from the lower list. Creates a NetworkEvent and sends it through the network client.- Specified by:
drawLowerTribeCardin interfaceIGameServer- Parameters:
playerUsername- the name of the player performing the actionpos- the index of the card to draw
-
drawUpperBuildingCard
Requests to draw a building card from the upper list. Creates a NetworkEvent and sends it through the network client.- Specified by:
drawUpperBuildingCardin interfaceIGameServer- Parameters:
playerUsername- the name of the player performing the actionpos- the index of the card to draw
-
drawLowerBuildingCard
Requests to draw a building card from the lower list. Creates a NetworkEvent and sends it through the network client.- Specified by:
drawLowerBuildingCardin interfaceIGameServer- Parameters:
playerUsername- the name of the player performing the actionpos- the index of the card to draw
-
skipTurn
Requests to skip the turn. This action is available only when the player cannot draw any tribe card, but still can buy some buildings.- Specified by:
skipTurnin interfaceIGameServer- Parameters:
playerUsername- the name of the player performing the action
-
slotChoice
Used to perform the slot choice action for the specified player at the specified position.- Specified by:
slotChoicein interfaceIGameServer- Parameters:
playerUsername- the name of the player performing the actionpos- the index of the selected slot
-
totemChoice
Enqueues a totem choice event for the specified player.- Specified by:
totemChoicein interfaceIGameServer- Parameters:
playerUsername- the username of the player choosing the totem.totems- the name of the chosen totem.- Throws:
RemoteException- if the RMI call fails.
-
start
public void start()Starts the RMI server and binds it to the configured registry.The method configures the server hostname, creates the RMI registry on the specified port, and registers this server instance under the
RMIGameServername. -
startWatchdog
Creates and starts anRMIHeartbeatfor the specified player.- Parameters:
username- the username of the player monitored by the heartbeat watchdog.
-
disconnectPlayer
Triggers a voluntary disconnection for the specified player by stopping their heartbeat watchdog.- Specified by:
disconnectPlayerin interfaceIGameServer- Parameters:
username- the username of the player to disconnect.
-
disconnectedUsernames
-