Mercurial > hg > Database > Alice
view src/alice/topology/manager/keeparive/PingScheduler.java @ 309:797267843126
Refactor
author | sugi |
---|---|
date | Tue, 26 Nov 2013 15:33:29 +0900 |
parents | a8255a831ade |
children | f1cd920ea913 |
line wrap: on
line source
package alice.topology.manager.keeparive; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; public class PingScheduler extends CodeSegment{ static class SingletonHolder { private static PingScheduler Instance = new PingScheduler(); } public static PingScheduler getInstance(){ return SingletonHolder.Instance; } private Receiver info = ids.create(CommandType.TAKE); public void setKey(){ info.setKey("_WAITINGLIST"); } private TaskInfo nowTask; private boolean interruptFlag = false; private long time = 0; private long postponeTime = 0; @Override public synchronized void run() { WaitingList list = info.asClass(WaitingList.class); try { nowTask = list.getTaskList().pollFirst(); ods.update("_WAITINGLIST", list); time = System.currentTimeMillis(); if (nowTask.getSleepTime()!=0) this.wait(nowTask.getSleepTime()); if (interruptFlag){ interruptFlag = false; } else { ods.ping(nowTask.getManagerKey(), nowTask.getReturnKey()); } } catch (InterruptedException e) { } PingScheduler.getInstance().setKey(); } /* * private long INTERVAL = 60 * 1000; public synchronized void postpone(String name){ long elapsedTime = System.currentTimeMillis() - time; postponeTime = nowTask.getSleepTime() - elapsedTime; LinkedList<TaskInfo> list = plist.getTaskList(); if (name.equals(nowTask.getManagerKey())){ TaskInfo nextTask = list.get(0); nextTask.setSleepTime(postponeTime + nextTask.getSleepTime()); nowTask.setSleepTime(INTERVAL); plist.addTask(nowTask); } else { int cnt = 0; nowTask.setSleepTime(postponeTime); list.add(cnt, nowTask); for (TaskInfo info : list){ if (name.equals(info.getManagerKey())){ if (info != list.getLast()){ TaskInfo nextInfo = list.get(cnt+1); nextInfo.setSleepTime(nextInfo.getSleepTime() + info.getSleepTime()); } list.remove(info); info.setSleepTime(INTERVAL); plist.addTask(info); break; } cnt++; } } interruptFlag = true; notify(); } */ }