107
|
1 package alice.test.topology.fishmodel.beta;
|
|
2
|
|
3 import java.util.regex.Matcher;
|
|
4 import java.util.regex.Pattern;
|
|
5
|
|
6 import alice.codesegment.CodeSegment;
|
|
7 import alice.datasegment.CommandType;
|
|
8 import alice.datasegment.Receiver;
|
111
|
9 import alice.test.topology.fishmodel.alpha.AutoIncrement;
|
|
10 import alice.test.topology.fishmodel.alpha.SetLocation;
|
109
|
11 import alice.test.topology.fishmodel.alpha.FishPoint;
|
|
12 import alice.test.topology.fishmodel.alpha.MakeFrame;
|
|
13 import alice.test.topology.fishmodel.alpha.MakeObject;
|
107
|
14
|
|
15
|
|
16 public class CheckMyName extends CodeSegment {
|
|
17 Receiver host = ids.create(CommandType.PEEK);
|
|
18 Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$");
|
109
|
19 String key = "fish";
|
107
|
20
|
|
21 @Override
|
|
22 public void run(){
|
|
23
|
|
24 String name = host.asString();
|
|
25 Matcher matcher = pattern.matcher(name);
|
|
26
|
|
27 matcher.find();
|
|
28 String type = matcher.group(1);
|
110
|
29 int num = new Integer(matcher.group(2));
|
107
|
30
|
111
|
31 MakeFrame frame = new MakeFrame(name);
|
107
|
32 RoutingTable routing = new RoutingTable();
|
111
|
33
|
|
34
|
107
|
35
|
|
36 if (type.equals("cli")){
|
110
|
37 System.out.println("cli"+num);
|
107
|
38 routing.table.add(new Routing("parent"));
|
|
39 ods.put("local", "list", routing);
|
|
40
|
|
41 new AddRoutingTable(routing,0);
|
|
42 ods.put("parent", "member", name);
|
|
43
|
|
44 }else if (type.equals("node")){
|
110
|
45 System.out.println("node"+num);
|
|
46 if (num != 0){
|
109
|
47 routing.table.add(new Routing("parent"));
|
|
48 ods.put("parent", "member", name);
|
|
49
|
|
50 }
|
107
|
51 ods.put("local", "list", routing);
|
|
52 new AddRoutingTable(routing,0);
|
|
53
|
|
54 }
|
109
|
55
|
111
|
56 ods.update("local", key, new FishPoint(0.0f,0.0f));
|
|
57 new SetLocation(new MakeObject(frame),key,0,num);
|
|
58 new CheckLocalIndex(key,1);
|
|
59 key = "fish1";
|
|
60 if (num == 0) new AutoIncrement(key,0);
|
|
61 ods.update("local", key, new FishPoint(0.0f,0.0f));
|
|
62 new SetLocation(new MakeObject(frame),key,0,num);
|
|
63 new CheckLocalIndex(key,1);
|
109
|
64
|
107
|
65 }
|
|
66 }
|