view src/alice/test/topology/fish/CheckMyName.java @ 95:7982324d4329 working

"setKey" move in the instance
author sugi
date Mon, 18 Jun 2012 17:54:26 +0900
parents 0b25b48116b6
children b5daccf36104
line wrap: on
line source

package alice.test.topology.fish;

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);
	
	public CheckMyName(){
		host.setKey("local", "host");
	}
	
	@Override
	public void run() {
		String name = host.asString();
		Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$");
		Matcher matcher = pattern.matcher(name);
		
		matcher.find();
		String type = matcher.group(1);
		int num = new Integer(matcher.group(2));
		
		if (type.equals("cli")) {
			System.out.println("********************I am cli" + num);
			ods.update("local", "width", 400);
			
			GetStartX cs = new GetStartX();
			cs.startX.setKey("local", "startX");
			
		} else if (type.equals("node")) {
			System.out.println("********************I am node" + num);
			WidthReceiver cs = new WidthReceiver();
			cs.widths.setKey("local", "widths");
			cs.routing.setKey("local", "routing");
			
			PeekStartX cs2 = new PeekStartX(0);
			cs2.startX.setKey("local", "startX");
			
			ods.put("local", "routing", new RoutingTable());
			if (num == 0) { // First node ("node0") check
				StartStartX cs3 = new StartStartX();
				cs3.width.setKey("local", "width");
				//ods.update("local", "startX", 0);
				return;
			}
		}
		
		SendWidth cs = new SendWidth();
		cs.width.setKey("local", "width");

	}

}