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

add Receiver state pattern
author one
date Wed, 27 Mar 2013 17:30:52 +0900
parents 206c7dd9cb48
children fec0726bb126
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.data.asClass(this.list, 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.data.from)){
				ods.update(r.name, this.key, this.data.data.val);
				count++;
			}
			
		}
		if (count==0&&flag){
			ods.put("parent", "data", this.data.data.val);
		}
		new CheckLocalIndex(this.key, this.data.data.index);
		
	}

}