Refactor dispatch method of ResponseDispatcher to be unchecked #223
+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);
|
||||
}
|
||||
}
|
||||
+9
-4
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+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.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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user