Commit 03aa0c1a authored by amir.yosef's avatar amir.yosef

clean up

parent a1b617f9
import director.Director;
import server.Server;
import server.ServerBuilder;
import util.Settings;
import java.util.Map;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
Map<String, String> parameters = Settings.extractArgs(args);
int port = 6379;
port = Settings.extractPort(parameters, port);
Director director = new Director();
ServerBuilder builder = new ServerBuilder();
// System.out.println(Arrays.toString(args));
ServerBuilder builder = new ServerBuilder(args);
director.buildMaster(builder);
builder.setPort(port);
try (Server server = builder.build()) {
server.start();
}
......
package client.primary;
package client.master;
import client.Client;
......@@ -12,7 +12,6 @@ import java.util.List;
public class MasterClient extends Client {
public MasterClient(Socket socket) {
super(socket);
......
......@@ -2,7 +2,7 @@ package command;
import model.Command;
import util.Response;
import util.ServerInfo;
import server.ServerInfo;
import java.util.List;
import java.util.Map;
......
......@@ -18,6 +18,10 @@ public class SetCommand implements CommandHandler {
@Override
public byte[] execute() {
return getBytes(args, storage);
}
private byte[] getBytes(List<String> args, Storage storage) {
Map<String, String> commandsMap = new HashMap<>();
for (int i = 2; i < args.size(); i += 2) {
......@@ -25,7 +29,6 @@ public class SetCommand implements CommandHandler {
}
String value = args.get(1);
String expiration = commandsMap.get(Command.PX.getValue().toLowerCase());
if (expiration != null) {
try {
......@@ -37,8 +40,6 @@ public class SetCommand implements CommandHandler {
} else {
storage.save(args.getFirst().toLowerCase(), value);
}
return ("+OK\r\n".getBytes());
}
}
package server;
import client.Client;
import client.primary.MasterClient;
import client.master.MasterClient;
import storage.StorageManager;
import java.io.IOException;
......
package server;
import util.Settings;
import java.util.Map;
public class ServerBuilder {
private int port = 6379;
private String role;
String[] masterPortAndHost;
private final static ServerInfo info = ServerInfo.getInstance();
Map<String, String> parameters;
public void setPort(int port) {
this.port = port;
this.port = Settings.extractPort(parameters, port);
}
public ServerBuilder(String[] args) {
this.parameters = Settings.extractArgs(args);
this.port = Settings.extractPort(parameters, port);
this.masterPortAndHost = info.findRole(parameters);
}
public void setRole(String role) {
......
package util;
package server;
import java.util.Map;
......
......@@ -6,8 +6,8 @@ import java.util.Map;
public class Settings {
public static int extractPort(Map<String, String> args, int port) {
if (args.containsKey("--setPort")) {
port = Integer.parseInt(args.get("--setPort"));
if (args.containsKey("--Port")) {
port = Integer.parseInt(args.get("--Port"));
}
return port;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment