comparison src/alice/topology/manager/keeparive/TaskExecuter.java @ 326:c382d6fe1ec4

need reamainingTime add next task
author sugi
date Fri, 24 Jan 2014 02:18:09 +0900
parents 54d0b947079a
children 35b4e24e3e02
comparison
equal deleted inserted replaced
325:54d0b947079a 326:c382d6fe1ec4
8 public class TaskExecuter extends CodeSegment{ 8 public class TaskExecuter extends CodeSegment{
9 private Receiver info = ids.create(CommandType.TAKE); 9 private Receiver info = ids.create(CommandType.TAKE);
10 private TaskInfo nowTask; 10 private TaskInfo nowTask;
11 private boolean skipFlag = false; 11 private boolean skipFlag = false;
12 private long startTime = 0; 12 private long startTime = 0;
13 private long remainingTime = 0;
14 private static TaskExecuter instance = new TaskExecuter(); 13 private static TaskExecuter instance = new TaskExecuter();
15 14
16 private TaskExecuter(){} 15 private TaskExecuter(){}
17 public static TaskExecuter getInstance(){ 16 public static TaskExecuter getInstance(){
18 return instance; 17 return instance;
25 24
26 @Override 25 @Override
27 public synchronized void run(){ 26 public synchronized void run(){
28 ListManager list = info.asClass(ListManager.class); 27 ListManager list = info.asClass(ListManager.class);
29 if (list.getTaskList().size() == 0){ 28 if (list.getTaskList().size() == 0){
30 remainingTime = 0;
31 ods.update("_WAITINGLIST", list); 29 ods.update("_WAITINGLIST", list);
32 setKey(); 30 setKey();
33 return; 31 return;
34 } 32 }
35 nowTask = list.getTaskList().poll(); 33 nowTask = list.getTaskList().poll();
58 } 56 }
59 nowTask = null; 57 nowTask = null;
60 setKey(); 58 setKey();
61 } 59 }
62 60
63 public synchronized void skip(){ 61 public synchronized long skip(){
64 skipFlag = true; 62 skipFlag = true;
63 long remainingTime = nowTask.getSleepTime() - (System.currentTimeMillis() - startTime);
65 nowTask = null; 64 nowTask = null;
66 notify(); 65 notify();
66 return remainingTime;
67 } 67 }
68 68
69 public TaskInfo getNowTask(){ 69 public TaskInfo getNowTask(){
70 return nowTask; 70 return nowTask;
71 } 71 }