view src/alice/test/topology/share/CheckMyName.java @ 212:b5daccf36104 working

add Receiver state pattern
author one
date Wed, 27 Mar 2013 17:30:52 +0900
parents d7816b9b72e9
children b5c642ba998e
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.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.data.asString(host);
		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);
			new SendData(0);
		}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 SendData(0);
			}else{
				new LookUpData("data",0);
			}
			ods.put("local", "list", routing);
			new AddRoutingTable(routing,0);
			
		}
		for (int i =0 ;i<1000000;i++){}
		ods.update("local", key, new DataInfo());
		
		if (num == 0) new AutoIncrement(key,0);
		new CheckLocalIndex(key,1);
	}
}