Changeset 386

Show
Ignore:
Timestamp:
07/27/10 15:17:29 (2 years ago)
Author:
ke
Message:

Step IDs are no longer managed by KahinaObject?, but by KahinaState?. Loading saved sessions seems to work well already, except for the strange tree layer issue.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • kahina/trunk/src/org/kahina/core/KahinaRunner.java

    r384 r386  
    4242    } 
    4343 
    44         public static void store(KahinaObject object) 
     44    @Deprecated 
     45        public static void store(int id, KahinaObject object) 
    4546        { 
    4647                // TODO we want to do this differently 
    47                 steps.store(object.getID(), (KahinaStep) object); 
     48                steps.store(id, (KahinaStep) object); 
    4849        } 
    4950 
    5051        @SuppressWarnings("unchecked") 
     52        @Deprecated 
    5153        public static <T extends KahinaObject> T retrieve(Class<T> type, int stepID) 
    5254        { 
  • kahina/trunk/src/org/kahina/core/KahinaState.java

    r381 r386  
    3737    private int selectedStepID = -1; 
    3838     
     39    private int nextStepID = 1; 
     40     
    3941    public KahinaState() 
    4042    { 
     
    4244        consoleLines = new HashMap<Integer,Set<KahinaLineReference>>(); 
    4345        KahinaRunner.getControl().registerListener("select", this); 
     46    } 
     47     
     48    public int nextStepID() 
     49    { 
     50        return nextStepID++; 
    4451    } 
    4552     
  • kahina/trunk/src/org/kahina/core/data/KahinaObject.java

    r383 r386  
    11package org.kahina.core.data; 
    22 
    3 import org.kahina.core.KahinaRunner
     3import java.io.Serializable
    44 
    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 
     5public class KahinaObject implements Serializable 
    186{ 
    197 
    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; 
    7812} 
  • kahina/trunk/src/org/kahina/lp/bridge/LogicProgrammingBridge.java

    r378 r386  
    7171                { 
    7272                        LogicProgrammingStep newStep = generateStep(); 
    73                         intID = newStep.getID(); 
     73                        intID = state.nextStepID(); 
    7474                        newStep.setExternalID(extID); 
    75                         newStep.storeCaching(); 
     75                        KahinaRunner.store(intID, newStep); 
    7676                        stepIDConv.put(extID, intID); 
    7777                } 
     
    9191                        step.setGoalDesc(nodeLabel); 
    9292                        step.setSourceCodeLocation(LogicProgrammingStep.get(currentID).getSourceCodeLocation()); 
    93                         step.storeCaching(); 
     93                        KahinaRunner.store(stepID, step); 
    9494                        KahinaRunner.processEvent(new LogicProgrammingBridgeEvent(LogicProgrammingBridgeEventType.SET_GOAL_DESC, stepID, nodeLabel)); 
    9595                        currentID = stepID; 
     
    115115                        step.setSourceCodeLocation(new KahinaSourceCodeLocation(absolutePath, lineNumber - 1, stepID)); 
    116116                        currentID = stepID; 
    117                         step.storeCaching(); 
     117                        KahinaRunner.store(stepID, step); 
    118118                } catch (Exception e) 
    119119                { 
     
    156156                        LogicProgrammingStep lastStep = LogicProgrammingStep.get(lastStepID); 
    157157                        LogicProgrammingStep newStep = lastStep.copy(); 
    158                         newStep.storeCaching(); 
    159                         int newStepID = newStep.getID(); 
     158                        int newStepID = state.nextStepID(); 
     159                        KahinaRunner.store(newStepID, newStep); 
    160160                        stepIDConv.put(extID, newStepID); 
    161161                        KahinaRunner.processEvent(new LogicProgrammingBridgeEvent(LogicProgrammingBridgeEventType.STEP_REDO, lastStepID)); 
  • kahina/trunk/src/org/kahina/tralesld/bridge/TraleSLDBridge.java

    r381 r386  
    2727import org.kahina.tralesld.control.event.TraleSLDBridgeEventType; 
    2828import org.kahina.tralesld.data.chart.TraleSLDChartEdgeStatus; 
    29 import org.kahina.tralesld.data.fs.TraleSLDFS; 
    3029import org.kahina.tralesld.data.fs.TraleSLDFSPacker; 
    3130import org.kahina.tralesld.data.fs.TraleSLDVariableBinding; 
     
    7675                        newStep.setGoalDesc("init"); 
    7776                        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); 
    8685                        // if (bridgeState == 'n') KahinaRunner.processEvent(new 
    8786                        // KahinaSelectionEvent(newStep.getID())); 
     
    217216                                System.err.println("TraleSLDBridge.registerRuleApplication(" + extID + ",\"" + ruleName + "," + leftmostDaughter + "\")"); 
    218217                        } 
    219                         TraleSLDStep newStep = generateStep(); 
     218                        final TraleSLDStep newStep = generateStep(); 
    220219                        newStep.setGoalDesc("rule(" + ruleName + ")"); 
    221220                        newStep.setExternalID(extID); 
    222                         stepIDConv.put(extID, newStep.getID()); 
     221                        int newStepID = state.nextStepID(); 
     222                        stepIDConv.put(extID, newStepID); 
    223223                        registerProspectiveEdge(extID, ruleName, leftmostDaughter); 
    224224                        if (verbose) 
     
    226226                                System.err.println("Storing new step."); 
    227227                        } 
    228                         newStep.storeCaching(); 
     228                        KahinaRunner.store(newStepID, newStep); 
    229229                        if (verbose) 
    230230                        { 
     
    232232                        } 
    233233                        // 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)); 
    235235                        if (verbose) 
    236236                        { 
     
    238238                        } 
    239239                        // experimental: message for console 
    240                         state.consoleMessage(newStep.getID(), extID, LogicProgrammingStepType.CALL, consoleMessage); 
     240                        state.consoleMessage(newStepID, extID, LogicProgrammingStepType.CALL, consoleMessage); 
    241241                        if (verbose) 
    242242                        { 
     
    245245                        // if (bridgeState == 'n') 
    246246                        { 
    247                                 KahinaRunner.processEvent(new KahinaSelectionEvent(newStep.getID())); 
     247                                KahinaRunner.processEvent(new KahinaSelectionEvent(newStepID)); 
    248248                        } 
    249249                        // the following two actions and the structures they operate on seem 
     
    306306                try 
    307307                { 
    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); 
    312310                        if ("start".equals(key)) 
    313311                        { 
    314                                 step.startFeatStruct = createFSObject(grisuMessage, step.getID()); 
     312                                step.startFeatStruct = packer.pack(grisuMessage); 
    315313                        } else if ("end".equals(key)) 
    316314                        { 
    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        } 
    354324 
    355325        public void registerMessage(int extID, String key, String varName, String type, String grisuMessage) 
     
    377347                try 
    378348                { 
    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))); 
    387352                        if ("start".equals(key)) 
    388353                        { 
  • kahina/trunk/src/org/kahina/tulipa/bridge/TulipaBridge.java

    r357 r386  
    6060        { 
    6161            TulipaStep newStep = generateStep(); 
    62             intID = newStep.getID(); 
     62            intID = state.nextStepID(); 
    6363            newStep.setExternalID(extID); 
    64             newStep.storeCaching(); 
     64            KahinaRunner.store(intID, newStep); 
    6565            itemIDConv.put(extID, intID); 
    6666        } 
     
    291291            TulipaStep step = TulipaStep.get(stepID); 
    292292            step.setItemDesc(label.substring(0, label.indexOf("-->"))); 
    293             step.storeCaching(); 
     293            KahinaRunner.store(stepID, step); 
    294294            KahinaRunner.processEvent(new TulipaBridgeEvent(TulipaBridgeEventType.SET_ITEM_DESC, stepID, label.substring(0, label.indexOf("-->")))); 
    295295            currentID = stepID;