server doc

This commit is contained in:
Johannes Schmelz 2024-12-02 09:06:00 +01:00
parent 957bf8ffcc
commit 95b9da9377
2 changed files with 23 additions and 1 deletions

View File

@ -70,7 +70,7 @@ import pp.monopoly.model.fields.TestStreckeField;
import pp.monopoly.model.fields.WacheField;
/**
* Server implementing the visitor pattern as MessageReceiver for ClientMessages
* MonopolyServer implementing the visitor pattern as MessageReceiver for ClientMessages
*/
public class MonopolyServer implements MessageListener<HostedConnection>, ConnectionListener, ServerSender {
private static final Logger LOGGER = System.getLogger(MonopolyServer.class.getName());
@ -109,12 +109,18 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
logic = new ServerGameLogic(this, config);
}
/**
* Run is executed on StartUp
*/
public void run() {
startServer();
while (true)
processNextMessage();
}
/**
* Starts the Server
*/
private void startServer() {
try {
LOGGER.log(Level.INFO, "Starting server..."); //NON-NLS
@ -130,6 +136,9 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
}
}
/**
* Processesthe next incoming message
*/
private void processNextMessage() {
try {
pendingMessages.take().process(logic);
@ -140,6 +149,9 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
}
}
/**
* Initialize alls Messages and Classes that need to be sent
*/
private void initializeSerializables() {
Serializer.registerClass(IntPoint.class);
Serializer.registerClass(BuyPropertyResponse.class);
@ -182,6 +194,9 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
Serializer.registerClass(GameOver.class);
}
/**
* Register all message listeners
*/
private void registerListeners() {
myServer.addMessageListener(this, BuyPropertyResponse.class);
myServer.addMessageListener(this, EndTurn.class);
@ -220,6 +235,10 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
}
}
/**
* Exits the server
* @param exitValue the exit code to throw
*/
private void exit(int exitValue) { //NON-NLS
LOGGER.log(Level.INFO, "close request"); //NON-NLS
if (myServer != null)

View File

@ -10,6 +10,9 @@ package pp.monopoly.server;
import pp.monopoly.message.client.ClientInterpreter;
import pp.monopoly.message.client.ClientMessage;
/**
* Record to process incoming Client Messages
*/
record ReceivedMessage(ClientMessage message, int from) {
void process(ClientInterpreter interpreter) {
message.accept(interpreter, from);