Mercurial > hg > Members > tatsuki > Alice
view src/alice/topology/manager/keeparive/RespondPing.java @ 329:35b4e24e3e02
setNowTask method need synchronized. may be...
author | sugi |
---|---|
date | Mon, 24 Mar 2014 23:52:20 +0900 |
parents | c382d6fe1ec4 |
children | d35ff0f588e8 |
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); if (pingedTime - d.time > 60 * 1000){ // need check, this connection is alive. may be close DataSegment.get(d.from).close(); } 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); } } }