Changeset 31720 for main/trunk


Ignore:
Timestamp:
2017-06-02T17:14:00+12:00 (7 years ago)
Author:
ak19
Message:
  1. GLI's DownloadJobs don't allow pausing and resuming (the button used to work, but didn't ever pause/resume in the background, at least it's been stopping the wget download activity after wget related changes from some years back). Changing the Pause/Resume button in the DownloadProgressBar to the Stop/Stopped button. 2. Added another useful link on InterruptedException to SafeProgress and its documentation.
Location:
main/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/classes/dictionary.properties

    r31691 r31720  
    861861Mirroring.DownloadJob.Pause_Tooltip:Pause this download
    862862Mirroring.DownloadJob.Stop:Stop
    863 Mirroring.DownloadJob.Stop_Tooltip:Stop this download
     863Mirroring.DownloadJob.Stop_Tooltip:Stop this download job if it is currently running
     864Mirroring.DownloadJob.Stopped:Stopped
     865Mirroring.DownloadJob.Stopped_Tooltip:This download has been stopped
    864866Mirroring.DownloadJob.Resume:Resume
    865867Mirroring.DownloadJob.Resume_Tooltip:Resume this download
  • main/trunk/gli/src/org/greenstone/gatherer/download/DownloadJob.java

    r31692 r31720  
    7575
    7676    private final String download_url;
    77    
     77    private boolean wasClosed = false;
     78
    7879    //    private String current_url;
    7980    //    private String destination;
     
    212213        if (getState() == RUNNING) {
    213214        //setState(STOPPED);
    214         stopDownload(); // cancels any running SafeProcess     
     215        stopDownload(); // cancels any running SafeProcess
    215216        } else {
    216217        //previous_state = getState();
     
    220221    }
    221222    else if (event.getSource() == progress.close_button) {
     223        setClosed();
    222224        SafeProcess.log("@@@ Progress bar close button pressed");
    223225        if(getState() == RUNNING) {
    224226        previous_state = getState();
    225227        //setState(STOPPED); // do we need to do anything else to stop this? YES, we do:
    226         stopDownload(); // cancels any running SafeProcess     
    227         } 
     228        stopDownload(); // cancels any running SafeProcess
     229        }
    228230        mummy.deleteDownloadJob(this);
    229231    }
     
    798800        // if the cancel button was clicked when it had already naturally terminated
    799801
     802        // If the user had pressed the Close button to terminate the running job, then
    800803        // we're now ready to remove the display of the until now running job
    801804        // from the download progress bar interface
    802         mummy.deleteCurrentDownloadJob(this);
     805        // But don't bother removing the progress bar if the user had only pressed the Stop button
     806        if(wasClosed()) {
     807        mummy.deleteCurrentDownloadJob(this);
     808        }
    803809    } /*else {
    804810        // If we've got to here and the state isn't STOPPED then the
     
    962968    return state;
    963969    }
     970   
     971    /** @return true if the close button of the DownloadProgressBar was pressed,
     972     * false otherwise such as if the Stop button had been pressed.
     973    */
     974    private synchronized boolean wasClosed() {
     975    return this.wasClosed;
     976    }
    964977
    965978    /** Returns the current state of the stop flag for this job.
     
    978991    previous_state = this.state;
    979992    this.state = state;
     993    }
     994
     995    private synchronized void setClosed() {
     996    this.wasClosed = true;
    980997    }
    981998
  • main/trunk/gli/src/org/greenstone/gatherer/download/DownloadProgressBar.java

    r31692 r31720  
    132132    // However, now we additionally ensure that the wget launched by the perl is stopped before
    133133    // process.destroy(), so at least it cleans up better. I'm therefore changing it to a "Stop" button.
    134     stop_start_button = new GLIButton(Dictionary.get("Mirroring.DownloadJob.Pause"),Dictionary.get("Mirroring.DownloadJob.Pause_Tooltip"));
    135     //stop_start_button = new GLIButton(Dictionary.get("Mirroring.DownloadJob.Stop"),Dictionary.get("Mirroring.DownloadJob.Stop_Tooltip"));
     134    stop_start_button = new GLIButton(Dictionary.get("Mirroring.DownloadJob.Stop"),Dictionary.get("Mirroring.DownloadJob.Stop_Tooltip"));
    136135    stop_start_button.addActionListener(this);
    137136    stop_start_button.addActionListener(owner);
     
    189188        if (current_action == DownloadJob.RUNNING) {
    190189        current_action = DownloadJob.STOPPED;
    191                 stop_start_button.setText(Dictionary.get("Mirroring.DownloadJob.Resume"));
    192                 stop_start_button.setToolTipText(Dictionary.get("Mirroring.DownloadJob.Resume_Tooltip"));
     190                stop_start_button.setText(Dictionary.get("Mirroring.DownloadJob.Stopped"));
     191                stop_start_button.setToolTipText(Dictionary.get("Mirroring.DownloadJob.Stopped_Tooltip"));
    193192           
    194193        progress.setString(Dictionary.get("Mirroring.DownloadJob.Download_Stopped"));
    195194        progress.setIndeterminate(false);
    196         } else {
    197         current_action = DownloadJob.RUNNING;
    198         // we are stopped, so restart
    199                 stop_start_button.setText(Dictionary.get("Mirroring.DownloadJob.Pause"));
    200                 stop_start_button.setToolTipText(Dictionary.get("Mirroring.DownloadJob.Pause_Tooltip"));
    201         progress.setString(Dictionary.get("Mirroring.DownloadJob.Download_Progress"));
    202         progress.setIndeterminate(true);
     195        stop_start_button.setEnabled(false);
    203196        }
    204197    }
  • main/trunk/gli/src/org/greenstone/gatherer/util/Readme_Using_SafeProcess.txt

    r31719 r31720  
    581581- http://stackoverflow.com/questions/4906799/why-invoke-thread-currentthread-interrupt-when-catch-any-interruptexception
    582582- https://praveer09.github.io/technology/2015/12/06/understanding-thread-interruption-in-java/
     583- http://michaelscharf.blogspot.co.nz/2006/09/dont-swallow-interruptedexception-call.html
    583584
    584585
  • main/trunk/gli/src/org/greenstone/gatherer/util/SafeProcess.java

    r31718 r31720  
    618618        // See also http://stackoverflow.com/questions/4906799/why-invoke-thread-currentthread-interrupt-when-catch-any-interruptexception
    619619        // and https://praveer09.github.io/technology/2015/12/06/understanding-thread-interruption-in-java/
     620        // http://michaelscharf.blogspot.co.nz/2006/09/dont-swallow-interruptedexception-call.html
    620621        Thread.currentThread().interrupt(); // re-interrupt the thread - which thread? Infinite loop?
    621622   
  • main/trunk/greenstone3/src/java/org/greenstone/util/SafeProcess.java

    r31718 r31720  
    619619        // See also http://stackoverflow.com/questions/4906799/why-invoke-thread-currentthread-interrupt-when-catch-any-interruptexception
    620620        // and https://praveer09.github.io/technology/2015/12/06/understanding-thread-interruption-in-java/
     621        // http://michaelscharf.blogspot.co.nz/2006/09/dont-swallow-interruptedexception-call.html
    621622        Thread.currentThread().interrupt(); // re-interrupt the thread - which thread? Infinite loop?
    622623   
Note: See TracChangeset for help on using the changeset viewer.