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