Changeset 7601


Ignore:
Timestamp:
2004-06-17T11:08:27+12:00 (20 years ago)
Author:
mdewsnip
Message:

Have hopefully (and finally!) fixed the nasty race conditions with the local library server (causing, for example, the "could not remove index directory" problems). The Gatherer.configServer function performs an HTTP request, but returns before the local library processing is actually complete.

This can be solved by calling the configServer function again, with an empty string argument -- this extra request will not return until the first (real) request is processed.

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
4 edited

Legend:

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

    r7454 r7601  
    414414    }
    415415
    416     // used to send new coll messages to the local library
    417     public void configServer(String command) {
    418 
     416    // Used to send messages to the local library
     417    // Warning: this has a lot of potential for nasty race conditions
     418    // The response code is returned immediately -- but this does not mean the local
     419    //   library action has finished!
     420    public void configServer(String command)
     421    {
    419422    try {
    420423        String raw_url = config.exec_address.toString() + command;
     
    431434        url = null;
    432435    }
    433     catch(Exception exception) {
     436    catch (Exception ex) {
     437        ex.printStackTrace();
    434438        Gatherer.printStackTrace(exception);
    435         ///ystem.err.println("Bad URL.");
    436     }
    437 
     439    }
    438440    }
    439441
  • trunk/gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.java

    r7600 r7601  
    214214      // Release the collection
    215215      Gatherer.self.configServer(GSDLSiteConfig.RELEASE_COMMAND + Gatherer.c_man.getCollection().getName());
    216      collection_released = true;
     216      // This is very important -- it ensures that the above command has finished
     217      Gatherer.self.configServer("");
     218      collection_released = true;
    217219      }
    218220
     
    225227      // Then re-add it to force format commands to be processed
    226228      Gatherer.self.configServer(GSDLSiteConfig.ADD_COMMAND + Gatherer.c_man.getCollection().getName());
     229      // This is very important -- it ensures that the above command has finished
     230      Gatherer.self.configServer("");
    227231     // Unset formats changed
    228232     format_manager.setFormatsChanged(false);
  • trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r7592 r7601  
    11671167        if(installCollection()) {
    11681168        // If we have a local library running (that we know about) then we ask it to add our newly create collection
    1169         if(Gatherer.config.exec_file != null) {
     1169        if (Gatherer.config.exec_file != null) {
    11701170            Gatherer.self.configServer(GSDLSiteConfig.ADD_COMMAND + collection.getName());
    1171         } else if (Gatherer.GS3) {
     1171            // This is very important -- it ensures that the above command has finished
     1172            Gatherer.self.configServer("");
     1173        }
     1174        else if (Gatherer.GS3) {
    11721175            convertToGS3Collection();
    11731176            Gatherer.self.configGS3Server(Gatherer.config.site_name, ServletConfiguration.ADD_COMMAND + collection.getName());
     
    11771180        Gatherer.g_man.collectionChanged(ready());
    11781181
    1179         // Now display a message dialog saying its all built
    1180         WarningDialog collection_built_warning_dialog = new WarningDialog("warning.CollectionBuilt", false);
    1181         collection_built_warning_dialog.setMessageOnly(true); // Not a warning
    1182         collection_built_warning_dialog.display();
    1183         collection_built_warning_dialog.dispose();
    1184         collection_built_warning_dialog = null;
     1182        // Now display a message dialog saying its all built
     1183        WarningDialog collection_built_warning_dialog = new WarningDialog("warning.CollectionBuilt", false);
     1184        collection_built_warning_dialog.setMessageOnly(true); // Not a warning
     1185        collection_built_warning_dialog.display();
     1186        collection_built_warning_dialog.dispose();
     1187        collection_built_warning_dialog = null;
    11851188        }
    11861189        else {
     
    14161419
    14171420    try {
    1418         // We have to ensure that the local library doesn't have locks on any files
    1419         if(!Gatherer.GS3 && Gatherer.config.exec_file != null) {
     1421        // We have to ensure that the local library has released this collection so we can delete the index directory
     1422        if (!Gatherer.GS3 && Gatherer.config.exec_file != null) {
    14201423        Gatherer.self.configServer(GSDLSiteConfig.RELEASE_COMMAND + collection.getName());
    1421         }
    1422 
    1423         File build_dir = new File(getCollectionBuild());
    1424         Gatherer.println("Build = " + build_dir.getAbsolutePath());
    1425 
    1426         // Make sure an index directory exists to move files into
     1424
     1425        // This is very important -- it ensures that the above command has finished
     1426        // This prevents the nasty "could not remove index directory" race condition!
     1427        Gatherer.self.configServer("");
     1428        }
     1429
    14271430        File index_dir = new File(getCollectionIndex());
    1428         if (!index_dir.exists()) {
    1429         index_dir.mkdir();
    1430         }
    14311431        Gatherer.println("Index = " + index_dir.getAbsolutePath());
    14321432
    1433         moveContentsInto(build_dir, index_dir, true);
     1433        File building_dir = new File(getCollectionBuild());
     1434        Gatherer.println("Building = " + building_dir.getAbsolutePath());
     1435
     1436        // Get the build mode from the build options
     1437        String build_mode = collection.build_options.getBuildValue("mode");
     1438
     1439        // Special case for build mode "all": replace index dir with building dir
     1440        if (build_mode == null || build_mode.equals(Dictionary.get("CreatePane.Mode_All"))) {
     1441        // Remove the old index directory
     1442        if (index_dir.exists()) {
     1443            Utility.delete(index_dir);
     1444            // Check the delete worked
     1445            if (index_dir.exists()) {
     1446            throw new Exception("Index directory could not be removed.");
     1447            }
     1448        }
     1449
     1450        // Move the building directory to become the new index directory
     1451        if (building_dir.renameTo(index_dir) == false) {
     1452            throw new Exception("Build directory could not be moved.");
     1453        }
     1454        }
     1455
     1456        // Otherwise copy everything in the building dir into the index dir
     1457        else {
     1458        moveContentsInto(building_dir, index_dir);
     1459        }
    14341460    }
    14351461    catch (Exception exception) {
     
    14371463        return false;
    14381464    }
    1439 
    14401465    return true;
    14411466    }
    14421467
    14431468
    1444     /** Moves all the files in one directory into another, overwriting if desired */
    1445     private void moveContentsInto(File source_directory, File target_directory, boolean overwrite)
     1469    /** Moves all the files in one directory into another, overwriting existing files */
     1470    private void moveContentsInto(File source_directory, File target_directory)
    14461471    {
    14471472    File[] source_files = source_directory.listFiles();
     
    14511476
    14521477        if (source_file.isDirectory()) {
    1453         moveContentsInto(source_file, target_file, overwrite);
     1478        moveContentsInto(source_file, target_file);
    14541479        source_file.delete();
    14551480        }
    14561481        else {
    1457         if (target_file.exists() && overwrite) {
     1482        if (target_file.exists()) {
    14581483            target_file.delete();
    1459             source_file.renameTo(target_file);
    14601484        }
     1485
     1486        source_file.renameTo(target_file);
    14611487        }
    14621488    }
  • trunk/gli/src/org/greenstone/gatherer/collection/DeleteCollectionPrompt.java

    r7600 r7601  
    308308
    309309        // first of all we must release it from the local library
    310         if(Gatherer.config.exec_file != null) {
     310        if (Gatherer.config.exec_file != null) {
    311311        ///ystem.err.println("Local Library Found!");
    312312        Gatherer.self.configServer(GSDLSiteConfig.RELEASE_COMMAND + collection.getShortName());
     313        // This is very important -- it ensures that the above command has finished
     314        Gatherer.self.configServer("");
    313315        }
    314316
Note: See TracChangeset for help on using the changeset viewer.