Mercurial > hg > Database > Alice
view src/alice/topology/manager/keeparive/RespondPing.java @ 323:d746c4486287
work
author | one |
---|---|
date | Mon, 23 Dec 2013 17:13:16 +0900 |
parents | aafc88985822 |
children | 806cc010a5bd |
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 { System.out.println("alive"); // if nowTask is 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(); } 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); } } }