Mercurial > hg > Database > Alice
view src/alice/topology/manager/keeparive/TaskExecuter.java @ 323:d746c4486287
work
author | one |
---|---|
date | Mon, 23 Dec 2013 17:13:16 +0900 |
parents | 4b5bf9cf1505 |
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 TaskExecuter extends CodeSegment{ private Receiver info = ids.create(CommandType.TAKE); private TaskInfo nowTask; private boolean skipFlag = false; private long startTime = 0; private long remainingTime = 0; private static TaskExecuter instance = new TaskExecuter(); private TaskExecuter(){} public static TaskExecuter getInstance(){ return instance; } public void setKey(){ ids.init(); info.setKey("_WAITINGLIST"); } @Override public synchronized void run(){ ListManager list = info.asClass(ListManager.class); if (list.getTaskList().size() == 0){ remainingTime = 0; ods.update("_WAITINGLIST", list); setKey(); return; } nowTask = list.getTaskList().poll(); ods.update("_WAITINGLIST", list); if (skipFlag){ nowTask.setSleepTime(nowTask.getSleepTime() + remainingTime); } startTime = System.currentTimeMillis(); if (nowTask.getSleepTime()!=0){ try { this.wait(nowTask.getSleepTime()); } catch (InterruptedException e){} } if (!skipFlag){ if (nowTask.getType() == TaskType.PING){ ods.ping(nowTask.getManagerKey(), nowTask.getReturnKey()); TaskInfo task = new TaskInfo(TaskType.CLOSE); task.setInfo(nowTask.getManagerKey(), 60 * 1000); ods.put("_TASKINFO", task); new RespondPing(nowTask.getReturnKey()); } else { // no response from the Remote DataSegment. So close this connection. DataSegment.get(nowTask.getManagerKey()).close(); } } nowTask = null; setKey(); } public synchronized void skip(){ skipFlag = true; remainingTime = nowTask.getSleepTime() - (System.currentTimeMillis() - startTime); nowTask = null; notify(); } public TaskInfo getNowTask(){ return nowTask; } public long getTime(){ return startTime; } public boolean compareNowTask(TaskInfo task){ if (nowTask != null){ if (nowTask.getType().equals(task.getType()) && nowTask.getManagerKey().equals(task.getManagerKey())){ return true; } } return false; } }