view src/alice/test/topology/share/CheckMyName.java @ 137:ed78890ed8e9 working

Share Test
author sugi
date Sun, 26 Aug 2012 18:33:13 +0900
parents bb023f060f2f
children ae6ed9c35288
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.CheckLocalIndex;
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";
	double a = Math.pow(2,1)-1; 
	double b = Math.pow(2,2)-1; 
	double c = Math.pow(2,3)-1; 
	double d = Math.pow(2,4)-1;
	double e = Math.pow(2,5)-1;
	double f = Math.pow(2,6)-1;
	double g = Math.pow(2,7)-1;
	double h = Math.pow(2,8)-1;
	
	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);
			
		}
		int depth = 0;
		if (num == 0){
			depth = 0;
		}else if (a <= num && num < b){
			depth = 1;
		}else if (b <= num && num < c){
			depth = 2;
		}else if (c <= num && num < d){
			depth = 3;
		}else if (d <= num && num < e){
			depth = 4;
		}else if (e <= num && num < f){
			depth = 5;
		}else if (f <= num && num < g){
			depth = 6;
		}else if (g <= num && num < h){
			depth = 7;
		}
		
		ods.update("local", key, new DataInfo());
		for (long time=0;time<10000000;time++){}
		new LookUpData(key,1,depth);
		new CheckLocalIndex(key,1);
		if (num == 0) new AutoIncrement(key,0);
				
	}
}