Mercurial > hg > Database > Alice
view src/alice/test/topology/share/CheckMyName.java @ 96:a5fce70380e8 working
add share test
author | sugi |
---|---|
date | Tue, 19 Jun 2012 17:52:01 +0900 |
parents | |
children | df786bf8f036 |
line wrap: on
line source
package alice.test.topology.share; import java.util.regex.Matcher; import java.util.regex.Pattern; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; public class CheckMyName extends CodeSegment { Receiver host = ids.create(CommandType.PEEK); Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$"); public CheckMyName(){ host.setKey("local","host"); } @Override public synchronized void run(){ String name = host.asString(); Matcher matcher = pattern.matcher(name); matcher.find(); String type = matcher.group(1); int cliNum = new Integer(matcher.group(2)); if (type.equals("cli")){ System.out.println("cli"+cliNum); ods.update("local", "fish", 0); new RelayPoint("fish"); }else if(type.equals("node")){ System.out.println("node"+cliNum); if (cliNum == 0){ for (int i=0;i<20 ;i++){ System.out.println("i = " +i); ods.update("local", "fish", i); try { wait(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }else{ ods.update("local", "fish", 0); new RelayPoint("fish"); } } } }