Mercurial > hg > Members > tatsuki > Alice
view src/main/java/alice/test/topology/aquarium/fx/CheckMyName.java @ 390:e29cf08ad1f3 multicast
add CalculatePosition CodeSegment
author | sugi |
---|---|
date | Mon, 16 Jun 2014 21:45:43 +0900 |
parents | 1cbac5818dca |
children |
line wrap: on
line source
package alice.test.topology.aquarium.fx; import java.util.ArrayList; 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 { private Receiver host = ids.create(CommandType.PEEK); private Pattern pattern = Pattern.compile("^(node|cli|local)([0-9]+)$"); private int INNER_WIDTH = 10; public CheckMyName(){ host.setKey("host"); } @Override public void run() { String name = host.asString(); Matcher matcher = pattern.matcher(name); matcher.find(); // use view scope int num = new Integer(matcher.group(2)); // scope: A_n = 5 + 10(n - 1); int median = INNER_WIDTH * num; ods.put("median", median); // node0 median : 0 // node1 median : 10 // node2 median : 20 if (num == 0){ // root node new RegisterList(); ods.put("registeredList", new ArrayList<FishInfo>()); } else { new ReceiveRegisterList(); } FishInfo fishInfo = new FishInfo(median,0,0); fishInfo.setName(name); ods.put("OwnFishP", fishInfo.clone()); ods.put("fishData", fishInfo); new CreateObject(); new AddObject(); String[] args = {name}; Aquarium.main(args); } }