From 96e9a7d3c6c2f07c29278b9e898819d731a99180 Mon Sep 17 00:00:00 2001 From: ezTxmMC Date: Tue, 10 Dec 2024 12:17:42 +0100 Subject: [PATCH] added launch configuration --- .../eu/smoothcloud/node/SmoothCloudNode.java | 5 +- .../configuration/LaunchConfiguration.java | 63 +++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 smoothcloud-node/src/main/java/eu/smoothcloud/node/configuration/LaunchConfiguration.java diff --git a/smoothcloud-node/src/main/java/eu/smoothcloud/node/SmoothCloudNode.java b/smoothcloud-node/src/main/java/eu/smoothcloud/node/SmoothCloudNode.java index 1861ad3..ac589fc 100644 --- a/smoothcloud-node/src/main/java/eu/smoothcloud/node/SmoothCloudNode.java +++ b/smoothcloud-node/src/main/java/eu/smoothcloud/node/SmoothCloudNode.java @@ -1,5 +1,6 @@ package eu.smoothcloud.node; +import eu.smoothcloud.node.configuration.LaunchConfiguration; import eu.smoothcloud.node.console.Console; import eu.smoothcloud.node.util.ThreadManager; @@ -9,14 +10,15 @@ public static void main(String[] args) { new SmoothCloudNode(); } + private LaunchConfiguration launchConfiguration; private Console console; public SmoothCloudNode() { ThreadManager manager = new ThreadManager(12); - System.out.println("DEBUG: Before console.start()"); manager.startTask("Console", this::startConsole); print(console); + this.launchConfiguration = new LaunchConfiguration(); } private void startConsole() { @@ -27,5 +29,4 @@ private void startConsole() { private void print(Console console) { console.print("&eInitialize Cloud"); } - } diff --git a/smoothcloud-node/src/main/java/eu/smoothcloud/node/configuration/LaunchConfiguration.java b/smoothcloud-node/src/main/java/eu/smoothcloud/node/configuration/LaunchConfiguration.java new file mode 100644 index 0000000..6ff52be --- /dev/null +++ b/smoothcloud-node/src/main/java/eu/smoothcloud/node/configuration/LaunchConfiguration.java @@ -0,0 +1,63 @@ +package eu.smoothcloud.node.configuration; + +import org.json.JSONException; +import org.json.JSONObject; + +public class LaunchConfiguration { + private final JSONObject jsonObject; + + public LaunchConfiguration() { + this.jsonObject = new JSONObject("launcher.json"); + } + + public void setLanguage(String language) { + this.setValue("language", language); + } + + public void setHost(String host) { + this.setValue("host", host); + } + + public void setPort(int port) { + this.setValue("port", port); + } + + public void setMemory(String memory) { + this.setValue("memory", memory); + } + + public String getLanguage() { + return (String) this.getValue("language"); + } + + public String getHost() { + return (String) this.getValue("host"); + } + + public int getPort() { + return (int) this.getValue("port"); + } + + public String getMemory() { + return (String) this.getValue("memory"); + } + + private boolean setValue(String key, Object value) { + try { + this.jsonObject.put(key, value); + return true; + } catch (JSONException e) { + e.printStackTrace(); + return false; + } + } + + private Object getValue(String key) { + try { + return this.jsonObject.get(key); + } catch (JSONException e) { + e.printStackTrace(); + } + return null; + } +}