From 95b9da937789a0912c494ee191bded40d1201486 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 2 Dec 2024 09:06:00 +0100 Subject: [PATCH] server doc --- .../pp/monopoly/server/MonopolyServer.java | 21 ++++++++++++++++++- .../pp/monopoly/server/ReceivedMessage.java | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java index f271e1a..95f04c4 100644 --- a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java +++ b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java @@ -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, ConnectionListener, ServerSender { private static final Logger LOGGER = System.getLogger(MonopolyServer.class.getName()); @@ -109,12 +109,18 @@ public class MonopolyServer implements MessageListener, 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, Connec } } + /** + * Processesthe next incoming message + */ private void processNextMessage() { try { pendingMessages.take().process(logic); @@ -140,6 +149,9 @@ public class MonopolyServer implements MessageListener, 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, 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, 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) diff --git a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/ReceivedMessage.java b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/ReceivedMessage.java index 59c38cc..3707a38 100644 --- a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/ReceivedMessage.java +++ b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/ReceivedMessage.java @@ -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);