40
|
1 package jp.ac.u_ryukyu.alicevnc;
|
|
2
|
|
3 import java.io.BufferedWriter;
|
|
4 import java.io.File;
|
|
5 import java.io.FileWriter;
|
|
6 import java.io.IOException;
|
|
7 import java.io.PrintWriter;
|
|
8 import java.util.ArrayList;
|
|
9
|
|
10 import alice.codesegment.CodeSegment;
|
|
11 import alice.datasegment.CommandType;
|
41
|
12 import alice.datasegment.ReceiveData;
|
40
|
13 import alice.datasegment.Receiver;
|
|
14
|
|
15 public class ReceiveMeasurement extends CodeSegment {
|
|
16
|
|
17 private Receiver info = ids.create(CommandType.TAKE);
|
|
18 private Receiver info1 = ids.create(CommandType.PEEK);
|
|
19 private Receiver info2 = ids.create(CommandType.PEEK);
|
|
20
|
|
21 public ReceiveMeasurement() {
|
|
22 info.setKey("measurement");
|
|
23 info1.setKey("_CLIST");
|
|
24 info2.setKey("AliceVNCConfig");
|
|
25 }
|
|
26
|
|
27 @SuppressWarnings("unchecked")
|
|
28 @Override
|
|
29 public void run() {
|
41
|
30 long time = System.currentTimeMillis();
|
40
|
31 ArrayList<String> clist = info1.asClass(ArrayList.class);
|
|
32 boolean route = true;
|
|
33 for (String node : clist){
|
|
34 if ("parent".equals(node)) {
|
|
35 route = false;
|
|
36 break;
|
|
37 }
|
|
38 }
|
|
39
|
|
40 try {
|
|
41 if (route) {
|
|
42 AliceVNCConfig conf = info2.asClass(AliceVNCConfig.class);
|
|
43 if (conf.getFilePath()!=null) {
|
|
44 File file = new File(conf.getFilePath());
|
|
45 if (!file.exists()) {
|
|
46 file.createNewFile();
|
|
47 }
|
|
48 FileWriter filewriter = new FileWriter(file, true);
|
|
49 BufferedWriter bw = new BufferedWriter(filewriter);
|
|
50 PrintWriter pw = new PrintWriter(bw);
|
|
51
|
41
|
52 ReceiveData r = info.getReceiveData();
|
|
53 pw.println(r.depth/2+" "+(time - r.time)+" "+((byte[])info.getObj()).length);
|
40
|
54 pw.close();
|
|
55 }
|
|
56 } else {
|
|
57 ods.put("parent", info.key, info.getReceiveData());
|
|
58 }
|
|
59
|
|
60 } catch (IOException e) {
|
|
61
|
|
62 }
|
|
63 this.recycle();
|
|
64 }
|
|
65
|
|
66 }
|