134
|
1 package alice.test.topology.aquarium;
|
107
|
2
|
170
|
3 import java.util.Random;
|
107
|
4 import java.util.regex.Matcher;
|
|
5 import java.util.regex.Pattern;
|
|
6
|
|
7 import alice.codesegment.CodeSegment;
|
|
8 import alice.datasegment.CommandType;
|
|
9 import alice.datasegment.Receiver;
|
|
10
|
|
11
|
|
12 public class CheckMyName extends CodeSegment {
|
138
|
13 private Receiver host = ids.create(CommandType.PEEK);
|
|
14 private Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$");
|
|
15 private String key = "fish";
|
107
|
16
|
135
|
17 public CheckMyName(){
|
217
|
18 host.setKey("host");
|
135
|
19 }
|
|
20
|
107
|
21 @Override
|
|
22 public void run(){
|
217
|
23 String name = host.asString();
|
107
|
24 Matcher matcher = pattern.matcher(name);
|
|
25
|
|
26 matcher.find();
|
|
27 String type = matcher.group(1);
|
110
|
28 int num = new Integer(matcher.group(2));
|
217
|
29 ods.put("host_num", num*2);
|
170
|
30 MakeFrame frame = new MakeFrame(name,num*2);
|
217
|
31 ods.put("num", 1);
|
135
|
32
|
107
|
33 if (type.equals("cli")){
|
110
|
34 System.out.println("cli"+num);
|
259
|
35 new TakeMynum();
|
107
|
36 }else if (type.equals("node")){
|
110
|
37 System.out.println("node"+num);
|
|
38 if (num != 0){
|
139
|
39 new TakeMynum();
|
171
|
40 } else {
|
|
41 new SendMaxsize(0);
|
109
|
42 }
|
107
|
43 }
|
171
|
44 new CheckLocalIndex("maxsize",0);
|
109
|
45
|
217
|
46 ods.update(key, new FishPoint(-0.1f,-0.1f));
|
262
|
47 new SetLocation(new MakeObject(frame), key, 0);
|
111
|
48 new CheckLocalIndex(key,1);
|
145
|
49 for (int i = 0; i < 3 ; i++){
|
112
|
50 key = "fish"+i;
|
133
|
51 if (num == 0) new AutoIncrement(key,0);
|
217
|
52 ods.update(key, new FishPoint((float)Math.random(),
|
145
|
53 (float)Math.random(), (float)Math.random()));
|
262
|
54 new SetLocation(new MakeObject(frame), key, 0);
|
145
|
55 new CheckLocalIndex(key,1);
|
|
56 }
|
270
|
57 /*
|
145
|
58 for (int i = 3; i < 6 ; i++){
|
|
59 key = "fish"+i;
|
171
|
60 if (num == 1) new AutoIncrement(key,0);
|
170
|
61 Random rnd = new Random();
|
|
62 int tmp = rnd.nextInt(3);
|
|
63 int rand = tmp + 1;
|
217
|
64 ods.update(key, new FishPoint( (float)rand,
|
145
|
65 -(float)Math.random(), -(float)Math.random()));
|
262
|
66 new SetLocation(new MakeObject(frame), key, 0);
|
143
|
67 new CheckLocalIndex(key,1);
|
|
68 }
|
|
69
|
145
|
70 for (int i = 6; i < 9 ; i++){
|
143
|
71 key = "fish"+i;
|
171
|
72 if (num == 2) new AutoIncrement(key,0);
|
170
|
73 Random rnd = new Random();
|
|
74 int tmp = rnd.nextInt(3);
|
|
75 int rand = tmp + 3;
|
217
|
76 ods.update(key, new FishPoint( (float)rand,
|
145
|
77 (float)Math.random(), -(float)Math.random()));
|
262
|
78 new SetLocation(new MakeObject(frame), key, 0);
|
112
|
79 new CheckLocalIndex(key,1);
|
|
80 }
|
114
|
81
|
145
|
82 for (int i = 9; i < 12 ; i++){
|
|
83 key = "fish"+i;
|
171
|
84 if (num == 3) new AutoIncrement(key,0);
|
170
|
85
|
|
86 Random rnd = new Random();
|
|
87 int tmp = rnd.nextInt(3);
|
|
88 int rand = tmp + 5;
|
|
89
|
217
|
90 ods.update(key, new FishPoint( (float)rand,
|
145
|
91 -(float)Math.random(), (float)Math.random()));
|
262
|
92 new SetLocation(new MakeObject(frame), key, 0);
|
145
|
93 new CheckLocalIndex(key,1);
|
270
|
94 }*/
|
171
|
95
|
107
|
96 }
|
|
97 }
|