96
|
1 package alice.test.topology.share;
|
|
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;
|
|
9
|
|
10 public class CheckMyName extends CodeSegment {
|
|
11 Receiver host = ids.create(CommandType.PEEK);
|
|
12 Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$");
|
|
13
|
|
14 public CheckMyName(){
|
|
15 host.setKey("local","host");
|
|
16 }
|
|
17
|
|
18
|
|
19 @Override
|
|
20 public synchronized void run(){
|
|
21
|
|
22 String name = host.asString();
|
|
23 Matcher matcher = pattern.matcher(name);
|
|
24
|
|
25 matcher.find();
|
|
26 String type = matcher.group(1);
|
|
27 int cliNum = new Integer(matcher.group(2));
|
|
28
|
|
29 if (type.equals("cli")){
|
|
30 System.out.println("cli"+cliNum);
|
|
31 ods.update("local", "fish", 0);
|
|
32 new RelayPoint("fish");
|
|
33
|
|
34
|
|
35
|
|
36 }else if(type.equals("node")){
|
|
37
|
|
38 System.out.println("node"+cliNum);
|
|
39 if (cliNum == 0){
|
|
40 for (int i=0;i<20 ;i++){
|
|
41 System.out.println("i = " +i);
|
|
42 ods.update("local", "fish", i);
|
|
43 try {
|
|
44 wait(500);
|
|
45 } catch (InterruptedException e) {
|
|
46 // TODO Auto-generated catch block
|
|
47 e.printStackTrace();
|
|
48 }
|
|
49 }
|
|
50 }else{
|
|
51 ods.update("local", "fish", 0);
|
|
52 new RelayPoint("fish");
|
|
53
|
|
54 }
|
|
55
|
|
56 }
|
|
57 }
|
|
58 }
|