Merge branch 'feat/35-make-dispatch-method-of-responsedispatcher-unchecked' into 'main'

Refactor dispatch method of ResponseDispatcher to be unchecked

Closes #35

See merge request cs108-fs26/Gruppe-13!67
This commit was merged in pull request #223.
This commit is contained in:
Lars Simon Winzer
2026-04-01 13:04:14 +02:00
3 changed files with 22 additions and 4 deletions
@@ -0,0 +1,7 @@
package ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher;
public class ResponseDispatchException extends RuntimeException {
public ResponseDispatchException(String message, Throwable cause) {
super(message, cause);
}
}
@@ -27,12 +27,17 @@ public class ResponseDispatcher {
* the target session's response queue.
*
* @param response the response to dispatch
* @throws InterruptedException if the thread is interrupted while waiting to enqueue the
* primitive response
* @throws ResponseDispatchException wraps any exceptions that occur during dispatching, such as
* the {@link InterruptedException}
*/
public void dispatch(Response response) throws InterruptedException {
public void dispatch(Response response) {
PrimitiveResponse primitiveResponse = ResponseEncoder.encode(response);
Session session = sessionManager.getSessionById(response.getSessionId());
session.getResponseQueue().put(primitiveResponse);
try {
session.getResponseQueue().put(primitiveResponse);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ResponseDispatchException("Interrupted while dispatching response", e);
}
}
}
@@ -14,6 +14,7 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.Request;
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestContext;
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.ErrorResponse;
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.PrimitiveResponse;
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatchException;
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseEncoder;
import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.RawPacket;
import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.TransportLayer;
@@ -88,6 +89,11 @@ public class SessionReader implements Runnable {
"UNKNOWN_COMMAND",
"This command is unknown to the server."));
} catch (ResponseDispatchException e) {
logger.error(
"Unexpected ResponseDispatchException exception while dispatching request",
e);
} catch (IOException e) {
logger.error("Unexpected IO exception while reading from transport", e);