Add serverside PING-command #228

Merged
lars.winzer merged 6 commits from feat/38-add-serverside-ping-command into main 2026-04-02 12:45:56 +02:00
4 changed files with 38 additions and 0 deletions
Showing only changes of commit 87b2dcfc2c - Show all commits
@@ -69,6 +69,13 @@ public class ServerApp {
networkManager.start();
}
/**
* Registers command parsers and handlers.
*
* @param parserDispatcher the dispatcher responsible for parsing incoming commands
* @param commandRouter the router that dispatches parsed commands to appropriate handlers
* @param responseDispatcher the dispatcher responsible for sending responses back to clients
*/
private static void register_commands(
CommandParserDispatcher parserDispatcher,
CommandRouter commandRouter,
@@ -4,13 +4,24 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.command.execution.CommandH
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.OkResponse;
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher;
/** Handler for {@link PingRequest}. */
public class PingHandler implements CommandHandler<PingRequest> {
private final ResponseDispatcher responseDispatcher;
/**
* Create a new PingHandler to execute {@link PingRequest}s
*
* @param responseDispatcher dispatcher used to send responses back to clients
*/
public PingHandler(ResponseDispatcher responseDispatcher) {
this.responseDispatcher = responseDispatcher;
}
/**
* Execute the ping request.
*
* @param request the ping request to handle
*/
@Override
public void execute(PingRequest request) {
responseDispatcher.dispatch(new OkResponse(request.getContext()));
@@ -3,7 +3,18 @@ package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.ping;
import ch.unibas.dmi.dbis.cs108.casono.server.network.command.parsing.CommandParser;
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.PrimitiveRequest;
/**
* Parser for the Ping command.
*
* <p>Converts a low-level {@link PrimitiveRequest} into a {@link PingRequest}.
*/
public class PingParser implements CommandParser<PingRequest> {
/**
* Parse the given primitive request into a {@link PingRequest}.
*
* @param primitiveRequest the raw request to parse
* @return {@link PingRequest}
*/
@Override
public PingRequest parse(PrimitiveRequest primitiveRequest) {
return new PingRequest(primitiveRequest.context());
@@ -3,7 +3,16 @@ package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.ping;
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.Request;
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestContext;
/**
* Represents a "PING" request sent by a client to check server availability and keep the connection
* alive.
*/
public class PingRequest extends Request {
/**
* Constructs a new PingRequest with the given context.
*
* @param context the request context associated with this request
*/
public PingRequest(RequestContext context) {
super(context);
}