view src/main/java/christie/topology/node/IncomingConnectionInfo.java @ 61:20d4c0cce914

refactor Topology Node
author akahori
date Tue, 28 Aug 2018 18:56:45 +0900
parents 76b6da075ce0
children 5deea416f980
line wrap: on
line source

package christie.topology.node;


import christie.annotation.TakeFrom;
import christie.codegear.CodeGear;
import christie.codegear.CodeGearManager;
import christie.topology.HostMessage;
import org.apache.log4j.Logger;

public class IncomingConnectionInfo extends CodeGear {

    @TakeFrom("manager")
    HostMessage hostInfo;

    private String absName;
    private int count;
    private Logger log = Logger.getLogger(IncomingConnectionInfo.class);
    private String managerKey;

    public IncomingConnectionInfo(String absName, int count, String managerKey) {
        this.absName = absName;
        this.count = count;
        this.managerKey = managerKey;
        //hostInfo.setKey(managerKey,absName);
    }



    @Override
    protected void run(CodeGearManager cgm) {

        log.info(hostInfo.toString());
        if ( hostInfo.hostName.equals("")) { // end case
            log.info(" topology node finished " + absName);
            getLocalDGM().put("configNodeNum", 0);
            return ;
        }
        log.info("topology node " + absName + " will connect to " + hostInfo.hostName );
        if (cgm.getDgmList().contains(hostInfo.connectionName)) {
            // need to wait remove by DeleteConnection
            getDGM("manager").put(absName, hostInfo);
        } else {
            cgm.createRemoteDGM(hostInfo.connectionName, hostInfo.hostName, hostInfo.port);

            getDGM(hostInfo.connectionName).put("reverseKey", hostInfo.reverseName);
            getDGM(hostInfo.connectionName).put("reverseHostName", hostInfo.hostName);
            getDGM(hostInfo.connectionName).put("reverseKeyPort", hostInfo.port);

            count++;

            getLocalDGM().put("cMember", hostInfo.connectionName);
            cgm.setup(new CreateConnectionList());

        }
        cgm.setup(new IncomingConnectionInfo(absName, count, managerKey));
    }

}