Commit f2cfa68b authored by amir.yosef's avatar amir.yosef

Fixing try-with buffered-reader exception

parent b7615176
...@@ -27,7 +27,6 @@ public class FullRsyncCommand implements CommandExecutable<byte[]> { ...@@ -27,7 +27,6 @@ public class FullRsyncCommand implements CommandExecutable<byte[]> {
public byte[] execute() { public byte[] execute() {
synchronized (this) { synchronized (this) {
replicaSender.addConnection(outputStream); replicaSender.addConnection(outputStream);
System.out.println("hi");
byte[] decode = rdbFileInfo.getContent(); byte[] decode = rdbFileInfo.getContent();
try { try {
return createCommandBytes(Command.FULLRESYNC, decode, serverInfo); return createCommandBytes(Command.FULLRESYNC, decode, serverInfo);
......
...@@ -33,10 +33,10 @@ public class ConnectionHandler { ...@@ -33,10 +33,10 @@ public class ConnectionHandler {
} }
public BufferedReader handleConnection() { public BufferedReader handleConnection() {
try (OutputStream outputStream = socket.getOutputStream(); try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()))) { OutputStream outputStream = socket.getOutputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
commandSender.sendCommand(bufferedReader, outputStream); commandSender.sendCommand(bufferedReader, outputStream);
String line; String line;
while ((line = bufferedReader.readLine()) != null) { while ((line = bufferedReader.readLine()) != null) {
if (line.isEmpty()) { if (line.isEmpty()) {
......
...@@ -47,10 +47,10 @@ public class SendToReplica implements Closeable { ...@@ -47,10 +47,10 @@ public class SendToReplica implements Closeable {
byte[] commandBytes = command.getBytes(); byte[] commandBytes = command.getBytes();
connectedReplicas.forEach(replica -> { connectedReplicas.forEach(replica -> {
try { try {
try (OutputStream outputStream = replica.os()) { OutputStream outputStream = replica.os();
outputStream.write(commandBytes); outputStream.write(commandBytes);
outputStream.flush(); outputStream.flush();
}
} catch (IOException e) { } catch (IOException e) {
logger.log(Level.SEVERE, "Failed to send command to replica ", e); logger.log(Level.SEVERE, "Failed to send command to replica ", e);
} }
...@@ -67,7 +67,6 @@ public class SendToReplica implements Closeable { ...@@ -67,7 +67,6 @@ public class SendToReplica implements Closeable {
} }
public void addConnection(OutputStream outputStream) { public void addConnection(OutputStream outputStream) {
connectedReplicas.add(new ConnectedReplica(outputStream)); connectedReplicas.add(new ConnectedReplica(outputStream));
logger.info("SIZE CONNECTED REPLICAS = " + connectedReplicas.size()); logger.info("SIZE CONNECTED REPLICAS = " + connectedReplicas.size());
......
...@@ -8,7 +8,7 @@ import java.util.Map; ...@@ -8,7 +8,7 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
public class ServerBuilder { public class ServerBuilder {
private int port = 16380; private int port = 16379;
private String role; private String role;
private final String[] masterPortAndHost; private final String[] masterPortAndHost;
private final static ServerInfo info = ServerInfo.getInstance(); private final static ServerInfo info = ServerInfo.getInstance();
......
...@@ -51,7 +51,7 @@ public class RdbFileInfo { ...@@ -51,7 +51,7 @@ public class RdbFileInfo {
} }
public void setFile(Map<String, String> parameters) { public void setFile(Map<String, String> parameters) {
String path = "C:\\Users\\Amir\\Desktop\\Projects\\Redis\\tmp"; String path = "C:\\Users\\Amir\\Desktop\\Games\\Redis\\tmp\\";
String fileName = "rdb.rdb"; String fileName = "rdb.rdb";
out.println(parameters); out.println(parameters);
if (parameters.containsKey("--dir")) { if (parameters.containsKey("--dir")) {
......
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