view src/alice/test/topology/aquarium/fx/CheckMyName.java @ 1:b997f2ce1a04

add Controller Class
author one
date Sat, 26 Jan 2013 18:29:45 +0900
parents 6f44308ee519
children b973de8b6785
line wrap: on
line source

package alice.test.topology.aquarium.fx;

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]+)$");
	
	public CheckMyName(){
		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));
		if (type.equals("cli")){
			new OtherNode().execute();
		} else if (type.equals("node")){
			if (num==0) {
				new TopNode().execute();
			} else {
				new OtherNode().execute();
			}
		}
		
		
	}
}