view src/alice/test/topology/share/CheckMyName.java @ 135:2f401fd70311 working

create No Graphic aquarium
author sugi
date Thu, 16 Aug 2012 19:57:10 +0900
parents 53aff28cde6b
children bb023f060f2f
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;
import alice.test.topology.aquarium.AddRoutingTable;
import alice.test.topology.aquarium.AutoIncrement;
import alice.test.topology.aquarium.CheckLocalIndex;
import alice.test.topology.aquarium.FishPoint;
import alice.test.topology.aquarium.Routing;
import alice.test.topology.aquarium.RoutingTable;


public class CheckMyName extends CodeSegment {
	Receiver host = ids.create(CommandType.PEEK);
	Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$");
	String key = "fish";
	
	public CheckMyName(){
		this.host.setKey("local","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));
		
		RoutingTable routing = new RoutingTable();
		
		if (type.equals("cli")){
			System.out.println("cli"+num);
			routing.table.add(new Routing("parent"));
			ods.put("local", "list", routing);
			
			new AddRoutingTable(routing,0);
			ods.put("parent", "member", name);
				
		}else if (type.equals("node")){
			System.out.println("node"+num);
			if (num != 0){
				routing.table.add(new Routing("parent"));
				ods.put("parent", "member", name);
				
			}
			ods.put("local", "list", routing);
			new AddRoutingTable(routing,0);
			
		}
		
		ods.update("local", key, new FishPoint(-0.1f,-0.1f));
		new CheckLocalIndex(key,1);
		
		for (int i = 0;i < 3 ; i++){
			key = "fish"+i;
			if (num == 0) new AutoIncrement(key,0);
			ods.update("local", key, new FishPoint(0.2f*i,0.2f*i));
			new CheckLocalIndex(key,1);
			new LookUpData(key,1);
		}
		
		
		
	}
}