view src/main/java/alice/topology/manager/keeparive/RespondPing.java @ 467:6e304a7a60e7 dispose

remove white space
author sugi
date Sat, 22 Nov 2014 12:08:24 +0900
parents aefbe41fcf12
children 27079619f5fd
line wrap: on
line source

package alice.topology.manager.keeparive;

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

public class RespondPing extends CodeSegment{
    private Receiver respond = ids.create(CommandType.TAKE);
    private long pingedTime = System.currentTimeMillis();

    public RespondPing(String key) {
        respond.setKey(key);
    }

    @Override
    public void run() {
        RespondData d = respond.asClass(RespondData.class);
        System.out.print("ping from "+d.from);
        System.out.println(" Recieved time "+(d.time - pingedTime));
        if (d.time - pingedTime > 60 * 1000){
            // need check, this connection is alive. may be close
            DataSegment.get(d.from).shutdown();
        } else {
            // if nowTask close d.from's socket cancel.
            // if not remove close task in the Queue.
            TaskExecuter exec = TaskExecuter.getInstance();
            TaskInfo task = new TaskInfo(TaskType.CLOSE);
            task.setInfo(d.from, null, 0);
            if (exec.compareNowTask(task)){
                // case: remove task is state countdown.
                exec.skip(); // countdown
            } else {
                // case: remove task is still in the waiting queue.
                ods.put("_REMOVETASK",task);
                new RemoveTask();
            }
            TaskInfo task2 = new TaskInfo(TaskType.PING);
            task2.setInfo(d.from, "_FORM_"+d.from, 5 * 1000);
            ods.put("_TASKINFO", task2);
        }
    }
}