Ignore:
Timestamp:
2014-10-10T16:59:53+13:00 (10 years ago)
Author:
ak19
Message:

Fix to recent commit that made GS3ServerThread.java do a Process.waitFor(). JRE6 is included in GS binaries. But Java 6 does not work with Process.WaitFor() in GS3ServerThread, as the GS3 server waits to start until after GLI has been quit. Java 7 (JDK and JRE 7) work fine with this. To get Java 6 to work, need to handle the IOstreams of the Process launched by GS3ServerThread. Using the StreamGobbler classes for this.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/util/GS3ServerThread.java

    r29356 r29361  
    7878
    7979        if (p != null) {
    80             int result = p.waitFor();
    81             if(result != 0) {
     80            // in order for the process.waitFor() method to work with Java 6 (JRE 6 is included in GS binaries)
     81            // need to make sure the IOstreams of the process are not blocked. For Java 7, this is not necessary
     82            // and a waitFor() is sufficient. But with Java 6, the waitFor() causes the server to finally start
     83            // after the user has quit GLI.
     84       
     85            // Process takes no input, but we will still catch this iostream too
     86            // And we'll catch the error and output streams to prevent them from blocking during waitFor()
     87            // (For normal input and output stream handling using the Gobblers, see FormatConversionDialog.java)
     88            OutputStreamGobbler inputGobbler = new OutputStreamGobbler(p.getOutputStream(), null);         
     89            InputStreamGobbler errorGobbler = new InputStreamGobbler(p.getErrorStream(), true);
     90            InputStreamGobbler outputGobbler = new InputStreamGobbler(p.getInputStream());
     91           
     92            errorGobbler.start();
     93            outputGobbler.start();
     94            inputGobbler.start();
     95           
     96            // the important part: wait for the process (ant stop or start or re-start to terminate)
     97            int result = p.waitFor();
     98            if(result != 0) {
    8299            System.err.println("**** Failed to successfully " + _ant_command + " the GS3 server.");
    83             }
     100            }       
     101           
     102            outputGobbler.join();
     103            errorGobbler.join();
     104            inputGobbler.join();
    84105        } else {
    85106            System.err.println("**** Could not start the Process to " + _ant_command + " the GS3 server.");
Note: See TracChangeset for help on using the changeset viewer.