| 1 10 package org.mmbase.module.builders.vwms; 11 12 import java.util.*; 13 import java.util.Properties ; 14 import java.io.*; 15 16 import org.mmbase.util.logging.*; 17 import org.mmbase.module.core.*; 18 import org.mmbase.module.builders.*; 19 20 34 35 public class Vwm implements VwmInterface, VwmProbeInterface, Runnable { 36 37 private static Logger log = Logging.getLoggerInstance(Vwm.class); 39 40 protected void debug(String msg) { 42 log.debug(msg); 43 } 44 45 48 protected VwmProbe probe; 49 50 54 protected int sleeptime; 55 56 60 protected MMObjectNode wvmnode; 61 62 66 protected String name = "Unknown"; 67 68 73 protected Vwms Vwms; 74 75 81 Thread kicker = null; 82 83 87 Vector clients = new Vector(); 88 89 96 public void init(MMObjectNode vwmnode, Vwms Vwms) { 97 this.wvmnode = vwmnode; 98 this.name = vwmnode.getStringValue("name"); 99 this.sleeptime = wvmnode.getIntValue("maintime"); 100 this.Vwms = Vwms; 101 104 probe = new VwmProbe(this); 105 this.start(); 106 } 107 108 111 public void start() { 112 113 if (kicker == null) { 114 kicker = new Thread (this, "Vwm : " + name); 115 kicker.setDaemon(true); 116 kicker.start(); 117 } 118 } 119 120 124 public void stop() { 125 126 kicker.interrupt(); 127 kicker = null; 128 } 129 130 134 public void run() { 135 while (kicker != null) { 136 try { 137 probeCall(); 138 } catch (Exception e) { 139 log.error("Vwm : Got a Exception in my probeCall : " + e.getMessage()); 140 log.error(Logging.stackTrace(e)); 141 } 142 try { 143 Thread.sleep(sleeptime * 1000); 144 } catch (InterruptedException e) { 145 return; 147 } 148 } 149 } 150 151 156 public boolean addClient(VwmCallBackInterface client) { 157 if (clients.contains(client)) { 158 log.warn("Vwm : " + name + " allready has the client : " + client + "."); 159 return false; 160 } else { 161 clients.addElement(client); 162 return true; 163 } 164 } 165 166 171 public boolean releaseClient(VwmCallBackInterface client) { 172 if (clients.contains(client)) { 173 clients.removeElement(client); 174 return true; 175 } else { 176 log.warn("Vwm : " + name + " got a release call from : " + client + " but have no idea who he is."); 177 return false; 178 } 179 } 180 181 187 public boolean probeCall() { 188 log.info("Vwm probe call : " + name); 189 return false; 190 } 191 192 198 public boolean putTask(MMObjectNode node) { 199 return probe.putTask(node); 200 } 201 202 205 public String getName() { 206 return name; 207 } 208 209 217 public boolean performTask(MMObjectNode node) { 218 log.error("Vwm : performTask not implemented in : " + name); 219 node.setValue("status", Vwmtasks.STATUS_ERROR); 220 node.commit(); 221 222 Vwms.sendMail(name, "performTask not implemented", ""); 223 return false; 224 } 225 226 233 protected boolean claim(MMObjectNode node) { 234 node.setValue("status", Vwmtasks.STATUS_CLAIMED); 235 node.setValue("claimedcpu", Vwms.getMachineName()); 236 return node.commit(); 237 } 238 239 246 protected boolean rollback(MMObjectNode node) { 247 node.setValue("status", Vwmtasks.STATUS_REQUEST); 248 return node.commit(); 249 } 250 251 258 protected boolean failed(MMObjectNode node) { 259 node.setValue("status", Vwmtasks.STATUS_ERROR); 260 return node.commit(); 261 } 262 263 270 protected boolean performed(MMObjectNode node) { 271 node.setValue("status", Vwmtasks.STATUS_DONE); 272 return node.commit(); 273 } 274 275 283 protected Hashtable parseProperties(String props) { 284 byte[] bytes = props.getBytes(); 287 Properties p = new Properties (); 288 try { 289 p.load(new ByteArrayInputStream(bytes)); 290 } catch (IOException e) { 291 log.error("failed to load the String ["+props +"] into the properties object due to IOException (this might be an encoding problem) stacktrace" + Logging.stackTrace(e)); 292 } 293 return p; 294 } 295 296 299 public MMObjectNode getVwmNode() { 300 return wvmnode; 301 } 302 303 311 public boolean nodeRemoteChanged(String machine, String number, String builder, String ctype) { 312 return false; 313 } 314 315 323 public boolean nodeLocalChanged(String machine, String number, String builder, String ctype) { 324 return false; 325 } 326 } 327 | Popular Tags |