Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Coordinator.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,17 @@ private void checkVotes() throws IOException {

if (decision) {

this.coordinatorLog.log("COMMIT", true, true, true);
this.coordinatorLog.log("COMMIT", true);

} else {

this.coordinatorLog.log("ABORT", true, true, true);
this.coordinatorLog.log("ABORT", true);

}

if(this.sockets.size() == 0) {

this.coordinatorLog.log("END", false, true, true);
this.coordinatorLog.log("END");
this.failedSubordinatesLog.emptyLog();

}
Expand Down Expand Up @@ -415,7 +415,7 @@ private void checkAcknowledgements(List<Integer> subordinatesToBeChecked) throws

} else {

this.coordinatorLog.log("END", false, true, true);
this.coordinatorLog.log("END");

if (this.isRecoveryProcessStarted)
Printer.print("=============== END OF RECOVERY PROCESS =================\n", "orange");
Expand Down
21 changes: 16 additions & 5 deletions src/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,27 @@ public Logger(String filename, String nodeType, boolean append) throws IOExcepti

}

public void log(String msg) throws IOException {
log(msg, false, true, true);
}

public void log(String msg, boolean forceWrite) throws IOException {
log(msg, forceWrite, true, true);
}

public void log(String msg, boolean forceWrite, boolean appendDate) throws IOException {
log(msg, forceWrite, appendDate, true);
}

public void log(String msg, boolean forceWrite, boolean appendDate, boolean verbose) throws IOException {
String newLogEntry;
String newLogEntry = msg;

if(appendDate) {
String timeStamp = dateFormat.format(new Date());
newLogEntry = msg + " " + timeStamp + "\n";
} else {
newLogEntry = msg + "\n";
String timeStamp = dateFormat.format(new Date());
newLogEntry += " " + timeStamp;
}

newLogEntry += "\n";

this.bw.write(newLogEntry);
this.bw.flush();
Expand Down
12 changes: 6 additions & 6 deletions src/Subordinate.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private void phaseOne() throws IOException {
inputHandler.getUserInput().toUpperCase().equals("Y") &&
((System.currentTimeMillis() - startTime) < Coordinator.TIMEOUT_MILLIS)) {

this.SubordinateLog.log("PREPARED", true, true, true);
this.SubordinateLog.log("PREPARED", true);
this.send("Y");
Printer.print("=============== END OF PHASE 1 =================\n", "blue");
this.phaseTwo();
Expand All @@ -151,7 +151,7 @@ private void phaseOne() throws IOException {
inputHandler.getUserInput().toUpperCase().equals("N") &&
((System.currentTimeMillis() - startTime) < Coordinator.TIMEOUT_MILLIS)) {

this.SubordinateLog.log("ABORT", true, true, true);
this.SubordinateLog.log("ABORT", true);
this.send("N");
Printer.print("=============== END OF PHASE 1 =================\n", "blue");
this.phaseTwo();
Expand Down Expand Up @@ -238,11 +238,11 @@ private void phaseTwo() throws IOException {

if(!this.SubordinateLog.readLogBottom().split(" ")[0].equals("ABORT")){

this.SubordinateLog.log("ABORT", true, true, true);
this.SubordinateLog.log("ABORT", true);

}

this.SubordinateLog.log("END", false, true, true);
this.SubordinateLog.log("END");

Printer.print("=============== END OF RECOVERY PROCESS =================", "orange");
Printer.print("=============== UNILATERAL ABORT =================\n", "red");
Expand All @@ -263,7 +263,7 @@ private void phaseTwo() throws IOException {
if (!this.SubordinateLog.readLogBottom().split(" ")[0].equals("ABORT") &&
!this.SubordinateLog.readLogBottom().split(" ")[0].equals("COMMIT")) {

this.SubordinateLog.log(decisionMsg, true, true, true);
this.SubordinateLog.log(decisionMsg, true);

}

Expand Down Expand Up @@ -373,7 +373,7 @@ private void sendAck() throws IOException {
(timeDiff < Coordinator.TIMEOUT_MILLIS)) {

this.send("ACK");
this.SubordinateLog.log("END", false, true, true);
this.SubordinateLog.log("END");
Printer.print("=============== END OF PHASE 2 =================\n", "green");


Expand Down