m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu/mimuw/cloudatlas
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/pl/edu/mimuw/cloudatlas')
-rw-r--r--src/main/java/pl/edu/mimuw/cloudatlas/fetcher/Fetcher.java75
1 files changed, 75 insertions, 0 deletions
diff --git a/src/main/java/pl/edu/mimuw/cloudatlas/fetcher/Fetcher.java b/src/main/java/pl/edu/mimuw/cloudatlas/fetcher/Fetcher.java
new file mode 100644
index 0000000..67d7165
--- /dev/null
+++ b/src/main/java/pl/edu/mimuw/cloudatlas/fetcher/Fetcher.java
@@ -0,0 +1,75 @@
+package pl.edu.mimuw.cloudatlas.fetcher;
+
+import pl.edu.mimuw.cloudatlas.agent.Api;
+
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.google.gson.Gson;
+
+public class Fetcher {
+
+// private static String processAttribs(String jsonAttribs) {
+// Serializer serializer = new Serializer();
+// return
+// }
+
+ // https://jj09.net/interprocess-communication-python-java/
+ private static void fetchData() {
+ try {
+ Registry registry = LocateRegistry.getRegistry("localhost");
+ Api stub = (Api) registry.lookup("Api");
+ System.out.println("Fetcher runs with registry"); // TODO
+
+ String pythonScript = Fetcher.class.getResource("data_fetcher.py").getFile();
+ String pythonCmd = "/usr/bin/python3 " + pythonScript;
+ System.out.println("cmd: " + pythonCmd);
+ Process p = Runtime.getRuntime().exec(pythonCmd);
+ BufferedReader bufferRead = new BufferedReader( new InputStreamReader(p.getInputStream()));
+ BufferedReader errorRead = new BufferedReader( new InputStreamReader(p.getErrorStream()));
+
+
+ System.out.println("Gonna read some attribs");
+ String jsonAttribs = bufferRead.readLine();
+ String serializedAttribs;
+
+ System.out.println("Read some attribs");
+ System.out.println(jsonAttribs);
+ System.out.println("Got some attribs");
+
+ ArrayList aa = deserializeAttribs(jsonAttribs);
+ System.out.println(aa);
+
+ // TODO different condition
+ while(!jsonAttribs.equals("x")) {
+ System.out.println(jsonAttribs);
+ System.out.flush();
+ serializedAttribs = "1";
+ // stub.setAttributeValue(serializedAttribs);
+ jsonAttribs = bufferRead.readLine();
+ }
+
+ bufferRead.close();
+
+ } catch(IOException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ System.err.println("Fetcher exception:");
+ e.printStackTrace();
+ }
+ }
+
+
+ public static void main(String[] args) {
+ fetchData();
+ }
+
+ public static ArrayList deserializeAttribs(String serializedAttribs) {
+ Gson g = new Gson();
+
+ return g.fromJson(serializedAttribs, ArrayList.class);
+ }
+}