Mercurial > hg > Database > Alice
view src/alice/test/topology/aquarium/CheckMyName.java @ 217:b5c642ba998e working
change as** method and remove "local" key in TEST
author | sugi |
---|---|
date | Wed, 27 Mar 2013 20:02:38 +0900 |
parents | b5daccf36104 |
children | 7f7b3506bff9 |
line wrap: on
line source
package alice.test.topology.aquarium; import java.util.Random; 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)([0-9]+)$"); private String key = "fish"; public CheckMyName(){ host.setKey("host"); } @Override public void run(){ String name = host.asString(); Matcher matcher = pattern.matcher(name); matcher.find(); String type = matcher.group(1); int num = new Integer(matcher.group(2)); ods.put("host_num", num*2); MakeFrame frame = new MakeFrame(name,num*2); RoutingTable routing = new RoutingTable(); ods.put("num", 1); if (type.equals("cli")){ System.out.println("cli"+num); routing.table.add(new Routing("parent")); ods.put("list", routing); new AddRoutingTable(routing,0); ods.put("parent", "member", name); new TakeMynum(); }else if (type.equals("node")){ System.out.println("node"+num); if (num != 0){ routing.table.add(new Routing("parent")); ods.put("parent", "member", name); new TakeMynum(); } else { new SendMaxsize(0); } ods.put("list", routing); new AddRoutingTable(routing,0); } new CheckLocalIndex("maxsize",0); ods.update(key, new FishPoint(-0.1f,-0.1f)); new SetLocation(new MakeObject(frame), key, 0, num); new CheckLocalIndex(key,1); for (int i = 0; i < 3 ; i++){ key = "fish"+i; if (num == 0) new AutoIncrement(key,0); ods.update(key, new FishPoint((float)Math.random(), (float)Math.random(), (float)Math.random())); new SetLocation(new MakeObject(frame), key, 0, num); new CheckLocalIndex(key,1); } for (int i = 3; i < 6 ; i++){ key = "fish"+i; if (num == 1) new AutoIncrement(key,0); Random rnd = new Random(); int tmp = rnd.nextInt(3); int rand = tmp + 1; ods.update(key, new FishPoint( (float)rand, -(float)Math.random(), -(float)Math.random())); new SetLocation(new MakeObject(frame), key, 0, num); new CheckLocalIndex(key,1); } for (int i = 6; i < 9 ; i++){ key = "fish"+i; if (num == 2) new AutoIncrement(key,0); Random rnd = new Random(); int tmp = rnd.nextInt(3); int rand = tmp + 3; ods.update(key, new FishPoint( (float)rand, (float)Math.random(), -(float)Math.random())); new SetLocation(new MakeObject(frame), key, 0, num); new CheckLocalIndex(key,1); } for (int i = 9; i < 12 ; i++){ key = "fish"+i; if (num == 3) new AutoIncrement(key,0); Random rnd = new Random(); int tmp = rnd.nextInt(3); int rand = tmp + 5; ods.update(key, new FishPoint( (float)rand, -(float)Math.random(), (float)Math.random())); new SetLocation(new MakeObject(frame), key, 0, num); new CheckLocalIndex(key,1); } } }