Changeset 13779 for trunk/gli


Ignore:
Timestamp:
2007-01-24T11:43:02+13:00 (17 years ago)
Author:
mdewsnip
Message:

Now reads the output of config commands sent to the local library server, to ensure they are finished.

File:
1 edited

Legend:

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

    r13593 r13779  
    5252    {
    5353    config(ADD_COMMAND + collection_name);
    54     // This is very important -- it ensures that the above command has finished
    55     config("");
    5654    }
    5755
    5856
    5957    // Used to send messages to the local library
    60     // Warning: this has a lot of potential for nasty race conditions
    61     // The response code is returned immediately -- but this does not mean the local
    62     //   library action has finished!
    6358    static private void config(String command)
    6459    {
     
    7166        URL url = new URL(Configuration.library_url.toString() + command);
    7267        HttpURLConnection library_connection = (HttpURLConnection) url.openConnection();
     68
     69        // It's very important that we read the output of the command
     70        // This ensures that the command has actually finished
     71        // (The response code is returned immediately)
     72        InputStream library_is = library_connection.getInputStream();
     73        BufferedReader library_in = new BufferedReader(new InputStreamReader(library_is, "UTF-8"));
     74        String library_output_line = library_in.readLine();
     75        while (library_output_line != null) {
     76        DebugStream.println("Local library server output: " + library_output_line);
     77        library_output_line = library_in.readLine();
     78        }
     79        library_in.close();
     80
    7381        int response_code = library_connection.getResponseCode();
    7482        if (response_code >= HttpURLConnection.HTTP_OK && response_code < HttpURLConnection.HTTP_MULT_CHOICE) {
     
    7987        }
    8088    }
    81     catch (Exception ex) {
    82         DebugStream.printStackTrace(ex);
     89    catch (Exception exception) {
     90        DebugStream.printStackTrace(exception);
    8391    }
    8492    }
     
    93101    }
    94102
     103
    95104    static public void releaseCollection(String collection_name)
    96105    {
    97106    config(RELEASE_COMMAND + collection_name);
    98     // This is very important -- it ensures that the above command has finished
    99     config("");
    100 
    101     // !! HACK: Wait a couple of seconds, in the hope that this will reduce the "could not delete index" errors
    102     new OneSecondWait();
    103     new OneSecondWait();
    104107    }
    105108
Note: See TracChangeset for help on using the changeset viewer.