summaryrefslogtreecommitdiffstats
path: root/src/main/java/derms/replica1
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/derms/replica1')
-rw-r--r--src/main/java/derms/replica1/DERMSServerPublisher.java19
-rw-r--r--src/main/java/derms/replica1/Replica1.java32
2 files changed, 44 insertions, 7 deletions
diff --git a/src/main/java/derms/replica1/DERMSServerPublisher.java b/src/main/java/derms/replica1/DERMSServerPublisher.java
index 3edf16c..442f844 100644
--- a/src/main/java/derms/replica1/DERMSServerPublisher.java
+++ b/src/main/java/derms/replica1/DERMSServerPublisher.java
@@ -3,14 +3,25 @@ package derms.replica1;
import javax.xml.ws.Endpoint;
public class DERMSServerPublisher {
+
+ private static Endpoint[] endpoints = new Endpoint[3];
+
public static void main(String[] args) {
try {
- Endpoint.publish("http://localhost:8387/ws/derms", new DERMSServer("MTL"));
- Endpoint.publish("http://localhost:8081/ws/derms", new DERMSServer("QUE"));
- Endpoint.publish("http://localhost:8082/ws/derms", new DERMSServer("SHE"));
+ endpoints[0] = Endpoint.publish("http://localhost:8387/ws/derms", new DERMSServer("MTL"));
+ endpoints[1] = Endpoint.publish("http://localhost:8081/ws/derms", new DERMSServer("QUE"));
+ endpoints[3] = Endpoint.publish("http://localhost:8082/ws/derms", new DERMSServer("SHE"));
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
- System.out.println("DERMS Web Service is published at http://localhost:8387/ws/derms");
+ }
+
+ public static void stop() {
+ for (Endpoint endpoint : endpoints) {
+ if (endpoint != null && endpoint.isPublished()) {
+ endpoint.stop();
+ System.out.println("DERMS Server is stopped.");
+ }
+ }
}
} \ No newline at end of file
diff --git a/src/main/java/derms/replica1/Replica1.java b/src/main/java/derms/replica1/Replica1.java
index a59ed4c..c9e080d 100644
--- a/src/main/java/derms/replica1/Replica1.java
+++ b/src/main/java/derms/replica1/Replica1.java
@@ -5,6 +5,7 @@ import derms.ReplicaManager;
import derms.Request;
import derms.Response;
import derms.replica2.DermsLogger;
+import derms.util.TestLogger;
import derms.util.ThreadPool;
import java.io.IOException;
@@ -26,6 +27,7 @@ public class Replica1 implements Replica {
private final String coordinatorClientID = "MTLC1111";
private final ReplicaManager replicaManager;
private DERMSServer server;
+ private boolean byzFailure;
public Replica1(ReplicaManager replicaManager) {
this.replicaManager = replicaManager;
@@ -50,7 +52,21 @@ public class Replica1 implements Replica {
}
@Override
- public void startProcess() {
+ public void startProcess(int byzantine, int crash) {
+ // [TEST] Detect crash
+ if (crash == 1) {
+ alive = false;
+ } else {
+ alive = true;
+ }
+
+ // [TEST] Detect byzantine failure
+ if (byzantine == 1) {
+ byzFailure = true;
+ } else {
+ byzFailure = false;
+ }
+
try {
server = new DERMSServer("MTL");
} catch (InterruptedException e) {
@@ -66,13 +82,20 @@ public class Replica1 implements Replica {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
- alive = true;
+
log.info(getClass().getSimpleName() + " started.");
log.config("Local address is "+localAddr.toString());
}
@Override
public void processRequest(Request request) {
+ // [TEST] Simulate byzantine failure (return incorrect value)
+ if (byzFailure == true) {
+ Response response = new Response(request, replicaManager.getReplicaId(), "BYZANTINE FAILURE", false);
+ replicaManager.sendResponseToFE(response);
+ return;
+ }
+
log.info(request.toString());
String status = "";
@@ -121,7 +144,10 @@ public class Replica1 implements Replica {
ThreadPool.shutdown(pool, log);
alive = false;
log.info("Finished shutting down.");
- startProcess();
+
+ // [TEST] Restart process without byzantine failure or crash
+ TestLogger.log("REPLICA 1: {RESTARTED}");
+ startProcess(0, 0);
}
@Override