Ignore:
Timestamp:
2017-04-21T20:00:54+12:00 (7 years ago)
Author:
ak19
Message:

Further changes to SafeProcess to turn some interfaces to abstract classes. Corresponding changes to GS2PerlConstructor which makes use of this.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/build/GS2PerlConstructor.java

    r31602 r31631  
    485485        // handle each incoming line from stdout and stderr streams, and any exceptions that occur then
    486486        SafeProcess.CustomProcessHandler processOutHandler
    487         = new SynchronizedProcessHandler(bw, SynchronizedProcessHandler.STDOUT);
     487        = new SynchronizedProcessHandler(bw, SafeProcess.STDOUT);
    488488        SafeProcess.CustomProcessHandler processErrHandler
    489         = new SynchronizedProcessHandler(bw, SynchronizedProcessHandler.STDERR);
     489        = new SynchronizedProcessHandler(bw, SafeProcess.STDERR);
    490490       
    491491        // GS2PerlConstructor will do further handling of exceptions that may occur during the perl
     
    700700    // exceptions when reading from our perl process' stderr and stdout streams are handled by
    701701    // SynchronizedProcessHandler.gotException() below, since they happen in separate threads
    702     // from this one (the ine from which the perl process is run).
     702    // from this one (the one from which the perl process is run).
    703703    public synchronized void gotException(Exception e) {
    704704
     
    719719    // we do that here too, to continue original behaviour. These calls are also synchronized to make their
    720720    // use of the EventListeners threadsafe.
    721     protected class SynchronizedProcessHandler implements SafeProcess.CustomProcessHandler
     721    protected class SynchronizedProcessHandler extends SafeProcess.CustomProcessHandler
    722722    {
    723     public static final int STDERR = 0;
    724     public static final int STDOUT = 1;
    725 
    726     private final int source;
    727723    private final BufferedWriter bwHandle; // needs to be final to synchronize on the object
    728724       
    729 
    730725    public SynchronizedProcessHandler(BufferedWriter bw, int src) {
     726        super(src); // will set this.source to STDERR or STDOUT
    731727        this.bwHandle = bw; // caller will close bw, since many more than one
    732728                            // SynchronizedProcessHandlers are using it
    733         this.source = src; // STDERR or STDOUT
    734729    }
    735730
     
    751746
    752747
    753             //if(this.source == STDERR) {
     748            //if(this.source == SafeProcess.STDERR) {
    754749            ///System.err.println("ERROR: " + line);
    755750            //} else {
     
    767762            }
    768763            } catch(IOException ioe) {
    769             String msg = (source == STDERR) ? "stderr" : "stdout";
     764            String msg = (this.source == SafeProcess.STDERR) ? "stderr" : "stdout";
    770765            msg = "Exception when writing out a line read from perl process' " + msg + " stream.";
    771766            GS2PerlConstructor.logger.error(msg, ioe);
     
    780775        } catch (IOException ioe) { // problem with reading in from process with BufferedReader br
    781776
    782         String msg = (source == STDERR) ? "stderr" : "stdout";
     777        String msg = (this.source == SafeProcess.STDERR) ? "stderr" : "stdout";
    783778        msg = "Got exception when processing the perl process' " + msg + " stream.";
    784779        GS2PerlConstructor.logger.error(msg, ioe);
     
    821816        // http://stackoverflow.com/questions/14211629/java-util-logger-write-synchronization
    822817       
    823         String msg = (source == STDERR) ? "stderr" : "stdout";
     818        String msg = (this.source == SafeProcess.STDERR) ? "stderr" : "stdout";
    824819        msg = "IOException when writing out a line read from perl process' " + msg + " stream.";
    825820        msg += "\nGot line: " + line + "\n";
Note: See TracChangeset for help on using the changeset viewer.