Changeset 386
- Timestamp:
- 07/27/10 15:17:29 (2 years ago)
- Files:
-
- kahina/trunk/src/org/kahina/core/KahinaRunner.java (modified) (1 diff)
- kahina/trunk/src/org/kahina/core/KahinaState.java (modified) (2 diffs)
- kahina/trunk/src/org/kahina/core/data/KahinaObject.java (modified) (1 diff)
- kahina/trunk/src/org/kahina/lp/bridge/LogicProgrammingBridge.java (modified) (4 diffs)
- kahina/trunk/src/org/kahina/tralesld/bridge/TraleSLDBridge.java (modified) (9 diffs)
- kahina/trunk/src/org/kahina/tulipa/bridge/TulipaBridge.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
kahina/trunk/src/org/kahina/core/KahinaRunner.java
r384 r386 42 42 } 43 43 44 public static void store(KahinaObject object) 44 @Deprecated 45 public static void store(int id, KahinaObject object) 45 46 { 46 47 // TODO we want to do this differently 47 steps.store( object.getID(), (KahinaStep) object);48 steps.store(id, (KahinaStep) object); 48 49 } 49 50 50 51 @SuppressWarnings("unchecked") 52 @Deprecated 51 53 public static <T extends KahinaObject> T retrieve(Class<T> type, int stepID) 52 54 { kahina/trunk/src/org/kahina/core/KahinaState.java
r381 r386 37 37 private int selectedStepID = -1; 38 38 39 private int nextStepID = 1; 40 39 41 public KahinaState() 40 42 { … … 42 44 consoleLines = new HashMap<Integer,Set<KahinaLineReference>>(); 43 45 KahinaRunner.getControl().registerListener("select", this); 46 } 47 48 public int nextStepID() 49 { 50 return nextStepID++; 44 51 } 45 52 kahina/trunk/src/org/kahina/core/data/KahinaObject.java
r383 r386 1 1 package org.kahina.core.data; 2 2 3 import org.kahina.core.KahinaRunner;3 import java.io.Serializable; 4 4 5 /** 6 * The base class of all Kahina objects, i.e. pieces of information that can be 7 * stored and retrieved using a {@link DataManager}. 8 * 9 * Clients can define their own data types by extending this class. The runtime 10 * class of a Kahina object is referred to as its data type. 11 * 12 * Kahina objects are uniquely identified by their ID ({@link #getID()}). 13 * 14 * @author ke 15 * 16 */ 17 public class KahinaObject 5 public class KahinaObject implements Serializable 18 6 { 19 7 20 private int id; 21 22 private static int nextID = 1; 23 24 /** 25 * @return the ID of this object. If {@link #setID(int)} has not been called 26 * before, this will set the ID of the object to the next available ID. 27 */ 28 public final int getID() 29 { 30 if (id == 0) 31 { 32 synchronized(this) 33 { 34 setID(); 35 } 36 } 37 38 return id; 39 } 40 41 /** 42 * Sets the ID of this object. Callers are responsible for ensuring that IDs 43 * are unique, and that the next available ID has been set high enough using 44 * {@link #setNextID}. 45 * @param id 46 */ 47 public final void setID(int id) 48 { 49 this.id = id; 50 } 51 52 private void setID() 53 { 54 id = nextID++; 55 } 56 57 public static int getNextID() 58 { 59 return nextID; 60 } 61 62 public static void setNextID(int nextID) 63 { 64 KahinaObject.nextID = nextID; 65 } 66 67 @Deprecated 68 public void store() 69 { 70 KahinaRunner.store(this); 71 } 72 73 @Deprecated 74 public void storeCaching() 75 { 76 store(); 77 } 8 /** 9 * 10 */ 11 private static final long serialVersionUID = -262730875988653793L; 78 12 } kahina/trunk/src/org/kahina/lp/bridge/LogicProgrammingBridge.java
r378 r386 71 71 { 72 72 LogicProgrammingStep newStep = generateStep(); 73 intID = newStep.getID();73 intID = state.nextStepID(); 74 74 newStep.setExternalID(extID); 75 newStep.storeCaching();75 KahinaRunner.store(intID, newStep); 76 76 stepIDConv.put(extID, intID); 77 77 } … … 91 91 step.setGoalDesc(nodeLabel); 92 92 step.setSourceCodeLocation(LogicProgrammingStep.get(currentID).getSourceCodeLocation()); 93 step.storeCaching();93 KahinaRunner.store(stepID, step); 94 94 KahinaRunner.processEvent(new LogicProgrammingBridgeEvent(LogicProgrammingBridgeEventType.SET_GOAL_DESC, stepID, nodeLabel)); 95 95 currentID = stepID; … … 115 115 step.setSourceCodeLocation(new KahinaSourceCodeLocation(absolutePath, lineNumber - 1, stepID)); 116 116 currentID = stepID; 117 step.storeCaching();117 KahinaRunner.store(stepID, step); 118 118 } catch (Exception e) 119 119 { … … 156 156 LogicProgrammingStep lastStep = LogicProgrammingStep.get(lastStepID); 157 157 LogicProgrammingStep newStep = lastStep.copy(); 158 newStep.storeCaching();159 int newStepID = newStep.getID();158 int newStepID = state.nextStepID(); 159 KahinaRunner.store(newStepID, newStep); 160 160 stepIDConv.put(extID, newStepID); 161 161 KahinaRunner.processEvent(new LogicProgrammingBridgeEvent(LogicProgrammingBridgeEventType.STEP_REDO, lastStepID)); kahina/trunk/src/org/kahina/tralesld/bridge/TraleSLDBridge.java
r381 r386 27 27 import org.kahina.tralesld.control.event.TraleSLDBridgeEventType; 28 28 import org.kahina.tralesld.data.chart.TraleSLDChartEdgeStatus; 29 import org.kahina.tralesld.data.fs.TraleSLDFS;30 29 import org.kahina.tralesld.data.fs.TraleSLDFSPacker; 31 30 import org.kahina.tralesld.data.fs.TraleSLDVariableBinding; … … 76 75 newStep.setGoalDesc("init"); 77 76 newStep.setExternalID(0); 78 stepIDConv.put(0, newStep.getID());79 newStep.storeCaching();80 int id = newStep.getID();81 KahinaRunner.processEvent(new TraleSLDBridgeEvent(TraleSLDBridgeEventType.INIT, id, wordList.toString()));82 KahinaRunner.processEvent(new KahinaSelectionEvent( id));83 currentID = newStep .getID();84 85 state.consoleMessage(newStep .getID(), 0, LogicProgrammingStepType.CALL, "initialising parse: " + parsedSentenceList);77 int newStepID = state.nextStepID(); 78 stepIDConv.put(0, newStepID); 79 KahinaRunner.store(newStepID, newStep); 80 KahinaRunner.processEvent(new TraleSLDBridgeEvent(TraleSLDBridgeEventType.INIT, newStepID, wordList.toString())); 81 KahinaRunner.processEvent(new KahinaSelectionEvent(newStepID)); 82 currentID = newStepID; 83 84 state.consoleMessage(newStepID, 0, LogicProgrammingStepType.CALL, "initialising parse: " + parsedSentenceList); 86 85 // if (bridgeState == 'n') KahinaRunner.processEvent(new 87 86 // KahinaSelectionEvent(newStep.getID())); … … 217 216 System.err.println("TraleSLDBridge.registerRuleApplication(" + extID + ",\"" + ruleName + "," + leftmostDaughter + "\")"); 218 217 } 219 TraleSLDStep newStep = generateStep();218 final TraleSLDStep newStep = generateStep(); 220 219 newStep.setGoalDesc("rule(" + ruleName + ")"); 221 220 newStep.setExternalID(extID); 222 stepIDConv.put(extID, newStep.getID()); 221 int newStepID = state.nextStepID(); 222 stepIDConv.put(extID, newStepID); 223 223 registerProspectiveEdge(extID, ruleName, leftmostDaughter); 224 224 if (verbose) … … 226 226 System.err.println("Storing new step."); 227 227 } 228 newStep.storeCaching();228 KahinaRunner.store(newStepID, newStep); 229 229 if (verbose) 230 230 { … … 232 232 } 233 233 // let TraleSLDTreeBehavior do the rest 234 KahinaRunner.processEvent(new TraleSLDBridgeEvent(TraleSLDBridgeEventType.RULE_APP, newStep .getID(), ruleName, extID));234 KahinaRunner.processEvent(new TraleSLDBridgeEvent(TraleSLDBridgeEventType.RULE_APP, newStepID, ruleName, extID)); 235 235 if (verbose) 236 236 { … … 238 238 } 239 239 // experimental: message for console 240 state.consoleMessage(newStep .getID(), extID, LogicProgrammingStepType.CALL, consoleMessage);240 state.consoleMessage(newStepID, extID, LogicProgrammingStepType.CALL, consoleMessage); 241 241 if (verbose) 242 242 { … … 245 245 // if (bridgeState == 'n') 246 246 { 247 KahinaRunner.processEvent(new KahinaSelectionEvent(newStep .getID()));247 KahinaRunner.processEvent(new KahinaSelectionEvent(newStepID)); 248 248 } 249 249 // the following two actions and the structures they operate on seem … … 306 306 try 307 307 { 308 // if (verbose) 309 // System.err.println("registerMessageEnd(" + extID + ",\"" + key + 310 // "\"): " + grisuMessage); 311 TraleSLDStep step = TraleSLDStep.get(stepIDConv.get(extID)); 308 int stepID = stepIDConv.get(extID); 309 final TraleSLDStep step = TraleSLDStep.get(stepID); 312 310 if ("start".equals(key)) 313 311 { 314 step.startFeatStruct = createFSObject(grisuMessage, step.getID());312 step.startFeatStruct = packer.pack(grisuMessage); 315 313 } else if ("end".equals(key)) 316 314 { 317 step.endFeatStruct = createFSObject(grisuMessage, step.getID()); 318 } 319 step.storeCaching(); 320 } catch (Exception e) 321 { 322 e.printStackTrace(); 323 System.exit(1); 324 } 325 } 326 327 private TraleSLDFS createFSObject(String grisuMessage, int stepID) 328 { 329 /*if (KahinaRunner.getDataHandlingMethod() == KahinaDataHandlingMethod.MAGAZINE) 330 { 331 // YUCK! 332 if (stepID - lastStepIDWithFreshPacker >= 1000) 333 { 334 packer = new TraleSLDFSPacker(); 335 lastStepIDWithFreshPacker = stepID; 336 } 337 }*/ 338 return packer.pack(grisuMessage); 339 } 340 341 private TraleSLDVariableBinding createBindingObject(TraleSLDVariableBinding traleSLDVariableBinding, int stepID) 342 { 343 /*if (KahinaRunner.getDataHandlingMethod() == KahinaDataHandlingMethod.MAGAZINE) 344 { 345 if (stepID - lastStepIDWithFreshSharer >= 1000) 346 { 347 bindingSharer = new Sharer<TraleSLDVariableBinding>(); 348 lastStepIDWithFreshSharer = stepID; 349 } 350 }*/ 351 return bindingSharer.share(traleSLDVariableBinding); 352 } 353 315 step.endFeatStruct = packer.pack(grisuMessage); 316 } 317 KahinaRunner.store(stepID, step); 318 } catch (Exception e) 319 { 320 e.printStackTrace(); 321 System.exit(1); 322 } 323 } 354 324 355 325 public void registerMessage(int extID, String key, String varName, String type, String grisuMessage) … … 377 347 try 378 348 { 379 // if (verbose) 380 // { 381 // System.err.println("registerMessageEnd(" + extID + ",\"" + 382 // varName + ",\"" + tag + ",\"" + type + "): " + grisuMessage); 383 // } 384 TraleSLDStep step = TraleSLDStep.get(stepIDConv.get(extID)); 385 int id = step.getID(); 386 TraleSLDVariableBinding binding = createBindingObject(new TraleSLDVariableBinding(varName, tag, type, createFSObject(grisuMessage, id)), id); 349 int id = stepIDConv.get(extID); 350 TraleSLDStep step = TraleSLDStep.get(id); 351 TraleSLDVariableBinding binding = bindingSharer.share(new TraleSLDVariableBinding(varName, tag, type, packer.pack(grisuMessage))); 387 352 if ("start".equals(key)) 388 353 { kahina/trunk/src/org/kahina/tulipa/bridge/TulipaBridge.java
r357 r386 60 60 { 61 61 TulipaStep newStep = generateStep(); 62 intID = newStep.getID();62 intID = state.nextStepID(); 63 63 newStep.setExternalID(extID); 64 newStep.storeCaching();64 KahinaRunner.store(intID, newStep); 65 65 itemIDConv.put(extID, intID); 66 66 } … … 291 291 TulipaStep step = TulipaStep.get(stepID); 292 292 step.setItemDesc(label.substring(0, label.indexOf("-->"))); 293 step.storeCaching();293 KahinaRunner.store(stepID, step); 294 294 KahinaRunner.processEvent(new TulipaBridgeEvent(TulipaBridgeEventType.SET_ITEM_DESC, stepID, label.substring(0, label.indexOf("-->")))); 295 295 currentID = stepID;
