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:
+7
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-3
@@ -27,12 +27,17 @@ public class ResponseDispatcher {
|
|||||||
* the target session's response queue.
|
* the target session's response queue.
|
||||||
*
|
*
|
||||||
* @param response the response to dispatch
|
* @param response the response to dispatch
|
||||||
* @throws InterruptedException if the thread is interrupted while waiting to enqueue the
|
* @throws ResponseDispatchException wraps any exceptions that occur during dispatching, such as
|
||||||
* primitive response
|
* the {@link InterruptedException}
|
||||||
*/
|
*/
|
||||||
public void dispatch(Response response) throws InterruptedException {
|
public void dispatch(Response response) {
|
||||||
PrimitiveResponse primitiveResponse = ResponseEncoder.encode(response);
|
PrimitiveResponse primitiveResponse = ResponseEncoder.encode(response);
|
||||||
Session session = sessionManager.getSessionById(response.getSessionId());
|
Session session = sessionManager.getSessionById(response.getSessionId());
|
||||||
|
try {
|
||||||
session.getResponseQueue().put(primitiveResponse);
|
session.getResponseQueue().put(primitiveResponse);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
throw new ResponseDispatchException("Interrupted while dispatching response", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -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.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.ErrorResponse;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.PrimitiveResponse;
|
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.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.RawPacket;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.TransportLayer;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.TransportLayer;
|
||||||
@@ -88,6 +89,11 @@ public class SessionReader implements Runnable {
|
|||||||
"UNKNOWN_COMMAND",
|
"UNKNOWN_COMMAND",
|
||||||
"This command is unknown to the server."));
|
"This command is unknown to the server."));
|
||||||
|
|
||||||
|
} catch (ResponseDispatchException e) {
|
||||||
|
logger.error(
|
||||||
|
"Unexpected ResponseDispatchException exception while dispatching request",
|
||||||
|
e);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Unexpected IO exception while reading from transport", e);
|
logger.error("Unexpected IO exception while reading from transport", e);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user