blob: f7fdab268d958d26c00a1d55527de6c17a93cb8a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
package pl.edu.mimuw.cloudatlas.fetcher;
import pl.edu.mimuw.cloudatlas.api.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);
}
}
|