Changeset 5808 for trunk


Ignore:
Timestamp:
2003-11-07T13:55:10+13:00 (20 years ago)
Author:
jmt12
Message:

Several changes needed to make pipe the hierarchy separator while keeping backslash as what the user sees. Also made some tweaks to improve memory usage - hopefully. Need some testing to ensure hierarchy stuff works properly though.

Location:
trunk/gli/src/org/greenstone/gatherer/msm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/msm/GDMDocument.java

    r5668 r5808  
    179179        metadata_element.setAttribute(MODE_ATTRIBUTE, ACCUMULATE);
    180180        }
    181         // As we can't possibly store all the metadata in memory, nor can we ensure that the indexes written to file remain the same until the new time we look at this file, and to avoid having to open a rewrite every collection document whenever any value tree changes, I'm adding a new attribute called hvalue which indicates the hierarchy value path as a '\\' separated string.
    182         GValueModel model = Gatherer.c_man.getCollection().msm.getValueTree(metadata.getElement());
    183         if(model != null && model.isHierarchy()) {
    184         metadata_element.setAttribute(HVALUE_ATTRIBUTE, metadata.getValueNode().getFullPath(false));
    185         }
    186         String node_value = metadata.getAbsoluteValue();
     181        // As we can't possibly store all the metadata in memory, nor can we ensure that the indexes written to file remain the same until the new time we look at this file, and to avoid having to open a rewrite every collection document whenever any value tree changes, I'm adding a new attribute called hvalue which indicates the hierarchy value path as a '|' separated string.
     182        GValueModel model = Gatherer.c_man.getCollection().msm.getValueTree(metadata.getElement());
     183        String node_value = null;
     184        if(model != null && model.isHierarchy()) {
     185            node_value = Codec.transform(metadata.getValueNode().getFullPath(false), Codec.TEXT_TO_DOM);
     186            ///ystem.err.println("Saving H Info: " + node_value);
     187            metadata_element.setAttribute(HVALUE_ATTRIBUTE, node_value);
     188        }
     189        else {
     190            node_value = metadata.getAbsoluteValue();
     191            ///ystem.err.println("Not H Info: " + node_value);
     192        }
    187193        ///ystem.err.println("Creating node in GDMDocument: '" + node_value + "'");
    188194        metadata_element.appendChild(base_document.createTextNode(node_value));
     
    280286                // ***** LEGACY SUPPORT *****
    281287                // If this raw_value contains a '\' character, but no '\\', '[' or ']' characters, then replace the '\' with a '\\'
    282                 if(raw_value.indexOf(StaticStrings.ESCAPE_STR) != -1 && raw_value.indexOf(StaticStrings.ESCAPE_STR + StaticStrings.ESCAPE_STR) == -1 && raw_value.indexOf(StaticStrings.RBRACKET_CHARACTER) == -1 && raw_value.indexOf(StaticStrings.LBRACKET_CHARACTER) == -1) {
     288                if(raw_value.indexOf(StaticStrings.ESCAPE_STR) != -1) {
    283289                    Gatherer.println("Detected Legacy Path: " + raw_value);
    284                     raw_value = raw_value.replaceAll(StaticStrings.ESCAPE_PATTERN, StaticStrings.ESCAPE_PATTERN + StaticStrings.ESCAPE_PATTERN);
     290                    raw_value = raw_value.replaceAll(StaticStrings.ESCAPE_PATTERN, StaticStrings.PIPE_STR);
    285291                    Gatherer.println("Updated Path To: " + raw_value);
    286292                    metadata_element.setAttribute(HVALUE_ATTRIBUTE, raw_value);
     
    362368                    }
    363369                    else {
    364                     String current_value = metadata.getAbsoluteValue();
     370                    //String current_value = metadata.getAbsoluteValue();
     371                    String current_value = Codec.transform(metadata.getValueNode().getFullPath(false), Codec.TEXT_TO_DOM);
     372                    ///ystem.err.println("Checking the current hfile: " + current_value);
     373                    ///ystem.err.println("Against whats in the hfile: " + current_value);
    365374                    if(!raw_value.equals(current_value)) {
    366375                        // Remove old text
  • trunk/gli/src/org/greenstone/gatherer/msm/GDMManager.java

    r5793 r5808  
    5656*/
    5757public class GDMManager
    58     extends HashMap
     58    extends LinkedHashMap
    5959    implements MSMListener {
    6060    /** A list of the known metadata instances, thus we only store one of each unique metadata, and reference the rest. */
     
    6464    /** The threaded object responsible for loading all of the existing metadata.xml files prior to any save action. This is necessary so that hierarchy indexes within the metadata.xml files stay fresh. */
    6565    private GDMLoader gdm_loader = null;
     66    /** The maximum number of GDMDocuments to load at any one time */
     67    static final private int MAX_DOCUMENTS = 25;
    6668    static final private String METADATA_XML = "metadata.xml";
    6769    /** Constructor. */
     
    7274    Gatherer.c_man.getCollection().msm.addMSMListener(this);
    7375    // Now create and start the synchronous GDM loader.
    74     gdm_loader = new GDMLoader(false);
    75     gdm_loader.start();
     76    //gdm_loader = new GDMLoader();
     77    //gdm_loader.start();
    7678    ///atherer.println("New GDMManager created.");
    7779    }
    7880
    79    
    80 
    81    
     81
     82
     83
    8284    public GDMManager(boolean dummy_load) {
    8385    super();
     
    151153    if(containsKey(metadata_file)) {
    152154        metadata_xml = (GDMDocument) get(metadata_file);
     155        ///ystem.err.println("Get the GDMDocument for " + metadata_file.getAbsolutePath());
    153156    }
    154157    else {
    155158        // Now the two potential cache misses. The first requires us to load an existing metadata.xml
    156159        if(metadata_file.exists()) {
     160        ///ystem.err.println("Reload the GDMDocument for " + metadata_file.getAbsolutePath());
    157161        metadata_xml = new GDMDocument(metadata_file);
    158162        }
    159163        // The final case is where no current metadata.xml exists. Create a new one just by creating a new GDMDocument.
    160164        else {
     165        ///ystem.err.println("Create a new GDMDocument for " + metadata_file.getAbsolutePath());
    161166        metadata_xml = new GDMDocument();
    162167        }
     
    198203    GDMDocument document = getDummyDocument(file);
    199204
    200    
     205
    201206    }
    202207    /** Recover the metadata associated with a particular file. Note that this call is synchronized, so that all of the data holders don't need to be. */
     
    365370        GDMDocument document = (GDMDocument) get(file);
    366371        if(!document.isUpToDate()) {
     372        //ystem.err.println("Saving: " + file.getAbsolutePath());
    367373        // First purge any old references.
    368374        document.getMetadata(null, false, null, null, true);
     
    405411    }
    406412
     413    /** Write out the latest copy of a certain document. */
     414    public void save(File file, GDMDocument document) {
     415        if(!document.isUpToDate()) {
     416            // First purge any old references.
     417            document.getMetadata(null, false, null, null, true);
     418            // Now write the xml
     419            Utility.export(document.getDocument(), file);
     420            document.setUpToDate(true);
     421        }
     422    }
     423
     424
    407425    /** Method that is called whenever the metadata set collection changes in some way, such as the addition of a new set or the merging of two sets. If a set changes, mark all cached GDMDocuments as being stale.
    408426     * @param event A <strong>MSMEvent</strong> containing details of the event that caused this message to be fired.
     
    421439
    422440    public void waitUntilComplete() {
    423     gdm_loader.waitUntilComplete();
     441        if(gdm_loader != null) {
     442        gdm_loader.waitUntilComplete();
     443        }
    424444    }
    425445
     
    445465    }
    446466
    447    
     467
    448468    public void run() {
    449469        // Can't open a collections metadata when the collection isn't open!
     
    471491            remaining.add(record.getChildAt(i));
    472492            }
     493
     494            ///atherer.println("Retrieving metadata.xml for " + record);
     495            getMetadata(record.getFile());
     496
     497            record.unmap();
    473498        }
    474499        record = null;
     
    488513    }
    489514    }
     515
     516    protected boolean removeEldestEntry(Map.Entry eldest) {
     517        if(size() > MAX_DOCUMENTS) {
     518            // Save the oldest document before its dumped
     519            File file = (File) eldest.getKey();
     520            ///ystem.err.println("Dumping oldest Document: " + file.getAbsolutePath());
     521            GDMDocument document = (GDMDocument) eldest.getValue();
     522            save(file, document);
     523            // And then dump it
     524            return true;
     525        }
     526        else {
     527            return false;
     528        }
     529     }
    490530}
Note: See TracChangeset for help on using the changeset viewer.