Commit 5c89bdef authored by amir.yosef's avatar amir.yosef

Adding ServerBuilder

parent d7c1beda
package builder;
import server.Server;
import java.io.IOException;
public class ServerBuilder {
private int port;
private String role;
public void port(int port) {
this.port = port;
}
public void role(String role) {
this.role = role;
}
public Server build() {
try {
return Server.getInstance(port, role);
} catch (IOException e) {
throw new RuntimeException("Failed to build the Server");
}
}
}
...@@ -10,18 +10,21 @@ import java.util.concurrent.ExecutorService; ...@@ -10,18 +10,21 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
public class Server { public class Server {
private static final int PORT = 16379; private final int PORT ;
private final ExecutorService executor; private final ExecutorService executor;
private final String role;
private static Server instance; private static Server instance;
private Server() { Server(int port, String role) {
PORT = port;
this.role = role;
this.executor = Executors.newVirtualThreadPerTaskExecutor(); this.executor = Executors.newVirtualThreadPerTaskExecutor();
} }
public static synchronized Server getInstance() throws IOException { public static synchronized Server getInstance(int PORT,String role) throws IOException {
if (instance == null) { if (instance == null) {
instance = new Server(); instance = new Server(PORT,role);
} }
return instance; return instance;
} }
......
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