summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-12-03 12:38:16 -0500
committerSam Anthony <sam@samanthony.xyz>2024-12-03 12:38:16 -0500
commit19166b8af1bf635f3f11a21abcc22cba46cebd4a (patch)
tree1365e248dcbc64a38d21648fc58aaf541dc7fb26
parent21f4046ae1bf51dfe00f6d481e323f06b4300071 (diff)
downloadsoen423-19166b8af1bf635f3f11a21abcc22cba46cebd4a.zip
pass IP to replica manager
-rw-r--r--src/main/java/derms/ReplicaManager.java24
-rw-r--r--src/test/java/derms/test/SystemTest.java2
2 files changed, 13 insertions, 13 deletions
diff --git a/src/main/java/derms/ReplicaManager.java b/src/main/java/derms/ReplicaManager.java
index 252953c..a3008de 100644
--- a/src/main/java/derms/ReplicaManager.java
+++ b/src/main/java/derms/ReplicaManager.java
@@ -23,7 +23,7 @@ import java.util.Objects;
import java.util.logging.Logger;
public class ReplicaManager {
- public static final String usage = "Usage: java ReplicaManager <replicaId> <city> <frontEndIP> <byzantine(0 or 1)> <crash(0 or 1)>";
+ public static final String usage = "Usage: java ReplicaManager <replicaId> <city> <replicaManagerIP> <frontEndIP> <byzantine(0 or 1)> <crash(0 or 1)>";
private final int replicaId;
private final String city;
private Replica replica;
@@ -33,13 +33,13 @@ public class ReplicaManager {
private ReliableUnicastSender<Response> unicastSender;
private TotalOrderMulticastReceiver multicastReceiver;
- public ReplicaManager(int replicaId, String city, InetAddress frontEndIP, int byzantine, int crash) throws IOException {
+ public ReplicaManager(int replicaId, String city, InetAddress replicaManagerIP, InetAddress frontEndIP, int byzantine, int crash) throws IOException {
this.replicaId = replicaId;
this.city = city;
this.log = Logger.getLogger(getClass().getName());
initUnicastSender(frontEndIP);
initReplica(byzantine, crash);
- initMulticastReceiver();
+ initMulticastReceiver(replicaManagerIP);
startHeartbeatThread();
}
@@ -81,11 +81,10 @@ public class ReplicaManager {
replica.startProcess(byzantine, crash);
}
- private void initMulticastReceiver() throws IOException {
+ private void initMulticastReceiver(InetAddress replicaManagerIP) throws IOException {
InetSocketAddress group = Config.group;
- InetAddress localAddress = InetAddress.getLocalHost(); // Your local address
- NetworkInterface netInterface = NetworkInterface.getByInetAddress(localAddress);
- multicastReceiver = new TotalOrderMulticastReceiver<Request>(group, localAddress, netInterface);
+ NetworkInterface netInterface = NetworkInterface.getByInetAddress(replicaManagerIP);
+ multicastReceiver = new TotalOrderMulticastReceiver<Request>(group, replicaManagerIP, netInterface);
new Thread(() -> {
while (true) {
@@ -168,7 +167,7 @@ public class ReplicaManager {
}
public static void main(String[] args) {
- if (args.length < 3) {
+ if (args.length < 4) {
System.err.println(usage);
System.exit(1);
}
@@ -176,10 +175,11 @@ public class ReplicaManager {
try {
int replicaId = Integer.parseInt(args[0]);
String city = args[1];
- InetAddress frontEndIP = InetAddress.getByName(args[2]);
- int byzantine = Integer.parseInt(args[3]);
- int crash = Integer.parseInt(args[4]);
- ReplicaManager replicaManager = new ReplicaManager(replicaId, city, frontEndIP, byzantine, crash);
+ InetAddress replicaManagerIP = InetAddress.getByName(args[2]);
+ InetAddress frontEndIP = InetAddress.getByName(args[3]);
+ int byzantine = Integer.parseInt(args[4]);
+ int crash = Integer.parseInt(args[5]);
+ ReplicaManager replicaManager = new ReplicaManager(replicaId, city, replicaManagerIP, frontEndIP, byzantine, crash);
System.out.println("ReplicaManager " + replicaId + " is running.");
} catch (IOException e) {
System.err.println("Failed to start ReplicaManager: " + e.getMessage());
diff --git a/src/test/java/derms/test/SystemTest.java b/src/test/java/derms/test/SystemTest.java
index 59b08fa..aa3e066 100644
--- a/src/test/java/derms/test/SystemTest.java
+++ b/src/test/java/derms/test/SystemTest.java
@@ -70,7 +70,7 @@ class SystemTest {
@Test
void testNormal() throws IOException {
// Replica 1
- String[] argsRM = {"1", "MTL", IP, "0", "0"};
+ String[] argsRM = {"1", "MTL", IP, IP, "0", "0"};
// [TODO]
// Run the main function of the desired replica, for example: