view src/alice/topology/manager/reconnection/CheckConnectionList.java @ 270:23e53aaa8720

reconnect manager worked.
author sugi
date Wed, 21 Aug 2013 15:33:49 +0900
parents 9982e1c4f099
children 3667ab045530
line wrap: on
line source

package alice.topology.manager.reconnection;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.msgpack.type.ValueFactory;

import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.Receiver;
import alice.topology.HostMessage;

public class CheckConnectionList extends CodeSegment {

	private Receiver name = ids.create(CommandType.TAKE);
	private Receiver connection = ids.create(CommandType.TAKE);
	private Receiver abs = ids.create(CommandType.PEEK);
	private Receiver clone = ids.create(CommandType.TAKE);
	
	public CheckConnectionList(){
		name.setKey("_RECABSNAME");
		connection.setKey("connection");
		abs.setKey("_ABSIPTABLE");
		clone.setKey("_HMCLONE");
	}
	
	@Override
	public void run() {
		System.out.println("CheckConnectionList");
		@SuppressWarnings("unchecked")
		HashMap<String, ArrayList<HostMessage>> connectionList = connection.asClass(HashMap.class);
		@SuppressWarnings("unchecked")
		List<HostMessage> ABSIPList = abs.asClass(List.class);
		String absName = name.asClass(String.class);
		HostMessage oldInfo =  clone.asClass(HostMessage.class);
		HostMessage newInfo = null; 
		for (HostMessage mes : ABSIPList){
			if (mes.absName.equals(absName)){
				newInfo = mes;
				break;
			}
		}
		
		List<HostMessage> clist = connectionList.get(absName);
		for (HostMessage mes : clist){
			ods.put(absName, mes);
			for (HostMessage mes2 : ABSIPList){
				if (mes.name.equals(mes2.name)&&mes.port == mes2.port){
					String absName2 = mes2.getABSName();
					List<HostMessage> clist2 = connectionList.get(absName2);
					for (HostMessage mes3 : clist2){
						if (mes3.name.equals(oldInfo.name)&&mes3.port == oldInfo.port){
							mes3.name = newInfo.name;
							mes3.port = newInfo.port;
							System.out.println(mes3.port);
							System.out.println(mes3.name);
							System.out.println(absName2+" "+newInfo.port);
							ods.put(absName2, "_RECODATA", mes3);
							break;
						}
						
						
					}
					break;
				}			
			}
		}
		ods.put(absName, ValueFactory.createNilValue());
		
		
		ods.update("connection", connectionList);
		new ReceiveError();
	}
}