1 23 package org.objectweb.clif.scenario.util.isac.engine.loadprofile; 24 25 import java.util.Enumeration ; 26 import java.util.Hashtable ; 27 import java.util.Vector ; 28 29 import org.objectweb.clif.scenario.util.isac.loadprofile.GroupDescription; 30 import org.objectweb.clif.scenario.util.isac.loadprofile.Point; 31 import org.objectweb.clif.scenario.util.isac.loadprofile.RampDescription; 32 import org.objectweb.clif.scenario.util.isac.util.IntHolder; 33 import org.w3c.dom.Element ; 34 import org.w3c.dom.NamedNodeMap ; 35 import org.w3c.dom.Node ; 36 import org.w3c.dom.NodeList ; 37 38 47 public class GroupDescriptionManager { 48 49 52 private Hashtable groupDescriptionTable; 54 55 private Hashtable groupRunningBehaviorsTable; 57 58 private Hashtable threadWaitingNumberTable; 59 60 private Hashtable threadRunningRequiredTable ; 61 62 private Hashtable maximumsOfBehaviorsTable ; 63 64 private GroupDescription analysedGroup; 66 67 private RampDescription analysedRamp; 69 70 private Point currentEnd; 71 72 private Point currentStart; 73 74 private Point lastEnd; 75 76 private int analyzeMax ; 77 78 79 80 83 public GroupDescriptionManager() { 84 groupDescriptionTable = new Hashtable (); 85 groupRunningBehaviorsTable = new Hashtable (); 86 threadWaitingNumberTable = new Hashtable (); 87 threadRunningRequiredTable = new Hashtable () ; 88 maximumsOfBehaviorsTable = new Hashtable () ; 89 currentEnd = null; 90 currentStart = null; 91 lastEnd = null; 92 } 93 94 101 public void addGroupDescription(Node node) { 102 analysedGroup = new GroupDescription(null); 103 this.analyzeMax = 0 ; 104 Vector errors = new Vector (); 105 visitGroupDescriptionNode(node, errors); 106 analysedGroup.updateRampDescription(); 107 Integer identifiant = generateId(analysedGroup); 108 groupDescriptionTable.put(identifiant, analysedGroup); 109 groupRunningBehaviorsTable.put(identifiant, new Vector ()); 110 threadWaitingNumberTable.put(identifiant, new IntHolder(0)); 111 threadRunningRequiredTable.put(identifiant, new IntHolder(0)) ; 112 this.maximumsOfBehaviorsTable.put(identifiant, new Integer (this.analyzeMax)) ; 113 } 114 115 123 private Integer generateId(GroupDescription groupDescription) { 124 int keyInt = groupDescription.hashCode(); 125 while (this.groupDescriptionTable.containsKey(new Integer (keyInt))) 127 keyInt++; 128 return new Integer (keyInt); 129 } 130 131 139 private void visitGroupDescriptionNode(Node node, Vector errors) { 140 String tagName = null; 141 switch (node.getNodeType()) { 142 case Node.ELEMENT_NODE : 143 tagName = ((Element ) node).getTagName(); 144 if (org.objectweb.clif.scenario.util.isac.util.tree.Node.RAMP 145 .equals(tagName)) { 146 NamedNodeMap attributes = node.getAttributes(); 147 String style = attributes.getNamedItem("style").getNodeValue(); 148 if (style.equals(RampDescription.LINE_STRING)) { 150 analysedRamp = new RampDescription(null, 151 RampDescription.LINE); 152 } else if (style.equals(RampDescription.ARC_STRING)) { 153 analysedRamp = new RampDescription(null, 154 RampDescription.ARC); 155 } else if (style.equals(RampDescription.CRENEL_VH_STRING)) { 156 analysedRamp = new RampDescription(null, 157 RampDescription.CRENEL_VH); 158 } else if (style.equals(RampDescription.CRENEL_HV_STRING)) { 159 analysedRamp = new RampDescription(null, 160 RampDescription.CRENEL_HV); 161 } 162 } else if (org.objectweb.clif.scenario.util.isac.util.tree.Node.GROUP 163 .equals(tagName)) { 164 NamedNodeMap attributs = node.getAttributes(); 165 String behaviorId = new String (attributs.getNamedItem("behavior").getNodeValue()); 166 this.analysedGroup.setBehaviorId(behaviorId) ; 168 169 Node forceStopAttribute = attributs.getNamedItem("forceStop") ; 170 if (forceStopAttribute != null) { 172 String forceStopValue = forceStopAttribute.getNodeValue() ; 173 if (forceStopValue.equals("false")) { 174 this.analysedGroup.setForceStop(false) ; 176 } 177 } 179 } else if (org.objectweb.clif.scenario.util.isac.util.tree.Node.POINTS 180 .equals(tagName)) { 181 currentEnd = null; 184 currentStart = null; 185 } else if (org.objectweb.clif.scenario.util.isac.util.tree.Node.POINT 186 .equals(tagName)) { 187 if (analysedRamp == null) { 189 errors 190 .add("WARNING : There is a point defined outside a ramp description, ignore it..."); 191 } else { 192 NamedNodeMap attributes = node.getAttributes(); 194 String name = attributes.getNamedItem("name").getNodeValue(); 195 String xAxis = attributes.getNamedItem("x").getNodeValue(); 196 String yAxis = attributes.getNamedItem("y").getNodeValue(); 197 if (xAxis != null && yAxis != null && name != null) { 198 Integer xAxisInteger = new Integer (xAxis); 199 Integer yAxisInteger = new Integer (yAxis); 200 if (this.analyzeMax < (int)yAxisInteger.intValue()) { 202 this.analyzeMax = (int)yAxisInteger.intValue() ; 203 } 204 if (name.equals(RampDescription.POINT_START)) { 206 currentStart = new Point(xAxisInteger.intValue(), 210 yAxisInteger.intValue()); 211 212 if (lastEnd != null) { 214 if (!lastEnd.equals(currentStart)) { 215 errors 216 .add("ERROR : A ramp have a starting point which is not the same than the previous ramp ending point !"); 217 } 218 } 219 if (currentEnd != null) { 220 if (currentStart.x >= currentEnd.x) { 223 errors 224 .add("WARNING : The starting point is after the ending point in the time scale, ignore the ramp !"); 225 } 226 analysedRamp.setStart(currentStart); 229 analysedRamp.setEnd(currentEnd); 230 analysedGroup.addRamp(analysedRamp); 233 } 234 } else if (name.equals(RampDescription.POINT_END)) { 235 currentEnd = new Point(xAxisInteger.intValue(), 237 yAxisInteger.intValue()); 238 if (currentStart != null) { 239 if (currentStart.x >= currentEnd.x) { 242 errors 243 .add("WARNING : The starting point is after the ending point in the time scale, ignore the ramp !"); 244 } 245 analysedRamp.setStart(currentStart); 248 analysedRamp.setEnd(currentEnd); 249 analysedGroup.addRamp(analysedRamp); 252 } 253 254 } else if (name.equals(RampDescription.POINT_ANGLE)) { 255 if (analysedRamp.getType() == RampDescription.LINE) { 257 errors 258 .add("WARNING : The ramp is a line and does not need any angle point, so ignore it !"); 259 } else { 260 analysedRamp 261 .setAngle(new Point(xAxisInteger 262 .intValue(), yAxisInteger 263 .intValue())); 264 } 265 } 266 } else { 267 errors 268 .add("ERROR : One of the point parameter have not been defined, you must define : name, x, y !"); 269 } 270 } 271 } 272 273 break; 274 default : 275 } 277 if (node.hasChildNodes()) { 278 NodeList fils = node.getChildNodes(); 279 for (int i = 0; i < fils.getLength(); i++) { 280 Node tempNode = fils.item(i); 281 visitGroupDescriptionNode(fils.item(i), errors); 282 } 283 } 284 } 285 286 294 public GroupDescription getGroupDescription(Integer groupid) { 295 return (GroupDescription) groupDescriptionTable 296 .get(groupid); 297 } 298 299 306 public Enumeration getGroupsIds() { 307 return groupDescriptionTable.keys(); 308 } 309 310 319 public Vector getGroupRunningBehaviors(Integer id) { 320 return (Vector ) groupRunningBehaviorsTable.get(id); 321 } 322 323 329 public void removeGroup(Integer id) { 330 groupDescriptionTable.remove(id) ; 331 groupRunningBehaviorsTable.remove(id); 332 threadWaitingNumberTable.remove(id) ; 333 } 334 335 public IntHolder getNumberThreadWaitingForAGroup(Integer id) { 336 return (IntHolder) this.threadWaitingNumberTable.get(id); 337 } 338 339 public IntHolder getNumberThreadRunningRequiredForAGroup(Integer id) { 340 return (IntHolder) this.threadRunningRequiredTable.get(id); 341 } 342 343 public int getTotalNumberThreadWaiting() { 344 int result = 0; 345 Enumeration e = this.threadWaitingNumberTable.elements(); 346 while (e.hasMoreElements()) { 347 IntHolder temp = (IntHolder) e.nextElement(); 348 result += temp.getIntValue(); 349 } 350 return result; 351 } 352 353 public int getTotalNumberThreadRunning() { 354 int result = 0; 355 Enumeration e = this.groupRunningBehaviorsTable.elements(); 356 while (e.hasMoreElements()) { 357 Vector temp = (Vector ) e.nextElement(); 358 result += temp.size(); 359 } 360 return result; 361 } 362 363 368 public int getMaximumBehaviorsForAGroup(Integer currentId) { 369 return ((Integer )this.maximumsOfBehaviorsTable.get(currentId)).intValue() ; 370 } 371 372 } | Popular Tags |