1 10 package org.mmbase.module.builders; 11 12 import java.util.*; 13 14 import org.mmbase.module.core.*; 15 import org.mmbase.util.*; 16 import org.mmbase.util.logging.*; 17 18 41 public class Vwmtasks extends MMObjectBuilder implements Runnable { 42 45 public static final int STATUS_REQUEST = 1; 46 49 public static final int STATUS_CLAIMED = 2; 50 53 public static final int STATUS_DONE = 3; 54 57 public static final int STATUS_TIMEOUT = 4; 58 61 public static final int STATUS_ERROR = 5; 62 63 private static Logger log = Logging.getLoggerInstance(Vwmtasks.class.getName()); 65 66 69 public static final int SLEEP_TIME= 37; 70 71 public boolean replaceCache=true; 73 74 77 Thread kicker; 78 79 82 Vwms vwms; 83 84 Hashtable vwm_cache = new Hashtable (); 86 87 90 int lastchecked=0; 91 92 public boolean init () { 93 if (oType != -1) { 94 return true; 95 } else { 96 boolean success = super.init (); 97 if (success) { 98 start(); 99 } 100 return success; 101 } 102 } 103 104 107 public void start() { 108 109 if (kicker == null) { 110 kicker = new Thread (this,"VwmTasks"); 111 kicker.setDaemon(true); 112 kicker.start(); 113 } 114 } 115 116 120 public void stop() { 121 122 kicker.interrupt(); 123 kicker = null; 124 } 125 126 131 public void run() { 132 log.info("Thread started, entering while loop"); 133 134 while (kicker!=null) { 135 log.service("Periodically sleep "+SLEEP_TIME 136 +" seconds and add all new vwmtasks that were created since last check (" 137 +DateSupport.date2string(lastchecked)+")."); 138 try {Thread.sleep(SLEEP_TIME*1000);} catch (InterruptedException e){return;} 139 getVwmTasks(); 140 } 141 } 142 143 149 public MMObjectNode preCommit(MMObjectNode node) { 150 node.setValue("changedtime",(int)(System.currentTimeMillis()/1000)); 151 return node; 152 } 153 154 160 public String getGUIIndicator (MMObjectNode node) { 161 String str = node.getStringValue ("task"); 162 if (str.length () > 15) { 163 return str.substring (0,12) + "..."; 164 } else { 165 return str; 166 } 167 } 168 169 176 public String getGUIIndicator (String field, MMObjectNode node) { 177 if (field.equals ("status")) { 178 int val = node.getIntValue ("status"); 179 180 if (val==STATUS_REQUEST) { 181 return "verzoek"; } else if (val==STATUS_CLAIMED) { 183 return "onderweg"; } else if (val==STATUS_DONE) { 185 return "gedaan"; } else if (val==STATUS_TIMEOUT) { 187 return "timeout"; 188 } else if (val==STATUS_ERROR) { 189 return "error emailed"; 190 } else { 191 return "unknown"; 192 } 193 } else if (field.equals("changedtime")) { 194 int str=node.getIntValue("changedtime"); 195 return DateSupport.getTimeSec(str)+" op "+DateSupport.getMonthDay(str)+"/"+DateSupport.getMonth(str)+"/"+DateSupport.getYear(str); 196 } else if (field.equals("wantedtime")) { 197 int str=node.getIntValue("wantedtime"); 198 return DateSupport.getTimeSec(str)+" op "+DateSupport.getMonthDay(str)+"/"+DateSupport.getMonth(str)+"/"+DateSupport.getYear(str); 199 } else if (field.equals("expiretime")) { 200 int str=node.getIntValue("expiretime"); 201 return DateSupport.getTimeSec(str)+" op "+DateSupport.getMonthDay(str)+"/"+DateSupport.getMonth(str)+"/"+DateSupport.getYear(str); 202 } 203 return null; 204 } 205 206 213 protected void getVwmTasks() { 214 String vwm,task; 215 if (vwms==null) { 217 vwms = (Vwms)mmb.getMMObject("vwms"); 218 vwms.init(); } 220 int checktime = lastchecked; 221 lastchecked= (int)(System.currentTimeMillis()/1000); 222 log.service("Search vwmtasks "+"WHERE changedtime>"+checktime 224 +" AND wantedcpu='"+getMachineName()+"'" 225 +" AND "+mmb.getStorageManagerFactory().getStorageIdentifier("status")+"="+STATUS_REQUEST); 226 Enumeration e = search("WHERE changedtime>"+checktime 227 +" AND wantedcpu='"+getMachineName()+"'" 228 +" AND "+mmb.getStorageManagerFactory().getStorageIdentifier("status")+"="+STATUS_REQUEST); 229 230 for (MMObjectNode node=null; e.hasMoreElements();) { 231 node = (MMObjectNode)e.nextElement(); 232 vwm = node.getStringValue("vwm"); 233 task = node.getStringValue("task"); 234 log.debug("Adding "+vwm+" tasknode "+node); 235 vwms.putTask(vwm,node); 236 } 237 } 238 } 239 | Popular Tags |