view src/main/java/alice/topology/manager/CheckComingHost.java @ 647:e321c5ec9b58

fix toplogy manager; ring worked
author suruga
date Sun, 31 Dec 2017 19:32:27 +0900
parents 145c425db88d
children
line wrap: on
line source

package alice.topology.manager;

import java.util.HashMap;
import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.Receiver;
import alice.topology.HostMessage;

public class CheckComingHost extends CodeSegment {
    // checkIncomingHost
    private Receiver host = ids.create(CommandType.TAKE);
    private Receiver absCookieTable = ids.create(CommandType.PEEK); // cookie, AbsName HashMap

    public CheckComingHost(){
        this.host.setKey("hostMessage");
        this.absCookieTable.setKey("absCookieTable");
    }

    @Override
    public void run() {
        HostMessage host = this.host.asClass(HostMessage.class);
        @SuppressWarnings("unchecked")
        HashMap<String, String> absCookieTable = this.absCookieTable.asClass(HashMap.class);
        boolean match = false;
        // check cookie
        if (host.cookie != null) {
            if (absCookieTable.containsKey(host.cookie)){
                match = true;
                host.absName = absCookieTable.get(host.cookie);
                System.out.println("match");
            }
        }

        if (match){
            // coming host has ever joined this App
            ods.put("reconnectHost", host);
            new SearchHostName();
        } else {
            ods.put("orderHash", "order");
            ods.put("newHost", host);
        }

        new CheckComingHost();
    }

}