view src/main/java/alice/topology/manager/CheckComingHost.java @ 523:145c425db88d dispose

add CompressedLDSM
author Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
date Thu, 09 Apr 2015 18:36:26 +0900
parents 80e461aa10e9
children 15eeb439830c 767d93626b88 8f765e3eed24 e321c5ec9b58
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("host");
        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();
    }

}