Extract ResponseDispatcher field into constructor of CommandHandler #243
+1
-2
@@ -8,7 +8,6 @@ import java.util.Optional;
|
||||
|
||||
/** Handles {@link CheckUsernameRequest}s to check whether a username is available. */
|
||||
public class CheckUsernameHandler extends CommandHandler<CheckUsernameRequest> {
|
||||
private final ResponseDispatcher responseDispatcher;
|
||||
private final UserRegistry userRegistry;
|
||||
|
||||
/**
|
||||
@@ -18,7 +17,7 @@ public class CheckUsernameHandler extends CommandHandler<CheckUsernameRequest> {
|
||||
* @param userRegistry the registry used to look up existing users
|
||||
*/
|
||||
public CheckUsernameHandler(ResponseDispatcher responseDispatcher, UserRegistry userRegistry) {
|
||||
this.responseDispatcher = responseDispatcher;
|
||||
super(responseDispatcher);
|
||||
this.userRegistry = userRegistry;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -14,7 +14,6 @@ import java.util.Optional;
|
||||
* already
|
||||
*/
|
||||
public class LoginHandler extends CommandHandler<LoginRequest> {
|
||||
private final ResponseDispatcher responseDispatcher;
|
||||
private final UserRegistry userRegistry;
|
||||
private final UserFactory userFactory;
|
||||
|
||||
@@ -25,7 +24,7 @@ public class LoginHandler extends CommandHandler<LoginRequest> {
|
||||
* @param userRegistry the registry used to look up existing users and create the new one
|
||||
*/
|
||||
public LoginHandler(ResponseDispatcher responseDispatcher, UserRegistry userRegistry) {
|
||||
this.responseDispatcher = responseDispatcher;
|
||||
super(responseDispatcher);
|
||||
this.userRegistry = userRegistry;
|
||||
this.userFactory = new UserFactory(userRegistry);
|
||||
}
|
||||
|
||||
+1
-2
@@ -8,7 +8,6 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatch
|
||||
|
||||
/** Handles {@link LogoutRequest} to logout connected user. */
|
||||
public class LogoutHandler extends CommandHandler<LogoutRequest> {
|
||||
private final ResponseDispatcher responseDispatcher;
|
||||
private final UserRegistry userRegistry;
|
||||
|
||||
/**
|
||||
@@ -18,7 +17,7 @@ public class LogoutHandler extends CommandHandler<LogoutRequest> {
|
||||
* @param userRegistry registry responsible for tracking connected user sessions
|
||||
*/
|
||||
public LogoutHandler(ResponseDispatcher responseDispatcher, UserRegistry userRegistry) {
|
||||
this.responseDispatcher = responseDispatcher;
|
||||
super(responseDispatcher);
|
||||
this.userRegistry = userRegistry;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -6,7 +6,6 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatch
|
||||
|
||||
/** Handler for {@link PingRequest}. */
|
||||
public class PingHandler extends CommandHandler<PingRequest> {
|
||||
private final ResponseDispatcher responseDispatcher;
|
||||
|
||||
/**
|
||||
* Create a new PingHandler to execute {@link PingRequest}s
|
||||
@@ -14,7 +13,7 @@ public class PingHandler extends CommandHandler<PingRequest> {
|
||||
* @param responseDispatcher dispatcher used to send responses back to clients
|
||||
*/
|
||||
public PingHandler(ResponseDispatcher responseDispatcher) {
|
||||
this.responseDispatcher = responseDispatcher;
|
||||
super(responseDispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+11
@@ -2,6 +2,7 @@ package ch.unibas.dmi.dbis.cs108.casono.server.network.command.execution;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.command.execution.checks.HandlerCheck;
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.Request;
|
||||
import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -13,6 +14,16 @@ import java.util.List;
|
||||
*/
|
||||
public abstract class CommandHandler<T extends Request> {
|
||||
private final List<HandlerCheck> checks = new ArrayList<>();
|
||||
protected final ResponseDispatcher responseDispatcher;
|
||||
|
||||
/**
|
||||
* Constructs a CommandHandler with the specified ResponseDispatcher.
|
||||
*
|
||||
* @param responseDispatcher the ResponseDispatcher instance used to send responses to clients.
|
||||
*/
|
||||
public CommandHandler(ResponseDispatcher responseDispatcher) {
|
||||
this.responseDispatcher = responseDispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a handler check to be performed before request execution.
|
||||
|
||||
Reference in New Issue
Block a user