m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/pl/edu
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-11-15 14:04:03 +0100
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-11-15 14:04:03 +0100
commitea47b82d7553012b39f6ab6a836a1832da40ca4e (patch)
tree2a9203f12c94b6bd8e718aa703269d39465ba029 /src/main/java/pl/edu
parentad5bbbb8f4f7ca5f07b4e1f72491755114363726 (diff)
Add fetcher skeleton
Diffstat (limited to 'src/main/java/pl/edu')
-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);
+ }
+}