view src/main/java/alice/topology/node/IncomingConnectionInfo.java @ 641:646f705e65b1

setkey on remote
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 31 Dec 2017 01:08:52 +0900
parents 8d9f35701fdb
children e321c5ec9b58
line wrap: on
line source

package alice.topology.node;

import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.DataSegment;
import alice.datasegment.Receiver;
import alice.topology.HostMessage;
import org.apache.log4j.Logger;

public class IncomingConnectionInfo extends CodeSegment {

    public Receiver hostInfo = ids.create(CommandType.TAKE);
    private String absName;
    private int count;
    private Logger log = Logger.getLogger(IncomingConnectionInfo.class);

    public IncomingConnectionInfo(String absName, int count) {
        this.absName = absName;
        this.count = count;
    }

    @Override
    public void run() {
        if (this.hostInfo.getVal() == null) {
            ods.put("local", "configNodeNum", count);
        } else {
            HostMessage hostInfo = this.hostInfo.asClass(HostMessage.class);
            log.info("topology node " + absName + " will connect to " + hostInfo.name );
            if (DataSegment.contains(hostInfo.connectionName)) {
                // need to wait remove by DeleteConnection
                ods.put("manager", absName, hostInfo);
            } else {
                DataSegment.connect(hostInfo.connectionName, hostInfo.reverseName, hostInfo.name, hostInfo.port);
                ods.put(hostInfo.connectionName, "reverseKey", hostInfo.reverseName);
                count++;

                ods.put("cMember", hostInfo.connectionName);
                new CreateConnectionList();
            }

        }

        IncomingConnectionInfo cs = new IncomingConnectionInfo(absName, count);
        cs.hostInfo.setKey(absName);
    }

}