Style: Apply formatting by Spotless
This commit is contained in:
@@ -4,7 +4,6 @@ import ch.unibas.dmi.dbis.cs108.casono.server.domain.user.UserCleanupJob;
|
|||||||
import ch.unibas.dmi.dbis.cs108.casono.server.domain.user.UserRegistry;
|
import ch.unibas.dmi.dbis.cs108.casono.server.domain.user.UserRegistry;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.NetworkManager;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.NetworkManager;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.command.CommandRouter;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.command.CommandRouter;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.command.TestCommandHandler;
|
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.events.DisconnectEvent;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.events.DisconnectEvent;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.events.EventBus;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.events.EventBus;
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.parser.CommandParserDispatcher;
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.parser.CommandParserDispatcher;
|
||||||
|
|||||||
+7
-5
@@ -1,10 +1,9 @@
|
|||||||
package ch.unibas.dmi.dbis.cs108.casono.server.network.command;
|
package ch.unibas.dmi.dbis.cs108.casono.server.network.command;
|
||||||
|
|
||||||
|
import ch.unibas.dmi.dbis.cs108.casono.server.network.parser.Request;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.parser.Request;
|
|
||||||
|
|
||||||
public class CommandRouter {
|
public class CommandRouter {
|
||||||
private final Map<Class<? extends Request>, CommandHandler<?>> handlers = new HashMap<>();
|
private final Map<Class<? extends Request>, CommandHandler<?>> handlers = new HashMap<>();
|
||||||
|
|
||||||
@@ -12,14 +11,17 @@ public class CommandRouter {
|
|||||||
handlers.put(request, handler);
|
handlers.put(request, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Safe, because during registration, it's ensured that the provided CommandHandler only receives requests it can handle.
|
// Safe, because during registration, it's ensured that the provided CommandHandler only
|
||||||
|
// receives requests it can handle.
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void execute(Request request) {
|
public void execute(Request request) {
|
||||||
CommandHandler<Request> handler = (CommandHandler<Request>) handlers.get(request.getClass());
|
CommandHandler<Request> handler =
|
||||||
|
(CommandHandler<Request>) handlers.get(request.getClass());
|
||||||
|
|
||||||
if (handler == null) {
|
if (handler == null) {
|
||||||
String requestName = request.getClass().toString();
|
String requestName = request.getClass().toString();
|
||||||
throw new UnknownRequestException("Unable to execute request " + requestName + ". Type unknown", requestName);
|
throw new UnknownRequestException(
|
||||||
|
"Unable to execute request " + requestName + ". Type unknown", requestName);
|
||||||
}
|
}
|
||||||
handler.execute(request);
|
handler.execute(request);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,10 @@ public class Session {
|
|||||||
* @throws IOException if an I/O error occurs during initialization
|
* @throws IOException if an I/O error occurs during initialization
|
||||||
*/
|
*/
|
||||||
public Session(
|
public Session(
|
||||||
TransportLayer transport, EventBus eventBus, CommandParserDispatcher dispatcher, CommandRouter router) {
|
TransportLayer transport,
|
||||||
|
EventBus eventBus,
|
||||||
|
CommandParserDispatcher dispatcher,
|
||||||
|
CommandRouter router) {
|
||||||
this.id = new SessionId();
|
this.id = new SessionId();
|
||||||
this.transport = transport;
|
this.transport = transport;
|
||||||
this.dispatcher = dispatcher;
|
this.dispatcher = dispatcher;
|
||||||
|
|||||||
+2
-1
@@ -20,7 +20,8 @@ public class SessionManager {
|
|||||||
private final CommandRouter router;
|
private final CommandRouter router;
|
||||||
|
|
||||||
/** Constructs a new SessionManager. */
|
/** Constructs a new SessionManager. */
|
||||||
public SessionManager(EventBus eventBus, CommandParserDispatcher dispatcher, CommandRouter router) {
|
public SessionManager(
|
||||||
|
EventBus eventBus, CommandParserDispatcher dispatcher, CommandRouter router) {
|
||||||
this.sessions = new ConcurrentHashMap<>();
|
this.sessions = new ConcurrentHashMap<>();
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
this.logger = LogManager.getLogger(SessionManager.class);
|
this.logger = LogManager.getLogger(SessionManager.class);
|
||||||
|
|||||||
+1
-1
@@ -56,7 +56,7 @@ public class SessionReader implements Runnable {
|
|||||||
logger.debug("Converted to {}", primitiveRequest);
|
logger.debug("Converted to {}", primitiveRequest);
|
||||||
|
|
||||||
Request request = dispatcher.parse(primitiveRequest);
|
Request request = dispatcher.parse(primitiveRequest);
|
||||||
|
|
||||||
router.execute(request);
|
router.execute(request);
|
||||||
} catch (EOFException e) {
|
} catch (EOFException e) {
|
||||||
logger.info("Client disconnected");
|
logger.info("Client disconnected");
|
||||||
|
|||||||
Reference in New Issue
Block a user