view src/main/java/alice/topology/node/PrepareToClose.java @ 492:24e535123df7 dispose

add PrepareToClose CodeSegment
author sugi
date Thu, 11 Dec 2014 06:29:31 +0900
parents
children dca4b392f788
line wrap: on
line source

package alice.topology.node;

import java.util.List;

import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.DataSegment;
import alice.datasegment.DataSegmentManager;
import alice.datasegment.Receiver;

public class PrepareToClose extends CodeSegment {

    private Receiver info = ids.create(CommandType.PEEK);
    private Receiver info1 = ids.create(CommandType.TAKE);

    public PrepareToClose() {
        info.setKey("_CLOSEMESSEAGE");
        info1.setKey("_CLIST");
    }

    @SuppressWarnings("unchecked")
    @Override
    public void run() {
        String managerKey = info.asString();
        List<String> list = info1.asClass(List.class);
        if (list.contains(managerKey)) {
            list.remove(managerKey);
            DataSegmentManager manager = DataSegment.get(managerKey);
            manager.setSendError(false);

            ods.put(managerKey, "_CLOSEREADY", managerKey);
            ods.put("_CLOSEREADY", managerKey);
            ods.put(info1.key, list);

            new CloseRemoteDataSegment();
        } else {
            // lost node is this node's parent
        }

    }

}