1 23 24 31 package com.sun.enterprise.util.scheduler; 32 33 import com.sun.enterprise.util.collection.DListNode; 34 35 44 public class TimedTaskList 45 { 46 47 private DListNode first; 48 49 private DListNode last; 50 51 private int size = 0; 52 53 56 protected TimedTaskList() 57 { 58 first = new DListNode(null); 59 last = new DListNode(null); 60 first.next = last; 61 last.prev = first; 62 first.prev = last.next = null; 63 } 64 65 69 protected int size() 70 { 71 return size; 72 } 73 74 78 protected TaskData getFirstTask() 79 { 80 DListNode node = first; 81 node = node.next; 82 if(null!=node.next) { 84 node.delink(); 85 --size; 86 return (TaskData) node.object; 87 } 88 return null; 89 } 90 91 98 protected boolean addTask(PeriodicallyServicable taskObj, int startingTime, long currentTime) 99 { 100 TaskData task = new TaskData(); 101 task.obj = taskObj; 102 task.abs_execute_time = currentTime + startingTime - taskObj.getFrequency(); 104 return insertTask(task); 105 } 106 107 112 protected boolean insertTask(TaskData task) 113 { 114 task.abs_execute_time += ((PeriodicallyServicable)task.obj).getFrequency(); 115 DListNode addingNode = new DListNode(task); 116 DListNode node = first; 117 ++size; 118 for(int i=0; i<size-1; i++) 119 { 120 node = node.next; 121 long nodeTime = ((TaskData)node.object).abs_execute_time; 122 if(nodeTime > task.abs_execute_time) 123 { 124 node.insertBefore(addingNode); 125 return true; 126 } 127 } 128 node.insertAfter(addingNode); 129 return true; 130 } 131 132 137 protected boolean removeTask(PeriodicallyServicable obj) 138 { 139 DListNode node = first; 140 141 for(int i=0; i<size; i++) 142 { 143 node = node.next; 144 PeriodicallyServicable nodeObj = ((TaskData)node.object).obj; 145 146 if(nodeObj.equals(obj)) 147 { 148 node.delink(); 149 --size; 150 return true; 151 } 152 } 153 return false; 154 } 155 156 160 public String toString() 161 { 162 StringBuffer sb = new StringBuffer (100); 163 sb.append(" [TimedTaskList: "); 164 sb.append( size + " elements: "); 165 DListNode node = first; 166 while(null!=node.next && null!=node.next.object) 167 { 168 node = node.next; 169 sb.append((int) ( ((TaskData)node.object).abs_execute_time / 1000) ); 170 sb.append(","); 171 } 172 sb.append("] "); 173 return sb.toString(); 174 } 175 } 176 | Popular Tags |