view src/alice/test/topology/share/CheckLocalIndex.java @ 216:21bd8af1cf26 working

change asClass method
author one
date Wed, 27 Mar 2013 19:38:33 +0900
parents fec0726bb126
children b5c642ba998e
line wrap: on
line source

package alice.test.topology.share;

import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.Receiver;
import alice.test.topology.aquarium.Routing;
import alice.test.topology.aquarium.RoutingTable;

public class CheckLocalIndex extends CodeSegment {

	private Receiver data = ids.create(CommandType.PEEK);
	private Receiver list = ids.create(CommandType.PEEK);
	private Receiver host = ids.create(CommandType.PEEK);
	private String key;
	
	public CheckLocalIndex(String key, int index){
		this.key = key;
		this.host.setKey("local","host");
		this.list.setKey("local", "list");
		this.data.setKey("local", this.key, index);
	}
	
	@Override
	public void run() {
		RoutingTable rt = this.list.asClass(RoutingTable.class);
		int count = 0;
		boolean flag = false;
		for (Routing r : rt.table) {
			if (r.name.equals("parent"))flag=true;
			if (!r.name.equals(this.data.from)){
				ods.update(r.name, this.key, this.data.getVal());
				count++;
			}
			
		}
		if (count==0&&flag){
			ods.put("parent", "data", this.data.getVal());
		}
		new CheckLocalIndex(this.key, this.data.index);
		
	}

}