Changeset 5808 for trunk/gli/src/org/greenstone/gatherer/msm
- Timestamp:
- 2003-11-07T13:55:10+13:00 (21 years ago)
- 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 179 179 metadata_element.setAttribute(MODE_ATTRIBUTE, ACCUMULATE); 180 180 } 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 } 187 193 ///ystem.err.println("Creating node in GDMDocument: '" + node_value + "'"); 188 194 metadata_element.appendChild(base_document.createTextNode(node_value)); … … 280 286 // ***** LEGACY SUPPORT ***** 281 287 // 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) { 283 289 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); 285 291 Gatherer.println("Updated Path To: " + raw_value); 286 292 metadata_element.setAttribute(HVALUE_ATTRIBUTE, raw_value); … … 362 368 } 363 369 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); 365 374 if(!raw_value.equals(current_value)) { 366 375 // Remove old text -
trunk/gli/src/org/greenstone/gatherer/msm/GDMManager.java
r5793 r5808 56 56 */ 57 57 public class GDMManager 58 extends HashMap58 extends LinkedHashMap 59 59 implements MSMListener { 60 60 /** A list of the known metadata instances, thus we only store one of each unique metadata, and reference the rest. */ … … 64 64 /** 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. */ 65 65 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; 66 68 static final private String METADATA_XML = "metadata.xml"; 67 69 /** Constructor. */ … … 72 74 Gatherer.c_man.getCollection().msm.addMSMListener(this); 73 75 // 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(); 76 78 ///atherer.println("New GDMManager created."); 77 79 } 78 80 79 80 81 81 82 83 82 84 public GDMManager(boolean dummy_load) { 83 85 super(); … … 151 153 if(containsKey(metadata_file)) { 152 154 metadata_xml = (GDMDocument) get(metadata_file); 155 ///ystem.err.println("Get the GDMDocument for " + metadata_file.getAbsolutePath()); 153 156 } 154 157 else { 155 158 // Now the two potential cache misses. The first requires us to load an existing metadata.xml 156 159 if(metadata_file.exists()) { 160 ///ystem.err.println("Reload the GDMDocument for " + metadata_file.getAbsolutePath()); 157 161 metadata_xml = new GDMDocument(metadata_file); 158 162 } 159 163 // The final case is where no current metadata.xml exists. Create a new one just by creating a new GDMDocument. 160 164 else { 165 ///ystem.err.println("Create a new GDMDocument for " + metadata_file.getAbsolutePath()); 161 166 metadata_xml = new GDMDocument(); 162 167 } … … 198 203 GDMDocument document = getDummyDocument(file); 199 204 200 205 201 206 } 202 207 /** 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. */ … … 365 370 GDMDocument document = (GDMDocument) get(file); 366 371 if(!document.isUpToDate()) { 372 //ystem.err.println("Saving: " + file.getAbsolutePath()); 367 373 // First purge any old references. 368 374 document.getMetadata(null, false, null, null, true); … … 405 411 } 406 412 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 407 425 /** 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. 408 426 * @param event A <strong>MSMEvent</strong> containing details of the event that caused this message to be fired. … … 421 439 422 440 public void waitUntilComplete() { 423 gdm_loader.waitUntilComplete(); 441 if(gdm_loader != null) { 442 gdm_loader.waitUntilComplete(); 443 } 424 444 } 425 445 … … 445 465 } 446 466 447 467 448 468 public void run() { 449 469 // Can't open a collections metadata when the collection isn't open! … … 471 491 remaining.add(record.getChildAt(i)); 472 492 } 493 494 ///atherer.println("Retrieving metadata.xml for " + record); 495 getMetadata(record.getFile()); 496 497 record.unmap(); 473 498 } 474 499 record = null; … … 488 513 } 489 514 } 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 } 490 530 }
Note:
See TracChangeset
for help on using the changeset viewer.