From bb0d92a3a0339695776797d25252815bf8921fa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Fri, 10 Jan 2020 15:53:02 +0100 Subject: Separate server from udup --- .../java/pl/edu/mimuw/cloudatlas/agent/Agent.java | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java index 256fa6b..ad2a650 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java @@ -39,18 +39,15 @@ public class Agent { } } - public static HashMap initializeModules() { + public static HashMap initializeModules() throws UnknownHostException { HashMap modules = new HashMap(); modules.put(ModuleType.TIMER_SCHEDULER, new TimerScheduler(ModuleType.TIMER_SCHEDULER)); modules.put(ModuleType.RMI, new Remik()); Long freshnessPeriod = new Long(System.getProperty("freshness_period")); modules.put(ModuleType.STATE, new Stanik(freshnessPeriod)); modules.put(ModuleType.QUERY, new Qurnik()); - try { - modules.put(ModuleType.UDP, new UDUP(InetAddress.getByName("127.0.0.1"), 5988, 5000, 20000)); - } catch (UnknownHostException e) { - e.printStackTrace(); - } + UDUPServer server = new UDUPServer(InetAddress.getByName("127.0.0.1"), 5988, 2000); + modules.put(ModuleType.UDP, new UDUP(5988, 5000, 20000, null)); // TODO add modules as we implement them return modules; } @@ -89,14 +86,24 @@ public class Agent { } public static void runModulesAsThreads() { - HashMap modules = initializeModules(); + HashMap modules = null; + + try { + modules = initializeModules(); + } catch (UnknownHostException e) { + System.out.println("Module initialization failed"); + e.printStackTrace(); + return; + } + HashMap executors = initializeExecutors(modules); ArrayList executorThreads = initializeExecutorThreads(executors); - eventBus = new EventBus(executors); + Thread UDUPServerThread = new Thread(((UDUP) modules.get(ModuleType.UDP)).getServer()); Thread eventBusThread = new Thread(eventBus); System.out.println("Initializing event bus"); eventBusThread.start(); + UDUPServerThread.start(); } private static void initZones() { -- cgit v1.2.3 From f042953bdbe2a5e0d9e9e19d275fd45a958fe626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Fri, 10 Jan 2020 16:09:19 +0100 Subject: Set udup config from system properties --- src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java index ad2a650..a178193 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java @@ -2,6 +2,7 @@ package pl.edu.mimuw.cloudatlas.agent; import java.net.Inet4Address; import java.net.InetAddress; +import java.net.SocketException; import java.net.UnknownHostException; import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; @@ -39,15 +40,19 @@ public class Agent { } } - public static HashMap initializeModules() throws UnknownHostException { + public static HashMap initializeModules() throws UnknownHostException, SocketException { HashMap modules = new HashMap(); modules.put(ModuleType.TIMER_SCHEDULER, new TimerScheduler(ModuleType.TIMER_SCHEDULER)); modules.put(ModuleType.RMI, new Remik()); - Long freshnessPeriod = new Long(System.getProperty("freshness_period")); + Long freshnessPeriod = Long.getLong(System.getProperty("freshness_period")); modules.put(ModuleType.STATE, new Stanik(freshnessPeriod)); modules.put(ModuleType.QUERY, new Qurnik()); - UDUPServer server = new UDUPServer(InetAddress.getByName("127.0.0.1"), 5988, 2000); - modules.put(ModuleType.UDP, new UDUP(5988, 5000, 20000, null)); + + Integer port = Integer.getInteger(System.getProperty("port")); + Integer timeout = Integer.getInteger(System.getProperty("timeout")); + Integer bufsize = Integer.getInteger(System.getProperty("bufsize")); + UDUPServer server = new UDUPServer(InetAddress.getByName("127.0.0.1"), port, bufsize); + modules.put(ModuleType.UDP, new UDUP(port, timeout, bufsize, server)); // TODO add modules as we implement them return modules; } @@ -90,7 +95,7 @@ public class Agent { try { modules = initializeModules(); - } catch (UnknownHostException e) { + } catch (UnknownHostException | SocketException e) { System.out.println("Module initialization failed"); e.printStackTrace(); return; -- cgit v1.2.3 From ad872a25f94f6297a659cf945c4e1547ed8f28d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magdalena=20Grodzi=C5=84ska?= Date: Fri, 10 Jan 2020 16:29:49 +0100 Subject: Fix getting system properties --- src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java') diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java index a178193..62cd544 100644 --- a/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java +++ b/src/main/java/pl/edu/mimuw/cloudatlas/agent/Agent.java @@ -40,17 +40,17 @@ public class Agent { } } - public static HashMap initializeModules() throws UnknownHostException, SocketException { + public static HashMap initializeModules() throws UnknownHostException, SocketException, NullPointerException { HashMap modules = new HashMap(); modules.put(ModuleType.TIMER_SCHEDULER, new TimerScheduler(ModuleType.TIMER_SCHEDULER)); modules.put(ModuleType.RMI, new Remik()); - Long freshnessPeriod = Long.getLong(System.getProperty("freshness_period")); + Long freshnessPeriod = Long.getLong("freshness_period"); modules.put(ModuleType.STATE, new Stanik(freshnessPeriod)); modules.put(ModuleType.QUERY, new Qurnik()); - Integer port = Integer.getInteger(System.getProperty("port")); - Integer timeout = Integer.getInteger(System.getProperty("timeout")); - Integer bufsize = Integer.getInteger(System.getProperty("bufsize")); + Integer port = Integer.getInteger("UDUPServer.port"); + Integer timeout = Integer.getInteger("UDUPServer.timeout"); + Integer bufsize = Integer.getInteger("UDUPServer.bufsize"); UDUPServer server = new UDUPServer(InetAddress.getByName("127.0.0.1"), port, bufsize); modules.put(ModuleType.UDP, new UDUP(port, timeout, bufsize, server)); // TODO add modules as we implement them -- cgit v1.2.3