view src/alice/test/topology/share/CheckMyName.java @ 134:53aff28cde6b working

change package
author sugi
date Wed, 15 Aug 2012 17:11:57 +0900
parents a8f77957a477
children 2f401fd70311
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.FishPoint;

public class CheckMyName extends CodeSegment {
	Receiver host = ids.create(CommandType.PEEK);
	Pattern pattern = Pattern.compile("^(node|cli)([0-9]+)$");
	
	String key = "fish";
	
	public CheckMyName(){
		host.setKey("local","host");
	}
	
	
	@Override
	public synchronized void run(){
		
		String name = host.asString();
		Matcher matcher = pattern.matcher(name);
		
		matcher.find();
		String type = matcher.group(1);
		int cliNum = new Integer(matcher.group(2));
		
		if (type.equals("cli")){
			System.out.println("cli"+cliNum);
			ods.update("local", this.key, new FishPoint(0.0f,0.0f));
			new CheckLocalIndex(this.key,0);
			new CheckParentIndex(this.key,0);
			
			
									
		}else if(type.equals("node")){
			
			System.out.println("node"+cliNum);
			if (cliNum == 0){
				try {
					for (float i = 0.0f; i < 2.0f; i +=0.1f) {
						System.out.println("i = " + i);
						ods.update("local", "fish", new FishPoint(i,i));
						wait(500);
					} 
				}catch (InterruptedException e) {
					
					e.printStackTrace();
				}
			}else{
				ods.update("local", this.key, new FishPoint(0.0f,0.0f));
				new CheckLocalIndex(this.key,0);
				new CheckParentIndex(this.key,0);
				
			}
						
		}
	}
}