view src/alice/test/topology/fishmodel/beta/CheckMyName.java @ 117:e78402bb54cb working

minor change
author sugi
date Sat, 21 Jul 2012 11:22:20 +0900
parents 248064474909
children 1044a79ce4ef
line wrap: on
line source

package alice.test.topology.fishmodel.beta;

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.fishmodel.alpha.AutoIncrement;
import alice.test.topology.fishmodel.alpha.SetLocation;
import alice.test.topology.fishmodel.alpha.FishPoint;
import alice.test.topology.fishmodel.alpha.MakeFrame;
import alice.test.topology.fishmodel.alpha.MakeObject;


public class CheckMyName extends CodeSegment {
	Receiver host = ids.create(CommandType.PEEK);
	Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$");
	String key = "fish";
	
	@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("local", "myMax", num);
		if (type.equals("cli")){
			ods.put("parent", "check", num);
		}else if (type.equals("node")){
			if (num !=0){
				ods.put("parent", "check", num);
			} else {
				
			}
		}
		*/
		
		MakeFrame frame =  new MakeFrame(name);
		RoutingTable routing = new RoutingTable();
		/*
		ods.put("local", "max", num);
		new CheckLocalIndex(key,1);
		*/
		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 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("local", key, new FishPoint(0.2f*i,0.2f*i));
			new SetLocation(new MakeObject(frame),key,0,num);
			new CheckLocalIndex(key,1);
		}
		
		
	}
}