Changeset 29361 for main/trunk/gli


Ignore:
Timestamp:
10/10/14 16:59:53 (6 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.

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

Legend:

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

    r29356 r29361  
    744744                p = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "ant stop -f \"" + Configuration.gsdl3_src_path + File.separator + "build.xml\""});
    745745            }
    746             if(p != null && p.waitFor() == 0) {
     746            // doing a p.waitFor() without processing the Process' IOstreams causes blocking with Java 6
     747            // (i.e. when JRE 6 included with GS binaries). However, p.waitFor() with Java 7 is fine.
     748            /*if(p != null && p.waitFor() == 0) {
    747749                DebugStream.println("********** SUCCESSFULLY stopped THE GS3 SERVER ON EXIT");
    748750            }
     
    750752                System.err.println("********** FAILED TO SUCCESSFULLY stop THE GS3 SERVER ON EXIT");
    751753                //throw new Exception ("Failed to successfully stop the GS3 server on exit.");
    752             }
     754            }*/
    753755            } catch(Exception e) {
    754756            System.err.println("Exception when trying to stop the tomcat web server: " + e);
  • main/trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r29222 r29361  
    17551755        GS3ServerThread thread = new GS3ServerThread(Configuration.gsdl3_src_path, "restart");
    17561756        thread.start();
    1757 
    1758         // sleep before returning and doing the configGS3Server: give the GS3 server time to restart   
    1759         try {
    1760             Thread.sleep(5000);
    1761         } catch(Exception e) {
    1762             e.printStackTrace();
    1763         }
     1757       
     1758        // Give the GS3 server time to restart:
     1759        // the GS3ServerThread above waits for the process to terminate. ant restart target calls the start-tomcat ant target
     1760        // and that takes waits 5 seconds and polls to see if a GS3 server index page has loaded. So no need to sleep here     
    17641761       
    17651762        }
     
    20382035        return true;
    20392036    }
    2040 
    2041     if(CollectionManager.isSolrCollection()) {
    2042         // No installCollection() for GS3 solr collection: activate will take care of that
    2043         DebugStream.println("Solr collection build complete: building already moved to index by activate.pl.");
    2044 
    2045         // Finished building,
    2046         // For now, for a GS3 solr collection, we'd have stopped the GS3 server before building
    2047         // and will now need to restart it.
    2048         GS3ServerThread thread = new GS3ServerThread(Configuration.gsdl3_src_path, "restart");
    2049         thread.start();
    2050 
    2051         return true;
    2052     }
    2053 
    20542037
    20552038    DebugStream.println("Build complete. Moving files.");
  • 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.");
  • main/trunk/gli/src/org/greenstone/gatherer/util/OutputStreamGobbler.java

    r29031 r29361  
    5151    public void run()
    5252    {
     53   
     54    if (inputstr == null) {
     55        return;
     56    }
     57   
    5358    BufferedWriter osw = null;
    5459    try {
Note: See TracChangeset for help on using the changeset viewer.